diff --git a/src/represent/representer.cpp b/src/represent/representer.cpp index 6b4151a..269ac3f 100644 --- a/src/represent/representer.cpp +++ b/src/represent/representer.cpp @@ -25,6 +25,9 @@ void Representer::represent(const TaskPtr &task) void Representer::updateSettings(const Settings &settings) { mode_ = settings.resultShowType; + font_ = QFont(settings.fontFamily, settings.fontSize); + if (widget_) + widget_->changeFont(font_); } void Representer::showTooltip(const TaskPtr &task) @@ -35,8 +38,10 @@ void Representer::showTooltip(const TaskPtr &task) void Representer::showWidget(const TaskPtr &task) { - if (!widget_) + if (!widget_) { widget_ = std::make_unique(); + widget_->changeFont(font_); + } widget_->show(task); } diff --git a/src/represent/representer.h b/src/represent/representer.h index 732aac3..2998eee 100644 --- a/src/represent/representer.h +++ b/src/represent/representer.h @@ -2,6 +2,8 @@ #include "stfwd.h" +#include + enum class ResultMode; class ResultWidget; @@ -22,4 +24,5 @@ private: TrayIcon &tray_; std::unique_ptr widget_; ResultMode mode_; + QFont font_; }; diff --git a/src/represent/resultwidget.cpp b/src/represent/resultwidget.cpp index f0d1e06..b2f07d5 100644 --- a/src/represent/resultwidget.cpp +++ b/src/represent/resultwidget.cpp @@ -83,6 +83,13 @@ void ResultWidget::show(const TaskPtr &task) activateWindow(); } +void ResultWidget::changeFont(const QFont &font) +{ + // because of stylesheet + recognized_->setFont(font); + translated_->setFont(font); +} + bool ResultWidget::eventFilter(QObject *watched, QEvent *event) { if (event->type() == QEvent::MouseButtonPress) { diff --git a/src/represent/resultwidget.h b/src/represent/resultwidget.h index 2480ef4..a360f01 100644 --- a/src/represent/resultwidget.h +++ b/src/represent/resultwidget.h @@ -14,6 +14,7 @@ public: void show(const TaskPtr& task); using QWidget::show; + void changeFont(const QFont& font); bool eventFilter(QObject* watched, QEvent* event) override; diff --git a/src/settings.cpp b/src/settings.cpp index 4839742..23ac93c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -39,6 +39,10 @@ const QString qs_translationTimeout = "translation_timeout"; const QString qs_debugMode = "translation_debug"; const QString qs_translators = "translators"; +const QString qs_representationGroup = "Representation"; +const QString qs_fontFamily = "fontFamily"; +const QString qs_fontSize = "fontSize"; + QString shuffle(const QString& source) { if (source.isEmpty()) { @@ -175,6 +179,13 @@ void Settings::save() const settings.endGroup(); + settings.beginGroup(qs_representationGroup); + + settings.setValue(qs_fontFamily, fontFamily); + settings.setValue(qs_fontSize, fontSize); + + settings.endGroup(); + cleanupOutdated(settings); } @@ -252,6 +263,13 @@ void Settings::load() translators = translators.first().split('|'); settings.endGroup(); + + settings.beginGroup(qs_representationGroup); + + fontFamily = settings.value(qs_fontFamily, fontFamily).toString(); + fontSize = std::clamp(settings.value(qs_fontSize, fontSize).toInt(), 6, 24); + + settings.endGroup(); } void Settings::saveLastUpdateCheck(const QDateTime& dt) diff --git a/src/settings.h b/src/settings.h index ec96c1c..3758c48 100644 --- a/src/settings.h +++ b/src/settings.h @@ -63,6 +63,8 @@ public: QStringList translators{"google.js"}; ResultMode resultShowType{ResultMode::Widget}; // dialog + QString fontFamily; + int fontSize{11}; private: bool isPortable_{false}; diff --git a/src/settingseditor.cpp b/src/settingseditor.cpp index f3d7ec2..81790e0 100644 --- a/src/settingseditor.cpp +++ b/src/settingseditor.cpp @@ -50,7 +50,6 @@ SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater) } // correction - ui->userSubstitutionsTable->setEnabled(ui->useUserSubstitutions->isChecked()); connect(ui->useUserSubstitutions, &QCheckBox::toggled, // ui->userSubstitutionsTable, &QTableWidget::setEnabled); @@ -58,6 +57,14 @@ SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater) // translation updateTranslationLanguages(); + // representation + connect(ui->dialogRadio, &QRadioButton::toggled, // + ui->resultWindow, &QTableWidget::setEnabled); + connect(ui->resultFont, &QFontComboBox::currentFontChanged, // + this, &SettingsEditor::updateResultFont); + connect(ui->resultFontSize, qOverload(&QSpinBox::valueChanged), // + this, &SettingsEditor::updateResultFont); + // updates auto updatesProxy = new QSortFilterProxyModel(this); updatesProxy->setSourceModel(updater_.model()); @@ -129,6 +136,8 @@ Settings SettingsEditor::settings() const settings.resultShowType = ui->trayRadio->isChecked() ? ResultMode::Tooltip : ResultMode::Widget; + settings.fontFamily = ui->resultFont->currentFont().family(); + settings.fontSize = ui->resultFontSize->value(); settings.autoUpdateIntervalDays = ui->autoUpdateInterval->value(); @@ -176,6 +185,8 @@ void SettingsEditor::setSettings(const Settings &settings) ui->trayRadio->setChecked(settings.resultShowType == ResultMode::Tooltip); ui->dialogRadio->setChecked(settings.resultShowType == ResultMode::Widget); + ui->resultFont->setCurrentFont(QFont(settings.fontFamily)); + ui->resultFontSize->setValue(settings.fontSize); ui->autoUpdateInterval->setValue(settings.autoUpdateIntervalDays); } @@ -283,3 +294,10 @@ void SettingsEditor::handlePortableChanged() ? tr("Portable changed. Apply settings first") : QString()); } + +void SettingsEditor::updateResultFont() +{ + auto font = ui->resultFont->currentFont(); + font.setPointSize(ui->resultFontSize->value()); + ui->resultFont->setFont(font); +} diff --git a/src/settingseditor.h b/src/settingseditor.h index eb7155a..118f3d2 100644 --- a/src/settingseditor.h +++ b/src/settingseditor.h @@ -29,6 +29,7 @@ private: void adjustUpdatesView(); void handleButtonBoxClicked(QAbstractButton *button); void handlePortableChanged(); + void updateResultFont(); Ui::SettingsEditor *ui; Manager &manager_; diff --git a/src/settingseditor.ui b/src/settingseditor.ui index dfd3944..1be7d9e 100644 --- a/src/settingseditor.ui +++ b/src/settingseditor.ui @@ -423,7 +423,43 @@ - + + + + Result window + + + + + + Font: + + + + + + + 6 + + + 24 + + + + + + + + + + Font size: + + + + + + + Qt::Vertical