diff --git a/NameCreater/customlogo.cpp b/NameCreater/customlogo.cpp index f2f6227..18ddcaa 100644 --- a/NameCreater/customlogo.cpp +++ b/NameCreater/customlogo.cpp @@ -15,9 +15,9 @@ #define DEMO_BG_PATH ":/NameCreater/resource/custom_logo/bg_1.jpg" #define KEY_DEMO_BG_ITEM 10 -#define KEY_WORD_ITEM 99 -#define KEY_WORD_ITEM_X_POS 100 -#define KEY_WORD_ITEM_Y_POS 101 +#define KEY_WORD_ITEM 100 +#define KEY_WORD_ITEM_X_POS 101 +#define KEY_WORD_ITEM_Y_POS 102 #define DEMO_WORD_UNICODE "\u92ea\u96dc\u5152" static QPointF BG_POS_START = QPointF(159, 61); @@ -68,6 +68,7 @@ CustomLogo::CustomLogo(QFont* font, QDialog* parent) : connect(ui->load_list_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn); connect(ui->color_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn); connect(ui->reset_adjust_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn); + connect(ui->double_checkbox, &QCheckBox::clicked, this, &CustomLogo::onCheckboxClicked); connect(ui->x_adjust_slider, &QSlider::valueChanged, this, &CustomLogo::onSliderValueChanged); connect(ui->y_adjust_slider, &QSlider::valueChanged, this, &CustomLogo::onSliderValueChanged); @@ -125,16 +126,28 @@ void CustomLogo::createDemoGraphicItemBG(const QPixmap& img) { demo_scene.clear(); + bool isReverse = ui->double_checkbox->isChecked(); + QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(img); name_bgItem->setData(KEY_DEMO_BG_ITEM, KEY_DEMO_BG_ITEM); name_bgItem->setPos(10, 10); demo_scene.addItem(name_bgItem); - QGraphicsRectItem* name_rectItem = new QGraphicsRectItem(QRectF(0, 0, name_bgItem->boundingRect().width(), name_bgItem->boundingRect().height() / 2), name_bgItem); + QGraphicsRectItem* name_rectItem = NULL, * name_reverse_rectItem = NULL; + + 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, 255))); - QString name = QString(DEMO_WORD_UNICODE); + if (isReverse) { + 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()); + name_reverse_rectItem->setRotation(180); + } + + + QString name = QString(DEMO_WORD_UNICODE); int name_len = name.length(); QPointF pos = NAME_OFFSET_START; qreal y_offset = 0; @@ -143,6 +156,8 @@ void CustomLogo::createDemoGraphicItemBG(const QPixmap& img) y_offset = 55; } + + for (int k = 0; k < name_len; k++) { QGraphicsCloneTextItem* textItem = new QGraphicsCloneTextItem(name.mid(k, 1), name_rectItem); textItem->setFont(*customFont); @@ -156,21 +171,13 @@ void CustomLogo::createDemoGraphicItemBG(const QPixmap& img) textItem->setData(KEY_WORD_ITEM_Y_POS, QVariant(_posY)); textItem->setPos(_posX+x_adjust_offset, _posY+y_adjust_offset); - } - - - 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); + if (name_reverse_rectItem) { + QGraphicsCloneTextItem* _ti = ((QGraphicsCloneTextItem*)textItem)->clone(name_reverse_rectItem); _ti->setData(KEY_WORD_ITEM, QVariant(KEY_WORD_ITEM)); + _ti->setData(KEY_WORD_ITEM_X_POS, QVariant(_posX)); + _ti->setData(KEY_WORD_ITEM_Y_POS, QVariant(_posY)); } - name_reverse_rectItem->setRotation(180); - qDebug() << "name_rect item child count:" << name_rectItem->childItems().size(); } - } void CustomLogo::updateDemoGraphicItemBG() { @@ -229,10 +236,8 @@ void CustomLogo::gerneraImageFromList(const QList& nameList, Name_Ty scene.addItem(bg_item); } -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - QPixmap _bg = ui->display_label->pixmap()->copy(); -#else - QPixmap _bg; //= ui->display_label->pixmap().copy(); + + QPixmap _bg; foreach(QGraphicsItem * item, demo_scene.items()) { QVariant v = item->data(KEY_DEMO_BG_ITEM); @@ -243,9 +248,6 @@ void CustomLogo::gerneraImageFromList(const QList& nameList, Name_Ty } -#endif // - - QGraphicsPixmapItem* name_bgItem = new QGraphicsPixmapItem(_bg); bool rot = (idx == 10 || idx == 11); @@ -395,6 +397,19 @@ void CustomLogo::onSliderValueChanged(int value) updateDemoGraphicItemBG(); } +void CustomLogo::onCheckboxClicked(bool click) +{ + foreach(QGraphicsItem * item, demo_scene.items()) { + QVariant v = item->data(KEY_DEMO_BG_ITEM); + if (v.toInt() == KEY_DEMO_BG_ITEM) { + QPixmap _bg = ((QGraphicsPixmapItem*)item)->pixmap().copy(); + createDemoGraphicItemBG(_bg); + break; + } + + } +} + void CustomLogo::onClickedBtn() { auto sender = (QPushButton*)QObject::sender(); diff --git a/NameCreater/customlogo.h b/NameCreater/customlogo.h index 208580a..8faf591 100644 --- a/NameCreater/customlogo.h +++ b/NameCreater/customlogo.h @@ -38,6 +38,7 @@ private Q_SLOTS: void onClickedBtn(); void onColorSelected(const QColor& color); void onSliderValueChanged(int value); + void onCheckboxClicked(bool click);