Added ability to change result font

This commit is contained in:
Gres 2020-03-19 21:47:46 +03:00
parent 124d32857f
commit 69f7d10c3a
9 changed files with 94 additions and 3 deletions

View File

@ -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<ResultWidget>();
widget_->changeFont(font_);
}
widget_->show(task);
}

View File

@ -2,6 +2,8 @@
#include "stfwd.h"
#include <QFont>
enum class ResultMode;
class ResultWidget;
@ -22,4 +24,5 @@ private:
TrayIcon &tray_;
std::unique_ptr<ResultWidget> widget_;
ResultMode mode_;
QFont font_;
};

View File

@ -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) {

View File

@ -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;

View File

@ -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)

View File

@ -63,6 +63,8 @@ public:
QStringList translators{"google.js"};
ResultMode resultShowType{ResultMode::Widget}; // dialog
QString fontFamily;
int fontSize{11};
private:
bool isPortable_{false};

View File

@ -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<int>(&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);
}

View File

@ -29,6 +29,7 @@ private:
void adjustUpdatesView();
void handleButtonBoxClicked(QAbstractButton *button);
void handlePortableChanged();
void updateResultFont();
Ui::SettingsEditor *ui;
Manager &manager_;

View File

@ -423,7 +423,43 @@
</layout>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QGroupBox" name="resultWindow">
<property name="title">
<string>Result window</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="0" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="resultFontSize">
<property name="minimum">
<number>6</number>
</property>
<property name="maximum">
<number>24</number>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QFontComboBox" name="resultFont"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
<string>Font size:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>