1. add x, y position adjustment function.
This commit is contained in:
parent
12c2c02756
commit
734b3d1303
@ -35,6 +35,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
@ -43,6 +44,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>NotSet</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')">
|
||||
|
||||
@ -12,6 +12,14 @@
|
||||
#include <QColorDialog>
|
||||
|
||||
|
||||
#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 DEMO_WORD_UNICODE "\u92ea\u96dc\u5152"
|
||||
|
||||
static QPointF BG_POS_START = QPointF(159, 61);
|
||||
static QPointF BG_POS_ROT_START = QPointF(900, 2094);
|
||||
static qreal BG_WIDTH_OFFSET = 320;
|
||||
@ -25,6 +33,7 @@ static QColor FONT_COLOR = QColor(0, 0, 0);
|
||||
static QColorDialog* s_colorDialog = nullptr;
|
||||
|
||||
|
||||
|
||||
class QGraphicsCloneTextItem : public QGraphicsTextItem {
|
||||
public:
|
||||
QGraphicsCloneTextItem(const QString& text, QGraphicsItem* parent = nullptr) :
|
||||
@ -52,11 +61,16 @@ CustomLogo::CustomLogo(QFont* font, QDialog* parent) :
|
||||
fontColor(QColor(0, 0, 0))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
x_adjust_offset = y_adjust_offset = 0;
|
||||
onSliderValueChanged(0);
|
||||
|
||||
connect(ui->load_bg_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);
|
||||
connect(ui->reset_adjust_btn, &QPushButton::released, this, &CustomLogo::onClickedBtn);
|
||||
|
||||
connect(ui->x_adjust_slider, &QSlider::valueChanged, this, &CustomLogo::onSliderValueChanged);
|
||||
connect(ui->y_adjust_slider, &QSlider::valueChanged, this, &CustomLogo::onSliderValueChanged);
|
||||
|
||||
|
||||
QFont _f(*font);
|
||||
@ -70,6 +84,15 @@ CustomLogo::CustomLogo(QFont* font, QDialog* parent) :
|
||||
ui->color_btn->setFont(_f);
|
||||
ui->double_checkbox->setFont(_f);
|
||||
|
||||
|
||||
|
||||
|
||||
demo_scene.setBackgroundBrush(QBrush(QColor(255, 255, 255)));
|
||||
ui->demo_graphicsView->setScene(&demo_scene);
|
||||
|
||||
QPixmap def_demo_bg(DEMO_BG_PATH);
|
||||
createDemoGraphicItemBG(def_demo_bg);
|
||||
|
||||
}
|
||||
|
||||
CustomLogo::~CustomLogo()
|
||||
@ -86,7 +109,8 @@ void CustomLogo::loadBGFromFile()
|
||||
else {
|
||||
QPixmap pix;
|
||||
if (pix.loadFromData(fileContent, "JPG")) {
|
||||
ui->display_label->setPixmap(pix);
|
||||
//ui->display_label->setPixmap(pix);
|
||||
createDemoGraphicItemBG(pix);
|
||||
}
|
||||
else {
|
||||
qDebug() << "Data content not image format";
|
||||
@ -97,6 +121,70 @@ void CustomLogo::loadBGFromFile()
|
||||
QFileDialog::getOpenFileContent("Image (*.jpg)", fileContentReady);
|
||||
}
|
||||
|
||||
void CustomLogo::createDemoGraphicItemBG(const QPixmap& img)
|
||||
{
|
||||
demo_scene.clear();
|
||||
|
||||
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);
|
||||
name_rectItem->setPen(QPen(QColor(0, 0, 0, 255)));
|
||||
|
||||
QString name = QString(DEMO_WORD_UNICODE);
|
||||
|
||||
int name_len = name.length();
|
||||
QPointF pos = NAME_OFFSET_START;
|
||||
qreal y_offset = 0;
|
||||
if (name_len == 2) {
|
||||
pos.setY(pos.y() + 65.0);
|
||||
y_offset = 55;
|
||||
}
|
||||
|
||||
for (int k = 0; k < name_len; k++) {
|
||||
QGraphicsCloneTextItem* textItem = new QGraphicsCloneTextItem(name.mid(k, 1), name_rectItem);
|
||||
textItem->setFont(*customFont);
|
||||
textItem->setDefaultTextColor(fontColor);
|
||||
|
||||
qreal _posX = (name_rectItem->boundingRect().width() / 2 - textItem->boundingRect().width() / 2);
|
||||
qreal _posY = (pos.y()) + k * (EACH_WORD_OFFSET + y_offset);
|
||||
qDebug() << "Name num:" << QString::number(k) << "PosY:" << QString::number(_posY);
|
||||
textItem->setData(KEY_WORD_ITEM, QVariant(KEY_WORD_ITEM));
|
||||
textItem->setData(KEY_WORD_ITEM_X_POS, QVariant(_posX));
|
||||
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);
|
||||
_ti->setData(KEY_WORD_ITEM, QVariant(KEY_WORD_ITEM));
|
||||
}
|
||||
name_reverse_rectItem->setRotation(180);
|
||||
qDebug() << "name_rect item child count:" << name_rectItem->childItems().size();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CustomLogo::updateDemoGraphicItemBG() {
|
||||
foreach(QGraphicsItem * item, demo_scene.items()) {
|
||||
QVariant v = item->data(KEY_WORD_ITEM);
|
||||
if (v.toInt() == KEY_WORD_ITEM) {
|
||||
((QGraphicsTextItem*)item)->setDefaultTextColor(fontColor);
|
||||
qreal _ori_x = item->data(KEY_WORD_ITEM_X_POS).toReal();
|
||||
qreal _ori_y = item->data(KEY_WORD_ITEM_Y_POS).toReal();
|
||||
item->setPos(_ori_x + x_adjust_offset, _ori_y + y_adjust_offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CustomLogo::loadListFromFile()
|
||||
{
|
||||
auto fileContentReady = [this](const QString& fileName, const QByteArray& fileContent) {
|
||||
@ -144,7 +232,17 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
|
||||
#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; //= ui->display_label->pixmap().copy();
|
||||
|
||||
foreach(QGraphicsItem * item, demo_scene.items()) {
|
||||
QVariant v = item->data(KEY_DEMO_BG_ITEM);
|
||||
if (v.toInt() == KEY_DEMO_BG_ITEM) {
|
||||
_bg = ((QGraphicsPixmapItem*)item)->pixmap().copy();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif //
|
||||
|
||||
|
||||
@ -182,7 +280,7 @@ void CustomLogo::gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Ty
|
||||
qreal _posX = name_rectItem->boundingRect().width() / 2 - textItem->boundingRect().width() / 2;
|
||||
qreal _posY = pos.y() + k * (EACH_WORD_OFFSET + y_offset);
|
||||
qDebug() << "Name num:" << QString::number(k) << "PosY:" << QString::number(_posY);
|
||||
textItem->setPos(_posX, _posY);
|
||||
textItem->setPos(_posX+x_adjust_offset, _posY+y_adjust_offset);
|
||||
|
||||
}
|
||||
|
||||
@ -275,6 +373,26 @@ void CustomLogo::onColorSelected(const QColor& color)
|
||||
QPalette palette = ui->color_label->palette();
|
||||
palette.setColor(QPalette::WindowText, fontColor);
|
||||
ui->color_label->setPalette(palette);
|
||||
|
||||
updateDemoGraphicItemBG();
|
||||
}
|
||||
|
||||
void CustomLogo::onSliderValueChanged(int value)
|
||||
{
|
||||
auto slider = QObject::sender();
|
||||
|
||||
if (slider == ui->x_adjust_slider) {
|
||||
x_adjust_offset = value;
|
||||
}
|
||||
else if (slider == ui->y_adjust_slider) {
|
||||
y_adjust_offset = value;
|
||||
|
||||
}
|
||||
|
||||
ui->x_adjust_label->setText(QString("X: %1").arg(QString::number(x_adjust_offset)));
|
||||
ui->y_adjust_label->setText(QString("Y: %1").arg(QString::number(y_adjust_offset)));
|
||||
|
||||
updateDemoGraphicItemBG();
|
||||
}
|
||||
|
||||
|
||||
@ -296,6 +414,10 @@ void CustomLogo::onClickedBtn() {
|
||||
s_colorDialog->open();
|
||||
|
||||
}
|
||||
else if (sender == ui->reset_adjust_btn) {
|
||||
ui->x_adjust_slider->setValue(0);
|
||||
ui->y_adjust_slider->setValue(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,13 @@ private:
|
||||
Ui::CustomLogo *ui;
|
||||
QFont* customFont;
|
||||
QColor fontColor;
|
||||
QGraphicsScene demo_scene;
|
||||
|
||||
qreal x_adjust_offset, y_adjust_offset;
|
||||
|
||||
void loadBGFromFile();
|
||||
void createDemoGraphicItemBG(const QPixmap& img);
|
||||
void updateDemoGraphicItemBG();
|
||||
void loadListFromFile();
|
||||
void gerneraImageFromList(const QList<NameInfo_t>& nameList, Name_Type_e type);
|
||||
|
||||
@ -32,6 +37,7 @@ protected:
|
||||
private Q_SLOTS:
|
||||
void onClickedBtn();
|
||||
void onColorSelected(const QColor& color);
|
||||
void onSliderValueChanged(int value);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -7,31 +7,12 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>545</width>
|
||||
<height>1741</height>
|
||||
<height>653</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QLabel" name="display_label">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>10</y>
|
||||
<width>293</width>
|
||||
<height>1715</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="pixmap">
|
||||
<pixmap resource="NameCreater.qrc">:/NameCreater/resource/custom_logo/bg_1.jpg</pixmap>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="load_bg_btn">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@ -112,6 +93,104 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QGraphicsView" name="demo_graphicsView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>50</y>
|
||||
<width>311</width>
|
||||
<height>561</height>
|
||||
</rect>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>330</x>
|
||||
<y>410</y>
|
||||
<width>201</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>水平</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QSlider" name="x_adjust_slider">
|
||||
<property name="minimum">
|
||||
<number>-100</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QSlider" name="y_adjust_slider">
|
||||
<property name="minimum">
|
||||
<number>-100</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>垂直</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="x_adjust_label">
|
||||
<property name="text">
|
||||
<string>X</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="y_adjust_label">
|
||||
<property name="text">
|
||||
<string>Y</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QPushButton" name="reset_adjust_btn">
|
||||
<property name="text">
|
||||
<string>Reset</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="NameCreater.qrc"/>
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#ifndef DEF_H
|
||||
#define DEF_H
|
||||
|
||||
#define VERSION "v2.9.2"
|
||||
#define VERSION "v2.10.0"
|
||||
|
||||
|
||||
#endif // DEF_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user