diff --git a/NameCreater/NameCreater.qrc b/NameCreater/NameCreater.qrc
index c19bed8..f9048fe 100644
--- a/NameCreater/NameCreater.qrc
+++ b/NameCreater/NameCreater.qrc
@@ -2,5 +2,7 @@
resource/background.jpg
resource/background_sample.jpg
+ resource/background_boy.jpg
+ resource/background_girl.jpg
diff --git a/NameCreater/NameCreater.vcxproj b/NameCreater/NameCreater.vcxproj
index 8989da9..eb3446c 100644
--- a/NameCreater/NameCreater.vcxproj
+++ b/NameCreater/NameCreater.vcxproj
@@ -13,18 +13,18 @@
{B66B108B-6DA8-408D-936D-988FF8B6B722}
QtVS_v304
- 8.1
- 8.1
+ 10.0.19041.0
+ 10.0.19041.0
$(MSBuildProjectDirectory)\QtMsBuild
Application
- v140
+ v142
Application
- v140
+ v142
diff --git a/NameCreater/NameCreater.vcxproj.user b/NameCreater/NameCreater.vcxproj.user
index 68aff90..df0720f 100644
--- a/NameCreater/NameCreater.vcxproj.user
+++ b/NameCreater/NameCreater.vcxproj.user
@@ -1,6 +1,13 @@

