216 lines
7.7 KiB
C++
216 lines
7.7 KiB
C++
#include "def.h"
|
|
#include "NameCreater.h"
|
|
#include <QDebug>
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
#include <QFontDatabase>
|
|
#include <QTextCodec>
|
|
#include <QGraphicsScene>
|
|
#include <QGraphicsView>
|
|
#include <QGraphicsPixmapItem>
|
|
#include <QDateTime>
|
|
#include <QBuffer>
|
|
#include <QRegularExpression>
|
|
|
|
#include "FiveToSingle.h"
|
|
#include "BirthdayCreater.h"
|
|
#include "TowelCreater.h"
|
|
#include "NewFiveCreater.h"
|
|
#include "HKHolderCreater.h"
|
|
#include "customlogo.h"
|
|
#include "customlogo2.h"
|
|
|
|
|
|
#define TOWEL_FONT_PATH ":/NameCreater/_exp/W1.ttc"
|
|
#define ENGLISH_FONT_PATH ":/NameCreater/_exp/FontsFree-Net-Acumin-Pro-Semibold.ttf"
|
|
|
|
#define FONT_SIZE 120
|
|
|
|
#define FONT_CHT_URL "https://bazaar1688.ddns.net/font/TaiwanPearl-SemiBold.ttf"
|
|
|
|
//#define FONT_CHT_URL "http://45.32.51.135/font/TaiwanPearl-SemiBold.ttf"
|
|
|
|
NameCreater::NameCreater(QWidget *parent)
|
|
: QMainWindow(parent)
|
|
{
|
|
ui.setupUi(this);
|
|
connect(ui.fivesingle_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
//connect(ui.fiveold_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.birthday_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.towel_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.fivenew_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.birthday_zh_eng_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.birthday_eng_eng_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.handkerchief_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.fivesingle_zh_eng_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
|
connect(ui.customlogo_btn, &QPushButton::released, this , &NameCreater::OnClickedCustomLogoBtn);
|
|
connect(ui.customlogo2_btn, &QPushButton::released, this, &NameCreater::OnClickedCustomLogo2Btn);
|
|
|
|
//qDebug()<<"QSslSocket="<<QSslSocket::sslLibraryBuildVersionString();
|
|
|
|
connect(&network_mgr, &QNetworkAccessManager::finished, this, &NameCreater::onFontDownloadFinished);
|
|
network_mgr.get(QNetworkRequest(QUrl(FONT_CHT_URL)));
|
|
|
|
;
|
|
|
|
}
|
|
|
|
void NameCreater::loadFont(const QByteArray& fontdata){
|
|
|
|
int id = QFontDatabase::addApplicationFontFromData(fontdata);
|
|
QStringList family_list = QFontDatabase::applicationFontFamilies(id);
|
|
qDebug()<<"font family list:" <<family_list;
|
|
QString cht_fontname = family_list.at(0);
|
|
|
|
font = QFont(cht_fontname);
|
|
font.setPixelSize(FONT_SIZE);
|
|
|
|
QString font_path = QString(TOWEL_FONT_PATH);
|
|
QFile font_res_towel(font_path);
|
|
if (!font_res_towel.open(QIODevice::ReadOnly)) {
|
|
QMessageBox msgBox;
|
|
msgBox.setText("Can not load font file!" + font_path);
|
|
msgBox.exec();
|
|
font_res_towel.close();
|
|
}
|
|
|
|
id = QFontDatabase::addApplicationFontFromData(font_res_towel.readAll());
|
|
font_towel = QFont(QFontDatabase::applicationFontFamilies(id).at(0));
|
|
font_towel.setPixelSize(240);
|
|
font_towel.setLetterSpacing(QFont::PercentageSpacing, 42);
|
|
|
|
|
|
font_path = QString(ENGLISH_FONT_PATH);
|
|
QFile font_res_eng(font_path);
|
|
if (!font_res_eng.open(QIODevice::ReadOnly)) {
|
|
QMessageBox msgBox;
|
|
msgBox.setText("Can not load font file!" + font_path);
|
|
msgBox.exec();
|
|
font_res_eng.close();
|
|
}
|
|
|
|
id = QFontDatabase::addApplicationFontFromData(font_res_eng.readAll());
|
|
font_english = QFont(QFontDatabase::applicationFontFamilies(id).at(0));
|
|
|
|
|
|
font_color = QColor(0, 0, 0);
|
|
|
|
QFont tital_font = QFont(font);
|
|
tital_font.setPixelSize(20);
|
|
|
|
QFont version_font = QFont(font);
|
|
version_font.setPixelSize(12);
|
|
|
|
//ui.tital_label->setFont(tital_font);
|
|
|
|
char c_font_name[64] = {0};
|
|
sprintf(c_font_name,"%s", cht_fontname.toStdString().c_str());
|
|
ui.font_name_label->setFont(version_font);
|
|
ui.font_name_label->setText(QString::fromLocal8Bit(c_font_name));
|
|
|
|
ui.version_label->setFont(version_font);
|
|
ui.version_label->setText(VERSION);
|
|
|
|
QList<QLabel*> titals = findChildren<QLabel*>(QRegularExpression("tital_label"));
|
|
foreach(auto tital, titals) {
|
|
tital->setFont(tital_font);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
void NameCreater::OnClickedReadBtn() {
|
|
auto sender =(QPushButton*) QObject::sender();
|
|
|
|
#ifdef Q_OS_WASM
|
|
|
|
auto fileContentReady = [this, sender](const QString &fileName, const QByteArray &fileContent) {
|
|
if (!fileName.isEmpty()) {
|
|
this->execCreater(sender, fileName, fileContent);
|
|
}
|
|
|
|
};
|
|
QFileDialog::getOpenFileContent("CSV (*.csv)", fileContentReady);
|
|
|
|
#else
|
|
QString filename = QFileDialog::getOpenFileName(nullptr,"Open Name File", QDir::currentPath(),"CSV file(*.csv)");
|
|
if(!filename.isEmpty()){
|
|
QFile _f(filename);
|
|
if(_f.open(QIODevice::ReadOnly)){
|
|
execCreater(sender, filename, _f.readAll());
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void NameCreater::execCreater(QObject* sender, const QString& fileName, const QByteArray& fileContent) {
|
|
|
|
// Use fileName and fileContent
|
|
if(sender == ui.fivesingle_btn) FiveToSingle().generaImageFromCSV(Name_Type_e::Name_zh,fileName, fileContent, this->font, this->font_color);
|
|
|
|
if(sender == ui.birthday_btn) BirthdayCreater().generaImageFromCSV(Name_Type_e::Name_zh, fileName, fileContent, this->font, this->font_color);
|
|
if(sender == ui.fivenew_btn) NewFiveCreater().generaImageFromCSV(Name_Type_e::Name_zh, fileName, fileContent, this->font, this->font_color);
|
|
if(sender == ui.towel_btn) TowelCreater().generaImageFromCSV(Name_Type_e::Name_zh, fileName, fileContent, this->font_towel, this->font_color);
|
|
if (sender == ui.birthday_zh_eng_btn) {
|
|
BirthdayCreater creater;
|
|
creater.setEnglishFont(font_english);
|
|
creater.generaImageFromCSV(Name_Type_e::Name_zh_eng, fileName, fileContent, this->font, this->font_color);
|
|
}
|
|
if (sender == ui.birthday_eng_eng_btn){
|
|
BirthdayCreater b;
|
|
b.setEnglishFont(font_english);
|
|
b.generaImageFromCSV(Name_Type_e::Name_eng, fileName,fileContent,this->font, this->font_color);
|
|
}
|
|
if (sender == ui.handkerchief_btn) {
|
|
QFont newFont(font);
|
|
newFont.setPixelSize(78);
|
|
QColor newColor(0,0,0);
|
|
HKHolderCreater().generaImageFromCSV(Name_Type_e::Name_zh, fileName, fileContent, newFont, newColor);
|
|
}
|
|
if (sender == ui.fivesingle_zh_eng_btn) {
|
|
FiveToSingle f;
|
|
f.setEnglishFont(this->font_english);
|
|
f.generaImageFromCSV(Name_Type_e::Name_zh_eng, fileName, fileContent, this->font, this->font_color);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
void NameCreater::OnClickedCustomLogoBtn() {
|
|
QEventLoop loop;
|
|
CustomLogo widget(&this->font);
|
|
widget.show();
|
|
connect(&widget, &CustomLogo::finished, &loop, &QEventLoop::quit);
|
|
loop.exec();
|
|
qDebug()<<"exit event loop";
|
|
|
|
}
|
|
|
|
void NameCreater::OnClickedCustomLogo2Btn(){
|
|
QEventLoop loop;
|
|
customlogo2 widget(&this->font);
|
|
connect(&widget, &CustomLogo::finished, &loop, &QEventLoop::quit);
|
|
widget.show();
|
|
loop.exec();
|
|
}
|
|
|
|
void NameCreater::onFontDownloadFinished(QNetworkReply *reply){
|
|
|
|
if(reply->error() == QNetworkReply::NoError){
|
|
//do somthine
|
|
loadFont(reply->readAll());
|
|
qDebug()<<"Load Font Succeed!";
|
|
|
|
}else{
|
|
|
|
QMessageBox msgBox;
|
|
msgBox.setText("Can not load font file!" + reply->errorString());
|
|
msgBox.exec();
|
|
reply->deleteLater();
|
|
|
|
|
|
return ;
|
|
}
|
|
|
|
}
|