Skip to content

Commit

Permalink
feat/perf: 重构gui架构, 支持多层水印和不同字体
Browse files Browse the repository at this point in the history
  • Loading branch information
windsgo committed Jun 20, 2023
1 parent 609e661 commit f80a38a
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 23 deletions.
34 changes: 34 additions & 0 deletions application/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,21 @@ MainWindow::MainWindow(QWidget *parent)
_updateWaterMarkedPicture();
});

connect(ui->rbDigitalFont, &QRadioButton::clicked, this, [&](){
ui->cbDigitalFonts->setEnabled(true);
ui->fcbSystemFonts->setEnabled(false);

_updateWaterMarkedPicture();
});
connect(ui->rbSystemFont, &QRadioButton::clicked, this, [&](){
ui->cbDigitalFonts->setEnabled(false);
ui->fcbSystemFonts->setEnabled(true);

_updateWaterMarkedPicture();
});

connect(ui->cbDigitalFonts, &QComboBox::currentTextChanged, this, &MainWindow::_updateWaterMarkedPicture);
connect(ui->fcbSystemFonts, &QFontComboBox::currentTextChanged, this, &MainWindow::_updateWaterMarkedPicture);

connect(ui->dsbFontPercent, QOverload<double>::of(&QDoubleSpinBox::valueChanged),
this, &MainWindow::_updateWaterMarkedPicture);
Expand Down Expand Up @@ -201,6 +216,19 @@ bool MainWindow::_updateWaterMarkedPicture()
/* 更新字符串文本框 */
_updateGenerateStringText();

/* 选择字体 */
if (ui->rbDigitalFont->isChecked()) {
if (ui->cbDigitalFonts->currentIndex() == 0) {
/* traditional font */
mark_generator_.setFontFromFile(":/font/MTC-7-Segment.ttf");
} else {
/* enhanced font */
mark_generator_.setFontFromFile(":/font/LCD2U-4.ttf");
}
} else { /* ui->rbSystemFont->isChecked() */
mark_generator_.setFont(ui->fcbSystemFonts->currentFont());
}

mark_generator_.setPosSize({ui->dsbBottomPercent->value(),
ui->dsbRightPercent->value(),
ui->dsbFontPercent->value()});
Expand Down Expand Up @@ -246,4 +274,10 @@ void MainWindow::on_pbCacheCurrentMark_clicked()
{
current_cached_img_ = current_display_img_;
mark_generator_.setImage(current_cached_img_);

ui->dsbBottomPercent->setValue(ui->dsbBottomPercent->value() + 5.0);
if (!_updateWaterMarkedPicture()) {
QMessageBox::warning(this, tr("错误"), error_msg_);
return;
}
}
100 changes: 77 additions & 23 deletions application/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,59 @@ p, li { white-space: pre-wrap; }
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="maximumSize">
<size>
<width>272</width>
<height>16777215</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0">
<widget class="QRadioButton" name="rbDigitalFont">
<property name="text">
<string>数码字体</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="cbDigitalFonts">
<item>
<property name="text">
<string>复古精简数码字体</string>
</property>
</item>
<item>
<property name="text">
<string>加强数码字体</string>
</property>
</item>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="rbSystemFont">
<property name="text">
<string>系统字体</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QFontComboBox" name="fcbSystemFonts">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frameParam">
<property name="frameShape">
Expand All @@ -218,51 +271,52 @@ p, li { white-space: pre-wrap; }
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<widget class="QLabel" name="label_3">
<property name="text">
<string>字体大小</string>
<string>右侧间隙</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="dsbBottomPercent">
<property name="value">
<double>5.500000000000000</double>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>底部间隙</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="4" column="1">
<widget class="QPushButton" name="pbCacheCurrentMark">
<property name="text">
<string>保存当前水印
并新建水印</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QDoubleSpinBox" name="dsbFontPercent">
<property name="value">
<double>1.570000000000000</double>
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="dsbRightPercent">
<property name="value">
<double>13.500000000000000</double>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>底部间隙</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>右侧间隙</string>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="dsbBottomPercent">
<property name="value">
<double>5.500000000000000</double>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pbCacheCurrentMark">
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>保存当前水印</string>
<string>字体大小</string>
</property>
</widget>
</item>
Expand All @@ -281,7 +335,7 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>700</width>
<height>22</height>
<height>21</height>
</rect>
</property>
</widget>
Expand Down
Binary file added resource/LCD2U-4.ttf
Binary file not shown.
1 change: 1 addition & 0 deletions resource/resource.qrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/font">
<file>MTC-7-Segment.ttf</file>
<file>LCD2U-4.ttf</file>
</qresource>
</RCC>

0 comments on commit f80a38a

Please sign in to comment.