finish layout adjustment.

This commit is contained in:
shouchih_chen 2022-02-19 08:44:26 +08:00
parent 4db00ecdfa
commit 615fa0e283
12 changed files with 197 additions and 141 deletions

View File

@ -1,8 +1,9 @@
<RCC> <RCC>
<qresource prefix="/NameCreater"> <qresource prefix="/NameCreater">
<file>resource/background.jpg</file>
<file>resource/background_sample.jpg</file> <file>resource/background_sample.jpg</file>
<file>resource/background_boy.jpg</file> <file>resource/background_b.jpg</file>
<file>resource/background_girl.jpg</file> <file>resource/background_g.jpg</file>
<file>resource/background_r.jpg</file>
<file>resource/background_y.jpg</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -1,4 +1,13 @@
name_1,name_2,bg_type name_1,bg_type
ÄŹ´éśŁ,ÄŹ¤_ŽŚ,mix <EFBFBD>,r
łŻĽKŽŚ,łŻŹfżÎ,boy <EFBFBD>,g
§őŤBŞä,§őŤBŞä,girl <EFBFBD>衱郝,b
<EFBFBD>,y
<EFBFBD>,r
<EFBFBD>,g
<EFBFBD>衱郝,b
<EFBFBD>,y
<EFBFBD>,r
<EFBFBD>,g
<EFBFBD>,y
<EFBFBD>,b

1 name_1 name_2 bg_type
2 ÄŹ´éśŁ ︺�诧 ÄŹ¤_ŽŚ mix r
3 łŻĽKŽŚ 甃�和 łŻŹfżÎ boy g
4 §őŤBŞä �衱郝 §őŤBŞä girl b
5 え�丹 y
6 ︺�诧 r
7 甃�和 g
8 �衱郝 b
9 え�丹 y
10 ︺�诧 r
11 甃�和 g
12 ︺�诧 y
13 甃�和 b

View File

