#include "def.h" #include "NameCreater.h" #include #include #include #include #include #include #include #include #include #include #include #include "FiveToSingle.h" #include "BirthdayCreater.h" #include "TowelCreater.h" #include "NewFiveCreater.h" #include "HKHolderCreater.h" #include "customlogo.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" 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(&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:" <setFont(tital_font); QString fontName = QString::fromUtf8(family_list.at(0).toUtf8()); ui.version_label->setFont(version_font); ui.version_label->setText(QString(VERSION).append("/cht font:")+fontName); QList titals = findChildren(QRegularExpression("tital_label")); foreach(auto tital, titals) { tital->setFont(tital_font); } } void NameCreater::OnClickedReadBtn() { auto sender =(QPushButton*) QObject::sender(); auto fileContentReady = [this, sender](const QString &fileName, const QByteArray &fileContent) { if (fileName.isEmpty()) { // No file was selected } else { // 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; } } }; QFileDialog::getOpenFileContent("CSV (*.csv)", fileContentReady); } 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::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 ; } }