From 24639c50b0a67cbd265f881fc8b4ec76e3123679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?shouchih=5Fchen=20=E9=99=B3=E5=AE=88=E5=BF=97?= Date: Fri, 31 Mar 2023 14:40:23 +0800 Subject: [PATCH] web assemble testing --- .gitignore | 13 +- NameCreater/NameCreater.cpp | 39 ++- NameCreater/NameCreater.h | 33 +-- NameCreater/NameCreater.pri | 28 +- NameCreater/NameCreater.pro | 42 +-- NameCreater/NameCreater.qrc | 59 ++--- NameCreater/NameCreater.ui | 163 +++++++----- NameCreater/NameCreater.vcxproj | 375 ++++++++++++++------------- NameCreater/NameCreater.vcxproj.user | 60 ++--- NameCreater/main.cpp | 89 ++++--- 10 files changed, 480 insertions(+), 421 deletions(-) diff --git a/.gitignore b/.gitignore index f4a14ba..92f34a7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ -*Debug/ -*Release/ -/.vs/ -/*.opendb -/*.db -/_bin +*Debug/ +*Release/ +/.vs/ +/*.opendb +/*.db +/_bin +/web_build diff --git a/NameCreater/NameCreater.cpp b/NameCreater/NameCreater.cpp index 37eb9ab..b21210d 100644 --- a/NameCreater/NameCreater.cpp +++ b/NameCreater/NameCreater.cpp @@ -1,12 +1,27 @@ -#include "NameCreater.h" -#include - -NameCreater::NameCreater(QWidget *parent) - : QMainWindow(parent) -{ - ui.setupUi(this); - - - qDebug() << ui.label->font().family(); - -} +#include "NameCreater.h" +#include +#include + + +NameCreater::NameCreater(QWidget *parent) + : QMainWindow(parent) +{ + ui.setupUi(this); + connect(ui.openfile_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn); + + qDebug() << ui.label->font().family(); + +} + +void NameCreater::OnClickedReadBtn() { + auto fileContentReady = [](const QString &fileName, const QByteArray &fileContent) { + if (fileName.isEmpty()) { + // No file was selected + } + else { + // Use fileName and fileContent + //processCSV(fileName, font, font_color); + } + }; + QFileDialog::getOpenFileContent("CSV (*.csv)", fileContentReady); +} \ No newline at end of file diff --git a/NameCreater/NameCreater.h b/NameCreater/NameCreater.h index 75afe71..a5fc0bb 100644 --- a/NameCreater/NameCreater.h +++ b/NameCreater/NameCreater.h @@ -1,15 +1,18 @@ -#pragma once - -#include -#include "ui_NameCreater.h" - -class NameCreater : public QMainWindow -{ - Q_OBJECT - -public: - NameCreater(QWidget *parent = Q_NULLPTR); - -private: - Ui::NameCreaterClass ui; -}; +#pragma once + +#include +#include "ui_NameCreater.h" + +class NameCreater : public QMainWindow +{ + Q_OBJECT + +public: + NameCreater(QWidget *parent = Q_NULLPTR); + +private: + Ui::NameCreaterClass ui; + + private Q_SLOTS: + void OnClickedReadBtn(); +}; diff --git a/NameCreater/NameCreater.pri b/NameCreater/NameCreater.pri index c0e878e..15d6a4f 100644 --- a/NameCreater/NameCreater.pri +++ b/NameCreater/NameCreater.pri @@ -1,14 +1,14 @@ -# ---------------------------------------------------- -# This file is generated by the Qt Visual Studio Tools. -# ------------------------------------------------------ - -# This is a reminder that you are using a generated .pro file. -# Remove it when you are finished editing this file. -message("You are running qmake on a generated .pro file. This may not work!") - - -HEADERS += ./NameCreater.h -SOURCES += ./NameCreater.cpp \ - ./main.cpp -FORMS += ./NameCreater.ui -RESOURCES += ./NameCreater.qrc +# ---------------------------------------------------- +# This file is generated by the Qt Visual Studio Tools. +# ------------------------------------------------------ + +# This is a reminder that you are using a generated .pro file. +# Remove it when you are finished editing this file. +message("You are running qmake on a generated .pro file. This may not work!") + + +HEADERS += ./NameCreater.h +SOURCES += ./NameCreater.cpp \ + ./main.cpp +FORMS += ./NameCreater.ui +RESOURCES += NameCreater.qrc diff --git a/NameCreater/NameCreater.pro b/NameCreater/NameCreater.pro index 6594743..12e60ff 100644 --- a/NameCreater/NameCreater.pro +++ b/NameCreater/NameCreater.pro @@ -1,21 +1,21 @@ -QT += core gui - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets - -CONFIG += c++11 - -# You can make your code fail to compile if it uses deprecated APIs. -# In order to do so, uncomment the following line. -#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 - -include(NameCreater.pri) - - -# Default rules for deployment. -qnx: target.path = /tmp/$${TARGET}/bin -else: unix:!android: target.path = /opt/$${TARGET}/bin -!isEmpty(target.path): INSTALLS += target - - - - +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 resources_big + +# You can make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +include(NameCreater.pri) + + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + + + + diff --git a/NameCreater/NameCreater.qrc b/NameCreater/NameCreater.qrc index 0e21c65..d2d52c8 100644 --- a/NameCreater/NameCreater.qrc +++ b/NameCreater/NameCreater.qrc @@ -1,31 +1,32 @@ - - resource/background_sample.jpg - resource/background_b.jpg - resource/background_g.jpg - resource/background_r.jpg - resource/background_y.jpg - resource/two_word_sample.jpg - resource/background_1.jpg - resource/background_2.jpg - resource/background_3.jpg - resource/background_4.jpg - resource/background_5.jpg - resource/background_6.jpg - resource/background_7.jpg - resource/background_8.jpg - resource/background_9.jpg - resource/background_10.jpg - resource/background_number_smaple.jpg - resource/background_11.jpg - resource/background_12.jpg - resource/background_13.jpg - resource/background_14.jpg - resource/background_15.jpg - resource/background_16.jpg - resource/background_17.jpg - resource/background_18.jpg - resource/background_19.jpg - resource/background_20.jpg - + + _exp/DFYuanStd-W8.otf + resource/background_sample.jpg + resource/background_b.jpg + resource/background_g.jpg + resource/background_r.jpg + resource/background_y.jpg + resource/two_word_sample.jpg + resource/background_1.jpg + resource/background_2.jpg + resource/background_3.jpg + resource/background_4.jpg + resource/background_5.jpg + resource/background_6.jpg + resource/background_7.jpg + resource/background_8.jpg + resource/background_9.jpg + resource/background_10.jpg + resource/background_number_smaple.jpg + resource/background_11.jpg + resource/background_12.jpg + resource/background_13.jpg + resource/background_14.jpg + resource/background_15.jpg + resource/background_16.jpg + resource/background_17.jpg + resource/background_18.jpg + resource/background_19.jpg + resource/background_20.jpg + diff --git a/NameCreater/NameCreater.ui b/NameCreater/NameCreater.ui index b9bbe18..abd1671 100644 --- a/NameCreater/NameCreater.ui +++ b/NameCreater/NameCreater.ui @@ -1,65 +1,98 @@ - - - NameCreaterClass - - - - 0 - 0 - 977 - 716 - - - - - - - NameCreater - - - - - - 240 - 220 - 441 - 261 - - - - font: 26pt "華康圓體 Std W8"; - - - - - - :/NameCreater/resource/background.jpg - - - - - - - 0 - 0 - 977 - 22 - - - - - - TopToolBarArea - - - false - - - - - - - - - - + + + NameCreaterClass + + + + 0 + 0 + 977 + 716 + + + + + + + NameCreater + + + color: rgb(0, 0, 0); + + + + QWidget#centralWidget{ +background-color: rgb(0, 0, 0); +} + + + + + 470 + 40 + 441 + 261 + + + + font: 26pt "華康圓體 Std W8"; + + + + + + :/NameCreater/resource/background.jpg + + + + + + 150 + 470 + 181 + 61 + + + + Open File + + + + + + + 0 + 0 + 977 + 21 + + + + + File + + + + + + + + TopToolBarArea + + + false + + + + + + Open File + + + + + + + + + diff --git a/NameCreater/NameCreater.vcxproj b/NameCreater/NameCreater.vcxproj index fd9cbb4..8afb2c7 100644 --- a/NameCreater/NameCreater.vcxproj +++ b/NameCreater/NameCreater.vcxproj @@ -1,187 +1,190 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {B66B108B-6DA8-408D-936D-988FF8B6B722} - QtVS_v304 - 10.0.19041.0 - 10.0.19041.0 - 10.0.19041.0 - 10.0.19041.0 - $(MSBuildProjectDirectory)\QtMsBuild - - - - Application - v142 - - - Application - v142 - - - Application - v142 - - - Application - v142 - - - - - - - $(DefaultQtVersion) - core;gui;widgets - debug - - - $(DefaultQtVersion) - core;gui;widgets - debug - - - $(DefaultQtVersion) - core;gui;widgets - release - - - $(DefaultQtVersion) - core;gui;widgets - release - - - - - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)_bin\ - $(Configuration)\ - - - - $(SolutionDir)_bin\ - $(Configuration)\ - - - - xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" - - - - - xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" - - - - - xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" - - - - - xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" - - - - - true - true - ProgramDatabase - Disabled - MultiThreadedDebugDLL - - - Windows - true - - - - - true - true - ProgramDatabase - Disabled - MultiThreadedDebugDLL - - - Windows - true - - - - - true - true - None - MaxSpeed - MultiThreadedDLL - - - Windows - false - - - - - true - true - None - MaxSpeed - MultiThreadedDLL - - - Windows - false - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {B66B108B-6DA8-408D-936D-988FF8B6B722} + QtVS_v304 + 10.0.16299.0 + 10.0.19041.0 + 10.0.16299.0 + 10.0.19041.0 + $(MSBuildProjectDirectory)\QtMsBuild + + + + Application + v140 + + + Application + v142 + + + Application + v140 + + + Application + v142 + + + + + + + 5.8_msvc2015 + core;gui;widgets + debug + + + $(DefaultQtVersion) + core;gui;widgets + debug + + + $(DefaultQtVersion) + core;gui;widgets + release + + + $(DefaultQtVersion) + core;gui;widgets + release + + + + + + + + + + + + + + + + + + + + + + + + + $(SolutionDir)_bin\ + $(Configuration)\ + + + + $(SolutionDir)_bin\ + $(Configuration)\ + + + + xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" + + + /Zm1000 + + + + + xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" + + + + + xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" + + + + + xcopy /y "$(ProjectDir)_exp\*" "$(TargetDir)" + + + + + true + true + ProgramDatabase + Disabled + MultiThreadedDebugDLL + + + Windows + true + + + + + true + true + ProgramDatabase + Disabled + MultiThreadedDebugDLL + + + Windows + true + + + + + true + true + None + MaxSpeed + MultiThreadedDLL + + + Windows + false + + + + + true + true + None + MaxSpeed + MultiThreadedDLL + + + Windows + false + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NameCreater/NameCreater.vcxproj.user b/NameCreater/NameCreater.vcxproj.user index a1eb66b..e7ac749 100644 --- a/NameCreater/NameCreater.vcxproj.user +++ b/NameCreater/NameCreater.vcxproj.user @@ -1,31 +1,31 @@ - - - - $(TargetDir) - WindowsLocalDebugger - - - $(TargetDir) - WindowsLocalDebugger - - - $(TargetDir) - WindowsLocalDebugger - - - $(TargetDir) - WindowsLocalDebugger - - - 2022-02-09T21:34:52.5655210Z - - - 2022-02-09T21:34:52.5655210Z - - - 2022-02-09T21:34:53.9897137Z - - - 2022-02-09T21:34:53.9897137Z - + + + + $(TargetDir) + WindowsLocalDebugger + + + $(TargetDir) + WindowsLocalDebugger + + + $(TargetDir) + WindowsLocalDebugger + + + $(TargetDir) + WindowsLocalDebugger + + + 2023-02-07T09:42:35.8095077Z + + + 2022-02-09T21:34:52.5655210Z + + + 2022-02-09T21:34:53.9897137Z + + + 2022-02-09T21:34:53.9897137Z + \ No newline at end of file diff --git a/NameCreater/main.cpp b/NameCreater/main.cpp index 4e6c324..0cd7868 100644 --- a/NameCreater/main.cpp +++ b/NameCreater/main.cpp @@ -13,10 +13,12 @@ #include + //#define BG_SAMPLE_PATH ":/NameCreater/resource/background_sample.jpg" #define BG_SAMPLE_PATH ":/NameCreater/resource/background_number_smaple.jpg" #define BG_PATH_FORMAT ":/NameCreater/resource/background_%1.jpg" #define FONT_NAME "DFYuanStd-W8.otf" +#define FONT_PATH ":/NameCreater/_exp/DFYuanStd-W8.otf" #define FONT_SIZE 120 //#define FONT_SIZE 74 @@ -112,7 +114,7 @@ QList getNameByFile(const QString& filename) { #ifdef Q_OS_MAC QString root_path = QCoreApplication::applicationDirPath() + "/../../../"; #else - QString root_path = QCoreApplication::applicationDirPath() + "/"; + QString root_path = "";//QCoreApplication::applicationDirPath() + "/"; #endif @@ -161,38 +163,10 @@ QList getNameByFile(const QString& filename) { return nameList; } -int main(int argc, char* argv[]) -{ + +void processCSV(const QString& filename, const QFont& font, const QColor& font_color) { int export_times = 0; - - - - QApplication a(argc, argv); - // NameCreater w; - // w.show(); -#ifdef Q_OS_MAC - QString root_path = QCoreApplication::applicationDirPath() + "/../../../"; -#else - QString root_path = QCoreApplication::applicationDirPath() + "/"; -#endif - - QString font_path = root_path.append(FONT_NAME); - QFile font_res(font_path); - if (!font_res.open(QIODevice::ReadOnly)) { - QMessageBox msgBox; - msgBox.setText("Can not load font file!" + font_path); - msgBox.exec(); - font_res.close(); - return 0; - } - int id = QFontDatabase::addApplicationFontFromData(font_res.readAll()); - QStringList family_list = QFontDatabase::applicationFontFamilies(id); - QFont font = QFont(family_list.at(0)); - font.setPixelSize(FONT_SIZE); - QColor font_color(0, 0, 0); - - - QList nameList = getNameByFile("name.csv"); + QList nameList = getNameByFile(filename); if (nameList.isEmpty()) { QMessageBox msgBox; msgBox.setText(("Name is empty !")); @@ -214,7 +188,7 @@ int main(int argc, char* argv[]) int idx = n % BG_POS_COUNT; NameInfo_t name_info = nameList.at(n); QImage name_image(name_info.bg_path); - if (idx == 0) { + if (idx == 0) { QGraphicsRectItem* bg_item = new QGraphicsRectItem(0, 0, 3508, 2482); bg_item->setBrush(QBrush(QColor(255, 255, 255))); scene.addItem(bg_item); @@ -241,7 +215,7 @@ int main(int argc, char* argv[]) xscale = yscale = (j == 1) ? -1 : 1; QPointF pos = name_info.is_number_bg ? NAME_POS_NUMBER[pos_idx] : NAME_POS[pos_idx]; - int y_offset[2] = {0}; + int y_offset[2] = { 0 }; if (name_len == 2) { if (!rot) { pos.setY(pos.y() + 82 * xscale); @@ -250,7 +224,7 @@ int main(int argc, char* argv[]) pos.setX(pos.x() + 82 * xscale); } - + y_offset[0] = 25; } @@ -302,15 +276,15 @@ int main(int argc, char* argv[]) scene.addItem(textItem3); } - + } bool is_export_page = ((idx + 1) % BG_POS_COUNT == 0); - if (is_export_page || n == nameList.count()-1) { + if (is_export_page || n == nameList.count() - 1) { QString file_name = QString("%1_.jpg").arg(QString::number(export_times + 1)); saveToImage(file_name, &scene); export_times++; - + scene.clear(); } } @@ -320,9 +294,38 @@ int main(int argc, char* argv[]) QMessageBox msgBox; msgBox.setText(QString().asprintf("Export Finshed. Count:%d", export_times)); msgBox.exec(); - - - - font_res.close(); - return 0; +} + +int main(int argc, char* argv[]) +{ + + QApplication a(argc, argv); + NameCreater w; + w.show(); + +#ifdef Q_OS_MAC + QString root_path = QCoreApplication::applicationDirPath() + "/../../../"; +#else + //QString root_path = FONT_PATH;//QCoreApplication::applicationDirPath() + "/"; +#endif + + QString font_path = FONT_PATH; //root_path.append(FONT_NAME); + QFile font_res(font_path); + if (!font_res.open(QIODevice::ReadOnly)) { + QMessageBox msgBox; + msgBox.setText("Can not load font file!" + font_path); + msgBox.exec(); + font_res.close(); + return 0; + } + int id = QFontDatabase::addApplicationFontFromData(font_res.readAll()); + QStringList family_list = QFontDatabase::applicationFontFamilies(id); + QFont font = QFont(family_list.at(0)); + font.setPixelSize(FONT_SIZE); + QColor font_color(0, 0, 0); + + + + //font_res.close(); + return a.exec(); }