@ -12,9 +12,9 @@
#include <QDateTime> #include <QDateTime>
#include <QFontDatabase> #include <QFontDatabase>
#define BG_MIX_PATH ":/NameCreater/resource/background.jpg"
#define BG_BOY_PATH ":/NameCreater/resource/background_boy.jpg" #define BG_SAMPLE_PATH ":/NameCreater/resource/background_sample.jpg"
#define BG_GIRL_PATH ":/NameCreater/resource/background_girl.jpg" #define BG_PATH_FORMAT ":/NameCreater/resource/background_%1.jpg"
#define FONT_NAME "DFYuanStd-W8.otf" #define FONT_NAME "DFYuanStd-W8.otf"
#define FONT_SIZE 120 #define FONT_SIZE 120
//#define FONT_SIZE 74 //#define FONT_SIZE 74
@ -26,29 +26,37 @@
struct NameInfo_t { struct NameInfo_t {
QString name1; QString name1;
QString name2; QString name2;
int bg_type; QString bg_path;
}; };
static QPointF BOY_POS[] = { static QPointF BG_POS[] = {
QPointF(235, 387), QPointF(366, 1433), QPointF(159, 61), QPointF(482, 61), QPointF(802, 61),
QPointF(555, 387), QPointF(692, 1433), QPointF(1122, 61), QPointF(1449, 61), QPointF(1772, 61),
QPointF(878, 387), QPointF(1014, 1433), QPointF(2095, 61), QPointF(2414, 61), QPointF(2738, 61),
QPointF(1200, 387), QPointF(1337, 1433), QPointF(3060, 61), QPointF(900, 2094), QPointF(900, 2420),
QPointF(1527, 387), QPointF(1663, 1433),
}; };
static int BOY_POS_COUNT = sizeof(BOY_POS) / sizeof(BOY_POS[0]); static int BG_POS_COUNT = sizeof(BG_POS) / sizeof(BG_POS[0]);
static QPointF GIRL_POS[] = { static QPointF NAME_POS[] = {
QPointF(1854, 387), QPointF(1987, 1433), QPointF(240, 430), QPointF(372, 1402),
QPointF(2176, 387), QPointF(2314, 1433), QPointF(564, 430), QPointF(694, 1402),
QPointF(2498, 387), QPointF(2635, 1433), QPointF(883, 430), QPointF(1014, 1402),
QPointF(2821, 387), QPointF(2958, 1433), QPointF(1205, 430), QPointF(1337, 1402),
QPointF(3147, 387), QPointF(3285, 1433), QPointF(1532, 430), QPointF(1663, 1402),
QPointF(1854, 430), QPointF(1987, 1402),
QPointF(2176, 430), QPointF(2309, 1402),
QPointF(2498, 430), QPointF(2629, 1402),
QPointF(2821, 430), QPointF(2952, 1402),
QPointF(3145, 430), QPointF(3276, 1402),
QPointF(1268, 2012), QPointF(2240, 1880),
QPointF(1268, 2334), QPointF(2240, 2202),
}; };
static int GIRL_POS_COUNT = sizeof(GIRL_POS) / sizeof(GIRL_POS[0]); static int NAME_POS_COUNT = sizeof(NAME_POS) / sizeof(NAME_POS[0]);
@ -67,7 +75,7 @@ void saveToImage(const QString& filename, QGraphicsScene* scene) {
scene->render(&painter); scene->render(&painter);
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QString folder_name = QCoreApplication::applicationDirPath()+"/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd"); QString folder_name = QCoreApplication::applicationDirPath() + "/../../../export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#else #else
QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd"); QString folder_name = QCoreApplication::applicationDirPath() + "/export_" + QDateTime::currentDateTime().toString("yyyyMMdd");
#endif #endif
@ -102,7 +110,7 @@ QList<NameInfo_t> getNameByFile(const QString& filename) {
} }
int row = 0; int row = 0;
QTextCodec *tc = QTextCodec::codecForName("Big5"); QTextCodec* tc = QTextCodec::codecForName("Big5");
while (!file.atEnd()) while (!file.atEnd())
{ {
NameInfo_t info; NameInfo_t info;
@ -111,18 +119,18 @@ QList<NameInfo_t> getNameByFile(const QString& filename) {
QStringList csvList = name_tc.split(','); QStringList csvList = name_tc.split(',');
QString name1 = csvList.at(0); //QString::fromLocal8Bit(csvList.at(0)); QString name1 = csvList.at(0);
QString name2 = csvList.at(1);//QString::fromLocal8Bit(csvList.at(1));
QString type_str = csvList.last();//QString::fromLocal8Bit(csvList.last()); QString type_str = csvList.last();//QString::fromLocal8Bit(csvList.last());
qDebug() << "row :" << row << " " << name1 << " " << name2; qDebug() << "row :" << row << " " << name1;
type_str = type_str.remove(QRegExp("\r\n"));
if (name1.compare("name_1") == 0 || name2.compare("name_2") == 0) { if (name1.compare("name_1") == 0) {
continue; continue;
} }
info.name1 = name1; info.name1 = name1;
info.name2 = name2; info.bg_path = QString(BG_PATH_FORMAT).arg(type_str);
info.bg_type = type_str.contains(QRegExp("boy")) ? 1 : (type_str.contains(QRegExp("girl"))) ? 2 : 0;
nameList.append(info); nameList.append(info);
@ -139,8 +147,8 @@ int main(int argc, char* argv[])
QApplication a(argc, argv); QApplication a(argc, argv);
// NameCreater w; // NameCreater w;
// w.show(); // w.show();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
QString root_path = QCoreApplication::applicationDirPath() + "/../../../"; QString root_path = QCoreApplication::applicationDirPath() + "/../../../";
#else #else
@ -170,68 +178,106 @@ int main(int argc, char* argv[])
msgBox.exec(); msgBox.exec();
} }
QGraphicsScene scene; QGraphicsScene scene(0, 0, 3508, 2482);
scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
QGraphicsView view(&scene); QGraphicsView view(&scene);
//QImage image(BG_SAMPLE_PATH);
//QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image));
//scene.addItem(bgItem);
for (int n = 0; n < nameList.length(); n++) { for (int n = 0; n < nameList.length(); n++) {
//msgBox.setText(QString().sprintf("Export: %d / %d", export_times, nameList.length())); if (n >= BG_POS_COUNT)break;
NameInfo_t name_info = nameList.at(n); NameInfo_t name_info = nameList.at(n);
QImage name_image(name_info.bg_path);
scene.clear(); QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(name_image));
QImage image((name_info.bg_type == 1) ? BG_BOY_PATH : (name_info.bg_type == 2) ? BG_GIRL_PATH : BG_MIX_PATH); bool rot = (n == 10 || n == 11);
QGraphicsPixmapItem* bgItem = new QGraphicsPixmapItem(QPixmap::fromImage(image)); name_bgItem->setRotation(rot ? -90 : 0);
scene.addItem(bgItem); name_bgItem->setPos(BG_POS[n]);
scene.addItem(name_bgItem);
if (name_info.name1.isEmpty()) {
QMessageBox msgBox;
msgBox.setText(QString().asprintf("Name is Empty at %d", export_times + 1));
msgBox.exec();
}
QString name = name_info.name1;
for (int j = 0; j < 2; j++) { for (int j = 0; j < 2; j++) {
int flag = j % 2; int pos_idx = n * 2 + j;
QString name = (flag == 0) ? name_info.name1 : name_info.name2;
for (int i = 0; i < BOY_POS_COUNT; i++) {
int xscale, yscale; int xscale, yscale;
xscale = yscale = (i % 2 == 1) ? -1 : 1;
QPointF pos = (flag == 0) ? BOY_POS[i] : GIRL_POS[i]; xscale = yscale = (j == 1) ? -1 : 1;
QPointF pos = NAME_POS[pos_idx];
QGraphicsTextItem* textItem1 = new QGraphicsTextItem(name.mid(0, 1)); QGraphicsTextItem* textItem1 = new QGraphicsTextItem(name.mid(0, 1));
textItem1->setFont(font); textItem1->setFont(font);
textItem1->setDefaultTextColor(font_color); textItem1->setDefaultTextColor(font_color);
if (!rot) {
textItem1->setPos(pos); textItem1->setPos(pos);
textItem1->setTransform(QTransform::fromScale(xscale, yscale)); textItem1->setTransform(QTransform::fromScale(xscale, yscale));
}
else {
textItem1->setPos(pos);
textItem1->setRotation(-90);
textItem1->setTransform(QTransform::fromScale(xscale, yscale));
}
scene.addItem(textItem1); scene.addItem(textItem1);
QGraphicsTextItem* textItem2 = new QGraphicsTextItem(name.mid(1, 1)); QGraphicsTextItem* textItem2 = new QGraphicsTextItem(name.mid(1, 1));
textItem2->setFont(font); textItem2->setFont(font);
textItem2->setDefaultTextColor(font_color); textItem2->setDefaultTextColor(font_color);
textItem2->setPos(pos.x(), pos.y() + 148 * xscale); if (!rot) {
textItem2->setPos(pos.x(), pos.y() + 145 * xscale);
textItem2->setTransform(QTransform::fromScale(xscale, yscale)); textItem2->setTransform(QTransform::fromScale(xscale, yscale));
}
else {
textItem2->setPos(pos.x() + 145 * xscale, pos.y());
textItem2->setRotation(-90);
textItem2->setTransform(QTransform::fromScale(xscale, yscale));
}
scene.addItem(textItem2); scene.addItem(textItem2);
QGraphicsTextItem* textItem3 = new QGraphicsTextItem(name.mid(2, 1)); QGraphicsTextItem* textItem3 = new QGraphicsTextItem(name.mid(2, 1));
textItem3->setFont(font); textItem3->setFont(font);
textItem3->setDefaultTextColor(font_color); textItem3->setDefaultTextColor(font_color);
textItem3->setPos(pos.x(), pos.y() + 294 * xscale); if (!rot) {
textItem3->setPos(pos.x(), pos.y() + 290 * xscale);
textItem3->setTransform(QTransform::fromScale(xscale, yscale)); textItem3->setTransform(QTransform::fromScale(xscale, yscale));
scene.addItem(textItem3);
} }
else {
textItem3->setPos(pos.x() + 290 * xscale, pos.y());
textItem3->setRotation(-90);
textItem3->setTransform(QTransform::fromScale(xscale, yscale));
} }
// if (name_info.bg_type == 0) {
// view.show();
// break;
// }
QString file_name = QString("%1_%2_%3.jpg").arg(QString::number(export_times+1),name_info.name1,name_info.name2); scene.addItem(textItem3);
}
}
QString file_name = QString("%1_.jpg").arg(QString::number(export_times + 1));
saveToImage(file_name, &scene); saveToImage(file_name, &scene);
export_times++; export_times++;
}
/*QMessageBox msgBox;
QMessageBox msgBox; msgBox.setText(QString().asprintf("Export Finshed. Count:%d", export_times));
msgBox.setText(QString().asprintf("Export Finshed. Count:%d",export_times)); msgBox.exec();*/
msgBox.exec();
font_res.close(); font_res.close();
return 0; return a.exec();
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 MiB

After

Width:  |  Height:  |  Size: 2.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB