add towel creater

This commit is contained in:
shouchih_chen 2023-05-04 23:22:47 +08:00
parent 3da5037ca7
commit 3b6987bb8b
14 changed files with 239 additions and 25 deletions

View File

@ -4,8 +4,7 @@
#include <QDebug> #include <QDebug>
#include <QMessageBox> #include <QMessageBox>
#define BG_WIDTH 3508
#define BG_HEIGHT 2481
#define LABEL_HIGHT_LIMIT 350.0 #define LABEL_HIGHT_LIMIT 350.0
#define LABEL_POS_X_OFFSET 323.0 #define LABEL_POS_X_OFFSET 323.0

View File

@ -80,7 +80,8 @@ void FiveToSingle::generaImageFromCSV(const QString& filename, const QByteArray&
NameInfo_t name_info = nameList.at(n); NameInfo_t name_info = nameList.at(n);
QImage name_image(name_info.bg_path); QImage name_image(name_info.bg_path);
if (idx == 0) { if (idx == 0) {
QGraphicsRectItem* bg_item = new QGraphicsRectItem(0, 0, 3508, 2482);
QGraphicsRectItem* bg_item = new QGraphicsRectItem(0, 0, BG_WIDTH, BG_HEIGHT);
bg_item->setBrush(QBrush(QColor(255, 255, 255))); bg_item->setBrush(QBrush(QColor(255, 255, 255)));
scene.addItem(bg_item); scene.addItem(bg_item);
} }

View File

@ -4,6 +4,9 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QGraphicsRectItem> #include <QGraphicsRectItem>
#define BG_WIDTH 3508
#define BG_HEIGHT 2481
struct NameInfo_t { struct NameInfo_t {
QString name1; QString name1;
QString name2; QString name2;

View File

@ -13,11 +13,15 @@
#include "FiveToSingle.h" #include "FiveToSingle.h"
#include "OldFiveCreater.h" #include "OldFiveCreater.h"
#include "BirthdayCreater.h" #include "BirthdayCreater.h"
#include "TowelCreater.h"
#define FONT_NAME "DFYuanStd-W8.otf" #define FONT_NAME "DFYuanStd-W8.otf"
#define FONT_PATH ":/NameCreater/_exp/DFYuanStd-W8.otf" #define FONT_PATH ":/NameCreater/_exp/DFYuanStd-W8.otf"
#define FONT_SIZE 120 #define FONT_SIZE 120
#define TOWEL_FONT_PATH ":/NameCreater/_exp/W1.ttc"
#define VERSION "v1.2.0" #define VERSION "v1.2.0"
@ -28,6 +32,7 @@ NameCreater::NameCreater(QWidget *parent)
connect(ui.fivesingle_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn); connect(ui.fivesingle_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
connect(ui.fiveold_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.birthday_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
connect(ui.towel_btn, &QPushButton::released, this, &NameCreater::OnClickedReadBtn);
QString font_path = FONT_PATH; QString font_path = FONT_PATH;
QFile font_res(font_path); QFile font_res(font_path);
@ -41,9 +46,24 @@ NameCreater::NameCreater(QWidget *parent)
int id = QFontDatabase::addApplicationFontFromData(font_res.readAll()); int id = QFontDatabase::addApplicationFontFromData(font_res.readAll());
QStringList family_list = QFontDatabase::applicationFontFamilies(id); QStringList family_list = QFontDatabase::applicationFontFamilies(id);
font = QFont(family_list.at(0)); font = QFont(family_list.at(0));
font.setPixelSize(FONT_SIZE); font.setPixelSize(FONT_SIZE);
font_res.close();
font_path = QString(TOWEL_FONT_PATH);
QFile font_res_towel(font_path);
if (!font_res_towel.open(QIODevice::ReadOnly)) {
QMessageBox msgBox;
msgBox.setText("Can not load font file!" + font_path);
msgBox.exec();
font_res_towel.close();
}
id = QFontDatabase::addApplicationFontFromData(font_res_towel.readAll());
font_towel = QFont(QFontDatabase::applicationFontFamilies(id).at(0));
font_towel.setPixelSize(240);
font_towel.setLetterSpacing(QFont::PercentageSpacing, 42);
font_color = QColor(0, 0, 0); font_color = QColor(0, 0, 0);
QFont tital_font = QFont(font); QFont tital_font = QFont(font);
@ -56,13 +76,13 @@ NameCreater::NameCreater(QWidget *parent)
ui.version_label->setFont(version_font); ui.version_label->setFont(version_font);
ui.version_label->setText(VERSION); ui.version_label->setText(VERSION);
QList<QLabel*> titals = this->findChildren<QLabel*>(QRegExp("tital_label")); QList<QLabel*> titals = findChildren<QLabel*>(QRegExp("tital_label"));
foreach(auto tital, titals) { foreach(auto tital, titals) {
tital->setFont(tital_font); tital->setFont(tital_font);
} }
font_res.close();
} }
@ -79,6 +99,7 @@ void NameCreater::OnClickedReadBtn() {
if(sender == ui.fivesingle_btn) 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); if(sender == ui.fiveold_btn) OldFiveCreater().generaImageFromCSV(fileName, fileContent, this->font, this->font_color);
if(sender == ui.birthday_btn) BirthdayCreater().generaImageFromCSV(fileName, fileContent, this->font, this->font_color); if(sender == ui.birthday_btn) BirthdayCreater().generaImageFromCSV(fileName, fileContent, this->font, this->font_color);
if (sender == ui.towel_btn) TowelCreater().generaImageFromCSV(fileName, fileContent, this->font_towel, this->font_color);
} }
}; };