-
+
+ $(TargetDir)
+ WindowsLocalDebugger
+
+
+ $(TargetDir)
+ WindowsLocalDebugger
+
2022-02-09T21:34:52.5655210Z
diff --git a/NameCreater/_exp/name.csv b/NameCreater/_exp/name.csv
index fab5ae3..97db021 100644
--- a/NameCreater/_exp/name.csv
+++ b/NameCreater/_exp/name.csv
@@ -1,2 +1,4 @@
-boy_name,girl_name
-³¯¦u§Ó,§d¨Î¹a
+name_1,name_2,bg_type
+Ĭ´é¶£,Ĭ¤_®¦,mix
+³¯¥K®¦,³¯¬f¿Î,boy
+§õ«Bªä,§õ«Bªä,girl
diff --git a/NameCreater/background_sample.jpg b/NameCreater/background_sample.jpg
new file mode 100644
index 0000000..55f7928
Binary files /dev/null and b/NameCreater/background_sample.jpg differ
diff --git a/NameCreater/main.cpp b/NameCreater/main.cpp
index 9230ee1..5e66cee 100644
--- a/NameCreater/main.cpp
+++ b/NameCreater/main.cpp
@@ -1,97 +1,189 @@
#include "NameCreater.h"
+#include
+
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
-#include "QGraphicsScene"
-#include "QGraphicsView"
-#include "QGraphicsPixmapItem"
-#include "QGraphicsTextItem"
-
-#define BG_PATH ":/NameCreater/resource/background.jpg"
+#define BG_MIX_PATH ":/NameCreater/resource/background.jpg"
+#define BG_BOY_PATH ":/NameCreater/resource/background_boy.jpg"
+#define BG_GIRL_PATH ":/NameCreater/resource/background_girl.jpg"
#define FONT_NAME QStringLiteral("µØ±d¶êÅé Std W8")
-#define FONT_SIZE 76
+#define FONT_SIZE 74
+
+#define BG_MIX_TYPE_STR "mix"
+#define BG_BOY_TYPE_STR "boy"
+#define BG_GIRL_TYPE_STR "girl"
+
+struct NameInfo_t {
+ QString name1;
+ QString name2;
+ int bg_type;
+};
static QPointF BOY_POS[] = {
- QPointF(235, 400), QPointF(366, 1420),
- QPointF(555, 400), QPointF(692, 1420),
- QPointF(878, 400), QPointF(1014, 1420),
- QPointF(1200, 400), QPointF(1337, 1420),
- QPointF(1527, 400), QPointF(1663, 1420),
+ QPointF(235, 387), QPointF(366, 1433),
+ QPointF(555, 387), QPointF(692, 1433),
+ QPointF(878, 387), QPointF(1014, 1433),
+ QPointF(1200, 387), QPointF(1337, 1433),
+ QPointF(1527, 387), QPointF(1663, 1433),
};
static int BOY_POS_COUNT = sizeof(BOY_POS) / sizeof(BOY_POS[0]);
static QPointF GIRL_POS[] = {
- QPointF(1854, 400), QPointF(1987, 1420),
- QPointF(2176, 400), QPointF(2314, 1420),
- QPointF(2498, 400), QPointF(2635, 1420),
- QPointF(2821, 400), QPointF(2958, 1420),
- QPointF(3147, 400), QPointF(3285, 1420),
+ QPointF(1854, 387), QPointF(1987, 1433),
+ QPointF(2176, 387), QPointF(2314, 1433),
+ QPointF(2498, 387), QPointF(2635, 1433),
+ QPointF(2821, 387), QPointF(2958, 1433),
+ QPointF(3147, 387), QPointF(3285, 1433),
};
static int GIRL_POS_COUNT = sizeof(GIRL_POS) / sizeof(GIRL_POS[0]);
-void saveToImage(const QString& filename , QGraphicsScene *scene) {
+void saveToImage(const QString& filename, QGraphicsScene* scene) {
- scene->clearSelection(); // Selections would also render to the file
- scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
- QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
- image.fill(Qt::transparent); // Start all pixels transparent
- int dpm = 300 / 0.0254; // ~300 DPI
- image.setDotsPerMeterX(dpm);
- image.setDotsPerMeterY(dpm);
-
+ scene->clearSelection(); // Selections would also render to the file
+ scene->setSceneRect(scene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
+ QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
+ image.fill(Qt::transparent); // Start all pixels transparent
+ int dpm = 300 / 0.0254; // ~300 DPI
+ image.setDotsPerMeterX(dpm);
+ image.setDotsPerMeterY(dpm);
- QPainter painter(&image);
- scene->render(&painter);
- image.save(filename);
+
+ QPainter painter(&image);
+ scene->render(&painter);
+
+ if (!QDir("export").exists()) {
+ QDir().mkdir("export");
+ }
+
+ image.save(QString("export/").append(filename));
}
-int main(int argc, char *argv[])
+QList getNameByFile(const QString& filename) {
+ QList nameList;
+ QFile file(filename);
+ if (!file.open(QIODevice::ReadOnly)) {
+ qDebug() << "Load file failed!";
+ return nameList;
+ }
+
+ int row = 0;
+ while (!file.atEnd())
+ {
+ NameInfo_t info;
+ QByteArray line = file.readLine();
+ QByteArrayList csvList = line.split(',');
+
+
+ QString name1 = QString::fromLocal8Bit(csvList.at(0));
+ QString name2 = QString::fromLocal8Bit(csvList.at(1));
+ QString type_str = QString::fromLocal8Bit(csvList.last());
+ qDebug() << "row :" << row << " " << name1 << " " << name2;
+
+ if (name1.compare("name_1") == 0 || name2.compare("name_2") == 0) {
+ continue;
+ }
+
+ info.name1 = name1;
+ info.name2 = name2;
+ info.bg_type = type_str.contains(QRegExp("boy")) ? 1 : (type_str.contains(QRegExp("girl"))) ? 2 : 0;
+
+ nameList.append(info);
+
+ row++;
+ }
+
+ return nameList;
+}
+
+int main(int argc, char* argv[])
{
- QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
- QApplication a(argc, argv);
+ int export_times = 0;
+ QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ QApplication a(argc, argv);
- QFont font(FONT_NAME, FONT_SIZE);
- QColor font_color(0, 0, 0);
- QGraphicsScene scene;
- QGraphicsView view(&scene);
- QImage image(BG_PATH);
- QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
- scene.addItem(bgItem);
-
+ QFont font(FONT_NAME, FONT_SIZE);
+ QColor font_color(0, 0, 0);
- for (int i = 0; i < BOY_POS_COUNT; i++) {
- QGraphicsTextItem* textItem = new QGraphicsTextItem(QStringLiteral("Ĭ\n´é\n¶£"));
- textItem->setFont(font);
- textItem->setDefaultTextColor(font_color);
- textItem->setPos(BOY_POS[i]);
- int xscale, yscale;
- xscale = yscale = (i % 2 == 1) ? -1 : 1;
- textItem->setTransform(QTransform::fromScale(xscale, yscale));
- scene.addItem(textItem);
- }
+
+ QList nameList = getNameByFile("name.csv");
+ if (nameList.isEmpty()) {
+ QMessageBox msgBox;
+ msgBox.setText(("Name is empty !"));
+ msgBox.exec();
+ }
+
+ QGraphicsScene scene;
+ QGraphicsView view(&scene);
+
+
+ for (int n = 0; n < nameList.length(); n++) {
+ //msgBox.setText(QString().sprintf("Export: %d / %d", export_times, nameList.length()));
+
+ NameInfo_t name_info = nameList.at(n);
+
+ scene.clear();
+ QImage image((name_info.bg_type == 1) ? BG_BOY_PATH : (name_info.bg_type == 2) ? BG_GIRL_PATH : BG_MIX_PATH);
+ QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
+ scene.addItem(bgItem);
+
+
+ for (int j = 0; j < 2; j++) {
+ int flag = j % 2;
+ QString name = (flag == 0) ? name_info.name1 : name_info.name2;
+ for (int i = 0; i < BOY_POS_COUNT; i++) {
+ int xscale, yscale;
+ xscale = yscale = (i % 2 == 1) ? -1 : 1;
+ QPointF pos = (flag == 0) ? BOY_POS[i] : GIRL_POS[i];
+
+ QGraphicsTextItem* textItem1 = new QGraphicsTextItem(name.mid(0, 1));
+ textItem1->setFont(font);
+ textItem1->setDefaultTextColor(font_color);
+ textItem1->setPos(pos);
+ textItem1->setTransform(QTransform::fromScale(xscale, yscale));
+ scene.addItem(textItem1);
+
+ QGraphicsTextItem* textItem2 = new QGraphicsTextItem(name.mid(1, 1));
+ textItem2->setFont(font);
+ textItem2->setDefaultTextColor(font_color);
+ textItem2->setPos(pos.x(), pos.y() + 148 * xscale);
+ textItem2->setTransform(QTransform::fromScale(xscale, yscale));
+ scene.addItem(textItem2);
+
+ QGraphicsTextItem* textItem3 = new QGraphicsTextItem(name.mid(2, 1));
+ textItem3->setFont(font);
+ textItem3->setDefaultTextColor(font_color);
+ textItem3->setPos(pos.x(), pos.y() + 294 * xscale);
+ textItem3->setTransform(QTransform::fromScale(xscale, yscale));
+ scene.addItem(textItem3);
+ }
+ }
+ QString file_name = QString("export_%1.jpg").arg(QString::number(n + 1));
+ saveToImage(file_name, &scene);
+ export_times++;
+ }
+
+
+ QMessageBox msgBox;
+ msgBox.setText(QString().sprintf("Export Finshed. Count:%d",export_times));
+ msgBox.exec();
- for (int i = 0; i < GIRL_POS_COUNT; i++) {
- QGraphicsTextItem* textItem = new QGraphicsTextItem(QStringLiteral("Ĭ\n¤_\n®¦"));
- textItem->setFont(font);
- textItem->setDefaultTextColor(font_color);
- textItem->setPos(GIRL_POS[i]);
- int xscale, yscale;
- xscale = yscale = (i % 2 == 1) ? -1 : 1;
- textItem->setTransform(QTransform::fromScale(xscale, yscale));
- scene.addItem(textItem);
- }
-
- view.show();
-
- saveToImage("test.jpg",&scene);
-
- return a.exec();
+ return 0;
}
diff --git a/NameCreater/resource/background_boy.jpg b/NameCreater/resource/background_boy.jpg
new file mode 100644
index 0000000..75b0fb5
Binary files /dev/null and b/NameCreater/resource/background_boy.jpg differ
diff --git a/NameCreater/resource/background_girl.jpg b/NameCreater/resource/background_girl.jpg
new file mode 100644
index 0000000..cb25e96
Binary files /dev/null and b/NameCreater/resource/background_girl.jpg differ