add old five code in.
This commit is contained in:
parent
425e9fead2
commit
3b7756393e
@ -9,6 +9,7 @@ struct NameInfo_t {
|
||||
QString name2;
|
||||
QString bg_path;
|
||||
bool is_number_bg;
|
||||
int bg_type;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <QBuffer>
|
||||
|
||||
#include "FiveToSingle.h"
|
||||
#include "OldFiveCreater.h"
|
||||
|
||||
|
||||
//#define BG_SAMPLE_PATH ":/NameCreater/resource/background_sample.jpg"
|
||||
@ -33,6 +34,7 @@ NameCreater::NameCreater(QWidget *parent)
|
||||
{
|
||||
ui.setupUi(this);
|
||||
connect(ui.fivesingle_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
||||
connect(ui.fiveold_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
|
||||
|
||||
QString font_path = FONT_PATH;
|
||||
QFile font_res(font_path);
|
||||
@ -67,13 +69,16 @@ NameCreater::NameCreater(QWidget *parent)
|
||||
}
|
||||
|
||||
void NameCreater::OnClickedReadBtn() {
|
||||
auto fileContentReady = [this](const QString &fileName, const QByteArray &fileContent) {
|
||||
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
|
||||
FiveToSingle().generaImageFromCSV(fileName, fileContent, this->font, this->font_color);
|
||||
if(sender == ui.fivesingle_btn) FiveToSingle().generaImageFromCSV(fileName, fileContent, this->font, this->font_color);
|
||||
if(sender == ui.fiveold_btn) OldFiveCreater().generaImageFromCSV(fileName, fileContent, this->font, this->font_color);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
@ -7,8 +7,15 @@
|
||||
message("You are running qmake on a generated .pro file. This may not work!")
|
||||
|
||||
|
||||
HEADERS += ./NameCreater.h
|
||||
SOURCES += ./NameCreater.cpp \
|
||||
./main.cpp
|
||||
HEADERS += ./FiveToSingle.h \
|
||||
./INameCreater.h \
|
||||
./resource.h \
|
||||
./NameCreater.h \
|
||||
./OldFiveCreater.h
|
||||
SOURCES += ./FiveToSingle.cpp \
|
||||
./INameCreater.cpp \
|
||||
./NameCreater.cpp \
|
||||
./main.cpp \
|
||||
./OldFiveCreater.cpp
|
||||
FORMS += ./NameCreater.ui
|
||||
RESOURCES += NameCreater.qrc
|
||||
|
||||
@ -175,6 +175,7 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="OldFiveCreater.cpp" />
|
||||
<QtRcc Include="NameCreater.qrc" />
|
||||
<QtUic Include="NameCreater.ui" />
|
||||
<QtMoc Include="NameCreater.h" />
|
||||
@ -186,6 +187,7 @@
|
||||
<ItemGroup>
|
||||
<ClInclude Include="FiveToSingle.h" />
|
||||
<ClInclude Include="INameCreater.h" />
|
||||
<ClInclude Include="OldFiveCreater.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@ -46,6 +46,9 @@
|
||||
<ClCompile Include="FiveToSingle.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="OldFiveCreater.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="INameCreater.h">
|
||||
@ -57,6 +60,9 @@
|
||||
<ClInclude Include="FiveToSingle.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="OldFiveCreater.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="NameCreater.rc">
|
||||
|
||||
152
NameCreater/OldFiveCreater.cpp
Normal file
152
NameCreater/OldFiveCreater.cpp
Normal file
@ -0,0 +1,152 @@
|
||||
#include "OldFiveCreater.h"
|
||||
#include <QMessageBox>
|
||||
#include <QTextCodec>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
#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"
|
||||
|
||||
static QPointF BOY_POS[] = {
|
||||
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, 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]);
|
||||
|
||||
|
||||
OldFiveCreater::OldFiveCreater():INameCreater()
|
||||
{
|
||||
}
|
||||
|
||||
OldFiveCreater::~OldFiveCreater()
|
||||
{
|
||||
}
|
||||
|
||||
QList<NameInfo_t> OldFiveCreater::getNameByFileContent(const QByteArray& conetent)
|
||||
{
|
||||
QList<NameInfo_t> nameList;
|
||||
|
||||
QTextCodec* tc = QTextCodec::codecForName("Big5");
|
||||
QString codec = tc->toUnicode(conetent.data());
|
||||
QTextStream stream(&codec);
|
||||
|
||||
int row = 0;
|
||||
while (!stream.atEnd())
|
||||
{
|
||||
NameInfo_t info;
|
||||
QString line = stream.readLine();
|
||||
QString name_tc = line;
|
||||
QStringList csvList = name_tc.split(',');
|
||||
|
||||
|
||||
QString name1 = csvList.at(0); //QString::fromLocal8Bit(csvList.at(0));
|
||||
QString name2 = csvList.at(1);//QString::fromLocal8Bit(csvList.at(1));
|
||||
QString type_str = csvList.last();//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;
|
||||
}
|
||||
|
||||
void OldFiveCreater::generaImageFromCSV(const QString& filename, const QByteArray& filecontent, const QFont& font, const QColor& font_color)
|
||||
{
|
||||
int export_times = 0;
|
||||
|
||||
QList<NameInfo_t> nameList = getNameByFileContent(filecontent);
|
||||
if (nameList.isEmpty()) {
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString("Name is empty ! ").append(filename));
|
||||
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);
|
||||
}
|
||||
}
|
||||
// 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);
|
||||
saveToImage(file_name, &scene);
|
||||
export_times++;
|
||||
}
|
||||
|
||||
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(QString().asprintf("Export Finshed. Count:%d", export_times));
|
||||
msgBox.exec();
|
||||
|
||||
|
||||
}
|
||||
15
NameCreater/OldFiveCreater.h
Normal file
15
NameCreater/OldFiveCreater.h
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include "INameCreater.h"
|
||||
class OldFiveCreater :
|
||||
public INameCreater
|
||||
{
|
||||
public:
|
||||
OldFiveCreater();
|
||||
~OldFiveCreater();
|
||||
|
||||
protected:
|
||||
QList<NameInfo_t> getNameByFileContent(const QByteArray& conetent);
|
||||
public:
|
||||
virtual void generaImageFromCSV(const QString& filename, const QByteArray& filecontent, const QFont& font, const QColor& font_color);
|
||||
};
|
||||
|
||||
4
NameCreater/_exp/old_five.csv
Normal file
4
NameCreater/_exp/old_five.csv
Normal file
@ -0,0 +1,4 @@
|
||||
name_1,name_2,bg_type
|
||||
ÄŹ´éśŁ,ÄŹ¤_ŽŚ,mix
|
||||
łŻĽKŽŚ,łŻŹfżÎ,boy
|
||||
§őŤBŞä,§őŤBŞä,girl
|
||||
|
BIN
NameCreater/resource/background.jpg
Normal file
BIN
NameCreater/resource/background.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
BIN
NameCreater/resource/background_boy.jpg
Normal file
BIN
NameCreater/resource/background_boy.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.5 MiB |
BIN
NameCreater/resource/background_girl.jpg
Normal file
BIN
NameCreater/resource/background_girl.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.6 MiB |
Loading…
x
Reference in New Issue
Block a user