View File

@ -12,10 +12,12 @@ public:
private: private:
Ui::NameCreaterClass ui; Ui::NameCreaterClass ui;
QFont font; QFont font, font_towel;
QColor font_color; QColor font_color;
private Q_SLOTS: private Q_SLOTS:
void OnClickedReadBtn(); void OnClickedReadBtn();
}; };

View File

@ -9,15 +9,17 @@ message("You are running qmake on a generated .pro file. This may not work!")
HEADERS += ./resource.h \ HEADERS += ./resource.h \
./NameCreater.h \ ./NameCreater.h \
./BirthdayCreater.h \
./FiveToSingle.h \ ./FiveToSingle.h \
./INameCreater.h \ ./INameCreater.h \
./OldFiveCreater.h \ ./OldFiveCreater.h \
./BirthdayCreater.h ./TowelCreater.h
SOURCES += ./NameCreater.cpp \ SOURCES += ./NameCreater.cpp \
./main.cpp \ ./main.cpp \
./BirthdayCreater.cpp \
./OldFiveCreater.cpp \ ./OldFiveCreater.cpp \
./FiveToSingle.cpp \ ./FiveToSingle.cpp \
./INameCreater.cpp \ ./INameCreater.cpp \
./BirthdayCreater.cpp ./TowelCreater.cpp
FORMS += ./NameCreater.ui FORMS += ./NameCreater.ui
RESOURCES += NameCreater.qrc RESOURCES += NameCreater.qrc

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 6.0.2, 2023-05-04T11:12:11. --> <!-- Written by QtCreator 7.0.2, 2023-05-04T22:24:36. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
<value type="QByteArray">{f917f426-b975-46c9-8edb-fd77a95b6be2}</value> <value type="QByteArray">{4a5c8cc9-7483-402d-a0a2-3701e5257fd0}</value>
</data> </data>
<data> <data>
<variable>ProjectExplorer.Project.ActiveTarget</variable> <variable>ProjectExplorer.Project.ActiveTarget</variable>
@ -91,16 +91,16 @@
<variable>ProjectExplorer.Project.Target.0</variable> <variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap"> <valuemap type="QVariantMap">
<value type="QString" key="DeviceType">Desktop</value> <value type="QString" key="DeviceType">Desktop</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.15.2 MSVC2019 64bit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.15.2 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.15.2 MSVC2019 64bit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.15.2 MinGW 64-bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5152.win64_msvc2019_64_kit</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.qt5.5152.win64_mingw81_kit</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value> <value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="int" key="EnableQmlDebugging">0</value> <value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\_0E\_Private\_Software\namecreater\build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\_develop\_project\NameCreater\build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Debug</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/_0E/_Private/_Software/namecreater/build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/_develop/_project/NameCreater/build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -138,8 +138,8 @@
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value> <value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\_0E\_Private\_Software\namecreater\build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Release</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\_develop\_project\NameCreater\build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Release</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/_0E/_Private/_Software/namecreater/build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Release</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/_develop/_project/NameCreater/build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -179,8 +179,8 @@
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="int" key="EnableQmlDebugging">0</value> <value type="int" key="EnableQmlDebugging">0</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\_0E\_Private\_Software\namecreater\build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Profile</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">D:\_develop\_project\NameCreater\build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Profile</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/_0E/_Private/_Software/namecreater/build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Profile</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">D:/_develop/_project/NameCreater/build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -257,14 +257,14 @@
<valuelist type="QVariantList" key="CustomOutputParsers"/> <valuelist type="QVariantList" key="CustomOutputParsers"/>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/_0E/_Private/_Software/namecreater/NameCreater/NameCreater.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:D:/_develop/_project/NameCreater/NameCreater/NameCreater.pro</value>
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/_0E/_Private/_Software/namecreater/NameCreater/NameCreater.pro</value> <value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">D:/_develop/_project/NameCreater/NameCreater/NameCreater.pro</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value> <value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value> <value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value> <value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
<value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/_0E/_Private/_Software/namecreater/build-NameCreater-Desktop_Qt_5_15_2_MSVC2019_64bit-Debug</value> <value type="QString" key="RunConfiguration.WorkingDirectory.default">D:/_develop/_project/NameCreater/build-NameCreater-Desktop_Qt_5_15_2_MinGW_64_bit-Debug</value>
</valuemap> </valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value> <value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap> </valuemap>

