1. Add custom logo can export double name 2. add color selector for custom logo.
This commit is contained in:
parent
cbba28fcf5
commit
40d41b36e2
@ -9,34 +9,57 @@
|
|||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QColorDialog>
|
||||||
|
|
||||||
|
|
||||||
static QPointF BG_POS[] = {
|
static QPointF BG_POS_START = QPointF(159, 61);
|
||||||
QPointF(159, 61), QPointF(482, 61), QPointF(802, 61),
|
static QPointF BG_POS_ROT_START = QPointF(900, 2094);
|
||||||
QPointF(1122, 61), QPointF(1449, 61), QPointF(1772, 61),
|
static qreal BG_WIDTH_OFFSET = 320;
|
||||||
QPointF(2095, 61), QPointF(2414, 61), QPointF(2738, 61),
|
static int NAME_COUNT_IN_PAGE = 12;
|
||||||
QPointF(3060, 61), QPointF(900, 2094), QPointF(900, 2420),
|
|
||||||
};
|
|
||||||
|
|
||||||
static int BG_POS_COUNT = sizeof(BG_POS) / sizeof(BG_POS[0]);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static QPointF NAME_OFFSET_START = QPointF(79, 377);
|
static QPointF NAME_OFFSET_START = QPointF(79, 377);
|
||||||
static qreal EACH_WORD_OFFSET = 142;
|
static qreal EACH_WORD_OFFSET = 142;
|
||||||
|
|
||||||
static QColor FONT_COLOR = QColor(0, 0, 0);
|
static QColor FONT_COLOR = QColor(0, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class QGraphicsCloneTextItem : public QGraphicsTextItem {
|
||||||
|
public:
|
||||||
|
QGraphicsCloneTextItem(const QString& text, QGraphicsItem* parent = nullptr) :
|
||||||
|
QGraphicsTextItem(text, parent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsCloneTextItem* clone(QGraphicsItem* parent = nullptr) const {
|
||||||
|
|
||||||
|
QGraphicsCloneTextItem* newItem = new QGraphicsCloneTextItem(toPlainText(), parent);
|
||||||
|
newItem->setFont(font());
|
||||||
|
newItem->setPos(pos());
|
||||||
|
newItem->setDefaultTextColor(defaultTextColor());
|
||||||
|
return newItem;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
CustomLogo::CustomLogo(QFont* font, QDialog* parent) :
|
CustomLogo::CustomLogo(QFont* font, QDialog* parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::CustomLogo),
|
ui(new Ui::CustomLogo),
|
||||||
customFont(font)
|
customFont(font),
|
||||||
|
fontColor(QColor(0, 0, 0))
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
|
||||||
connect(ui->load_bg_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
connect(ui->load_bg_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
||||||
connect(ui->load_list_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
connect(ui->load_list_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
||||||
|
connect(ui->color_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
||||||
|
|
||||||
|
QPalette palette = ui->color_label->palette();
|
||||||
|
palette.setColor(QPalette::WindowText, fontColor);
|
||||||
|
ui->color_label->setPalette(palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
CustomLogo::~CustomLogo()
|
CustomLogo::~CustomLogo()
|
||||||
@ -49,11 +72,13 @@ void CustomLogo::loadBGFromFile()
|
|||||||
auto fileContentReady = [this](const QString& fileName, const QByteArray& fileContent) {
|
auto fileContentReady = [this](const QString& fileName, const QByteArray& fileContent) {
|
||||||
if (fileName.isEmpty()) {
|
if (fileName.isEmpty()) {
|
||||||
// No file was selected
|
// No file was selected
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
QPixmap pix;
|
QPixmap pix;
|
||||||
if (pix.loadFromData(fileContent, "JPG")) {
|
if (pix.loadFromData(fileContent, "JPG")) {
|
||||||
ui->display_label->setPixmap(pix);
|
ui->display_label->setPixmap(pix);
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
qDebug() << "Data content not image format";
|
qDebug() << "Data content not image format";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +121,7 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
|
|||||||
case Name_zh:
|
case Name_zh:
|
||||||
{
|
{
|
||||||
for (int n = 0; n < nameList.length(); n++) {
|
for (int n = 0; n < nameList.length(); n++) {
|
||||||
int idx = n % BG_POS_COUNT;
|
int idx = n % NAME_COUNT_IN_PAGE;
|
||||||
NameInfo_t name_info = nameList.at(n);
|
NameInfo_t name_info = nameList.at(n);
|
||||||
|
|
||||||
if (idx == 0) {
|
if (idx == 0) {
|
||||||
@ -117,7 +142,9 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
|
|||||||
QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(_bg);
|
QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(_bg);
|
||||||
bool rot = (idx == 10 || idx == 11);
|
bool rot = (idx == 10 || idx == 11);
|
||||||
name_bgItem->setRotation(rot ? -90 : 0);
|
name_bgItem->setRotation(rot ? -90 : 0);
|
||||||
name_bgItem->setPos(BG_POS[idx]);
|
qreal item_pos_x = rot ? BG_POS_ROT_START.x() : BG_POS_START.x() + idx * BG_WIDTH_OFFSET;
|
||||||
|
qreal item_pos_y = rot ? BG_POS_ROT_START.y() + (idx - 10) * BG_WIDTH_OFFSET : BG_POS_START.y();
|
||||||
|
name_bgItem->setPos(item_pos_x, item_pos_y);
|
||||||
scene.addItem(name_bgItem);
|
scene.addItem(name_bgItem);
|
||||||
|
|
||||||
|
|
||||||
@ -126,35 +153,39 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
|
|||||||
msgBox.setText(QString().asprintf("Name is Empty at %d", export_times + 1));
|
msgBox.setText(QString().asprintf("Name is Empty at %d", export_times + 1));
|
||||||
msgBox.exec();
|
msgBox.exec();
|
||||||
}
|
}
|
||||||
|
QGraphicsRectItem* name_rectItem = new QGraphicsRectItem(QRectF(0, 0, name_bgItem->boundingRect().width(), name_bgItem->boundingRect().height()/2), name_bgItem);
|
||||||
|
name_rectItem->setPen(QPen(QColor(0, 0, 0, 0)));
|
||||||
|
|
||||||
QString name = name_info.name1;
|
QString name = name_info.name1;
|
||||||
int name_len = name.length();
|
int name_len = name.length();
|
||||||
for (int j = 0; j < 1; j++) { // never reverse
|
|
||||||
qreal xscale, yscale;
|
|
||||||
|
|
||||||
xscale = yscale = (j == 1) ? -1 : 1;
|
|
||||||
QPointF pos = NAME_OFFSET_START;
|
QPointF pos = NAME_OFFSET_START;
|
||||||
qreal y_offset = 0;
|
qreal y_offset = 0;
|
||||||
if (name_len == 2) {
|
if (name_len == 2) {
|
||||||
if (!rot) {
|
pos.setY(pos.y() + 82.0 );
|
||||||
pos.setY(pos.y() + 82.0 * xscale);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
pos.setX(pos.x() + 82.0 * xscale);
|
|
||||||
|
|
||||||
}
|
|
||||||
y_offset = 25;
|
y_offset = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int k = 0; k < name_len; k++) {
|
for (int k = 0; k < name_len; k++) {
|
||||||
QGraphicsTextItem* textItem = new QGraphicsTextItem(name.mid(k, 1), name_bgItem);
|
QGraphicsCloneTextItem* textItem = new QGraphicsCloneTextItem(name.mid(k, 1), name_rectItem);
|
||||||
textItem->setFont(*customFont);
|
textItem->setFont(*customFont);
|
||||||
textItem->setDefaultTextColor(FONT_COLOR);
|
textItem->setDefaultTextColor(fontColor);
|
||||||
textItem->setPos(pos.x(), pos.y() + k * EACH_WORD_OFFSET + y_offset);
|
textItem->setPos(pos.x(), pos.y() + k * EACH_WORD_OFFSET + y_offset);
|
||||||
textItem->setTransform(QTransform::fromScale(xscale, yscale));
|
|
||||||
scene.addItem(textItem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (ui->double_checkbox->isChecked()) {
|
||||||
|
QGraphicsRectItem* name_reverse_rectItem = new QGraphicsRectItem(name_rectItem->rect(), name_bgItem);
|
||||||
|
name_reverse_rectItem->setPen(QPen(QColor(0, 0, 0, 0)));
|
||||||
|
name_reverse_rectItem->setPos(name_bgItem->boundingRect().width(), name_bgItem->boundingRect().height());
|
||||||
|
foreach(auto item, name_rectItem->childItems()) {
|
||||||
|
QGraphicsCloneTextItem* _ti = ((QGraphicsCloneTextItem*)item)->clone(name_reverse_rectItem);
|
||||||
}
|
}
|
||||||
bool is_export_page = ((idx + 1) % BG_POS_COUNT == 0);
|
name_reverse_rectItem->setRotation(180);
|
||||||
|
qDebug() << "name_rect item child count:" << name_rectItem->childItems().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool is_export_page = ((idx + 1) % NAME_COUNT_IN_PAGE == 0);
|
||||||
if (is_export_page || n == nameList.count() - 1) {
|
if (is_export_page || n == nameList.count() - 1) {
|
||||||
QString date_str = QDateTime::currentDateTime().toString("MMddhhmm");
|
QString date_str = QDateTime::currentDateTime().toString("MMddhhmm");
|
||||||
QString file_name = QString("Signal_%2_%1.jpg").arg(QString::number(export_times + 1), date_str);
|
QString file_name = QString("Signal_%2_%1.jpg").arg(QString::number(export_times + 1), date_str);
|
||||||
@ -232,6 +263,17 @@ void CustomLogo::onClickedBtn() {
|
|||||||
else if (sender == ui->load_list_btn) {
|
else if (sender == ui->load_list_btn) {
|
||||||
loadListFromFile();
|
loadListFromFile();
|
||||||
}
|
}
|
||||||
|
else if (sender == ui->color_btn) {
|
||||||
|
|
||||||
|
QColor color = QColorDialog::getColor(Qt::red, this);
|
||||||
|
|
||||||
|
if (color.isValid()) {
|
||||||
|
fontColor = color;
|
||||||
|
QPalette palette = ui->color_label->palette();
|
||||||
|
palette.setColor(QPalette::WindowText, color);
|
||||||
|
ui->color_label->setPalette(palette);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -20,6 +20,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
Ui::CustomLogo *ui;
|
Ui::CustomLogo *ui;
|
||||||
QFont* customFont;
|
QFont* customFont;
|
||||||
|
QColor fontColor;
|
||||||
|
|
||||||
void loadBGFromFile();
|
void loadBGFromFile();
|
||||||
void loadListFromFile();
|
void loadListFromFile();
|
||||||
|
|||||||
@ -76,6 +76,42 @@
|
|||||||
<string>雙面</string>
|
<string>雙面</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="horizontalLayoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>340</x>
|
||||||
|
<y>310</y>
|
||||||
|
<width>160</width>
|
||||||
|
<height>80</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="color_btn">
|
||||||
|
<property name="text">
|
||||||
|
<string>選色</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="color_label">
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>18</pointsize>
|
||||||
|
<weight>75</weight>
|
||||||
|
<bold>true</bold>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>顏色</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
<resources>
|
<resources>
|
||||||
<include location="NameCreater.qrc"/>
|
<include location="NameCreater.qrc"/>
|
||||||
|
|||||||
@ -200,15 +200,12 @@ void customlogo2::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_T
|
|||||||
textItem->setPos(20+(itemRect.width() - textItem->boundingRect().width())/2,42);
|
textItem->setPos(20+(itemRect.width() - textItem->boundingRect().width())/2,42);
|
||||||
|
|
||||||
|
|
||||||
scene.addItem(textItem);
|
|
||||||
|
|
||||||
QString name_en = name_info.name_eng;
|
QString name_en = name_info.name_eng;
|
||||||
QGraphicsTextItem* textItem_en = new QGraphicsTextItem(name_en, name_bgItem);
|
QGraphicsTextItem* textItem_en = new QGraphicsTextItem(name_en, name_bgItem);
|
||||||
textItem_en->setFont(enFont);
|
textItem_en->setFont(enFont);
|
||||||
textItem_en->setDefaultTextColor(fontColor);
|
textItem_en->setDefaultTextColor(fontColor);
|
||||||
textItem_en->setPos(20+(itemRect.width() - textItem_en->boundingRect().width())/2,170);
|
textItem_en->setPos(20+(itemRect.width() - textItem_en->boundingRect().width())/2,170);
|
||||||
|
|
||||||
scene.addItem(textItem_en);
|
|
||||||
|
|
||||||
bool is_export_page = ((idx + 1) % BG_POS_COUNT == 0);
|
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) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user