View File

@ -44,5 +44,6 @@
<file>resource/st.jpg</file> <file>resource/st.jpg</file>
<file>resource/w.jpg</file> <file>resource/w.jpg</file>
<file>resource/y.jpg</file> <file>resource/y.jpg</file>
<file>_exp/W1.ttc</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -180,6 +180,7 @@
<ItemGroup> <ItemGroup>
<ClCompile Include="BirthdayCreater.cpp" /> <ClCompile Include="BirthdayCreater.cpp" />
<ClCompile Include="OldFiveCreater.cpp" /> <ClCompile Include="OldFiveCreater.cpp" />
<ClCompile Include="TowelCreater.cpp" />
<QtRcc Include="NameCreater.qrc" /> <QtRcc Include="NameCreater.qrc" />
<QtUic Include="NameCreater.ui" /> <QtUic Include="NameCreater.ui" />
<QtMoc Include="NameCreater.h" /> <QtMoc Include="NameCreater.h" />
@ -194,6 +195,7 @@
<ClInclude Include="INameCreater.h" /> <ClInclude Include="INameCreater.h" />
<ClInclude Include="OldFiveCreater.h" /> <ClInclude Include="OldFiveCreater.h" />
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="TowelCreater.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="NameCreater.rc" /> <ResourceCompile Include="NameCreater.rc" />

View File

@ -55,6 +55,9 @@
<ClCompile Include="BirthdayCreater.cpp"> <ClCompile Include="BirthdayCreater.cpp">
<Filter>Creaters</Filter> <Filter>Creaters</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="TowelCreater.cpp">
<Filter>Creaters</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="resource.h"> <ClInclude Include="resource.h">
@ -72,6 +75,9 @@
<ClInclude Include="BirthdayCreater.h"> <ClInclude Include="BirthdayCreater.h">
<Filter>Creaters</Filter> <Filter>Creaters</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="TowelCreater.h">
<Filter>Creaters</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="NameCreater.rc"> <ResourceCompile Include="NameCreater.rc">

View File

@ -0,0 +1,158 @@
#include "TowelCreater.h"
#include <QTextCodec>
#include <QTextStream>
#include <qDebug>
#include <QMessageBox>
static QString LABEL_BG_PATH[] = { ":/NameCreater/resource/girl_bg.jpg",":/NameCreater/resource/boy_bg.jpg" };
static qreal LABEL_POS_X[] = { 250,1645,3300 };
static qreal LABEL_POS_Y_START = 120;
static qreal LABEL_POS_Y_DIFF = 315;
static qreal NAME_OFFSET_X[] = { 128, 715 };
static qreal NAME_OFFSET_Y = 38;
static qreal NAME_TWO_WORD_OFFSET = 25;
static int MAX_LABEL_IN_PAPER = 15;
static int LABEL_MAX_NUM_PER_COL = 7;
static int FONT_PIXEL_SIZE = 240;
static qreal LABEL_HIGHT_LIMIT = 350;
static int TEXT_WIDTH = 800;
TowelCreater::TowelCreater()
{
}
TowelCreater::~TowelCreater()
{
}
QList<NameInfo_t> TowelCreater::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())
{
QString line = stream.readLine();
QString name_tc = line;
QStringList csvList = name_tc.split(',');
QString name = csvList.at(0); //QString::fromLocal8Bit(csvList.at(0));
QString bg_type = csvList.at(1);//QString::fromLocal8Bit(csvList.at(1));
int num = csvList.last().toInt();//QString::fromLocal8Bit(csvList.last());
qDebug() << "row :" << row << " " << name << ", bg_type: " << bg_type << "Count: " <<QString::number(num);
if (name.compare("name") == 0) {
//pass first line
continue;
}
else {
for (int i = 0; i < num; ++i) {
NameInfo_t info;
info.name1 = name;
info.bg_type = (bg_type.compare("g") == 0) ? 0 : 1;
nameList.append(info);
}
}
row++;
}
return nameList;
}
void TowelCreater::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;
scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
QGraphicsView view(&scene);
for (int idx = 0; idx < nameList.length(); idx++) {
NameInfo_t name = nameList.at(idx);
if ((idx % MAX_LABEL_IN_PAPER) == 0) {
QGraphicsRectItem* bg_item = new QGraphicsRectItem(0, 0, BG_WIDTH, BG_HEIGHT);
bg_item->setBrush(QBrush(QColor(255, 255, 255)));
//QGraphicsPixmapItem* bg_item = QGraphicsPixmapItem(QPixmap(BG_SMAPLE_PATH));
scene.addItem(bg_item);
}
int col_idx = (idx % MAX_LABEL_IN_PAPER) / LABEL_MAX_NUM_PER_COL;
int col_num = (idx % MAX_LABEL_IN_PAPER) % LABEL_MAX_NUM_PER_COL;
QString label_rel_path = LABEL_BG_PATH[name.bg_type];
if (col_idx < 2) {
QGraphicsPixmapItem* label_item = new QGraphicsPixmapItem(QPixmap(label_rel_path));
label_item->setPos(LABEL_POS_X[col_idx], LABEL_POS_Y_START + LABEL_POS_Y_DIFF * col_num);
label_item->setOpacity(1);
scene.addItem(label_item);
for (int i = 0; i < 2; ++i) {
qreal offset_x = name.name1.count() == 2 ? NAME_TWO_WORD_OFFSET : 0;
QGraphicsTextItem* name_item = new QGraphicsTextItem(name.name1);
name_item->setTextWidth(TEXT_WIDTH);
name_item->setFont(font);
name_item->setDefaultTextColor(font_color);
name_item->setPos(label_item->x() + NAME_OFFSET_X[i] + offset_x, label_item->y() + NAME_OFFSET_Y);
scene.addItem(name_item);
}
}
else {
QGraphicsPixmapItem* label_item = new QGraphicsPixmapItem(QPixmap(label_rel_path));
label_item->setRotation(90);
label_item->setPos(LABEL_POS_X[col_idx], LABEL_POS_Y_START + LABEL_POS_Y_DIFF * col_num);
label_item->setOpacity(1);
scene.addItem(label_item);
for (int i = 0; i < 2; ++i) {
qreal offset_x = name.name1.count() == 2 ? NAME_TWO_WORD_OFFSET : 0;
QGraphicsTextItem* name_item = new QGraphicsTextItem(name.name1);
name_item->setTextWidth(TEXT_WIDTH);
name_item->setFont(font);
name_item->setDefaultTextColor(font_color);
name_item->setRotation(90);
name_item->setPos(label_item->x() - NAME_OFFSET_Y, label_item->y() + NAME_OFFSET_X[i] + offset_x);
scene.addItem(name_item);
}
}
if ((idx % MAX_LABEL_IN_PAPER == MAX_LABEL_IN_PAPER - 1) || idx == nameList.count() - 1) {
QString file_name = QString("%1_.jpg").arg(QString::number(export_times + 1));
saveToImage(file_name, &scene);
export_times++;
scene.clear();
}
}
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "INameCreater.h"
class TowelCreater : public INameCreater
{
public:
TowelCreater();
~TowelCreater();
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);
};

BIN
NameCreater/_exp/W1.ttc Normal file

Binary file not shown.

View File

@ -0,0 +1,5 @@
name,bg_type,num
³¯¦u§Ó,b,16
§d¨Î¹a,g,13
«Å´r,b,1
«Å´r,g,2
1 name bg_type num
2 ³¯¦u§Ó b 16
3 §d¨Î¹a g 13
4 «Å´r b 1
5 «Å´r g 2