Added ability to show/hide captured image and recognized text

This commit is contained in:
Gres 2020-03-19 21:55:32 +03:00
parent 69f7d10c3a
commit 1f478bc48a
8 changed files with 51 additions and 12 deletions

View File

@ -26,8 +26,10 @@ void Representer::updateSettings(const Settings &settings)
{
mode_ = settings.resultShowType;
font_ = QFont(settings.fontFamily, settings.fontSize);
showRecognized_ = settings.showRecognized;
showCaptured_ = settings.showCaptured;
if (widget_)
widget_->changeFont(font_);
widget_->updateSettings(font_, showRecognized_, showCaptured_);
}
void Representer::showTooltip(const TaskPtr &task)
@ -40,7 +42,7 @@ void Representer::showWidget(const TaskPtr &task)
{
if (!widget_) {
widget_ = std::make_unique<ResultWidget>();
widget_->changeFont(font_);
widget_->updateSettings(font_, showRecognized_, showCaptured_);
}
widget_->show(task);

View File

@ -25,4 +25,6 @@ private:
std::unique_ptr<ResultWidget> widget_;
ResultMode mode_;
QFont font_;
bool showRecognized_{true};
bool showCaptured_{true};
};

View File

@ -66,6 +66,9 @@ void ResultWidget::show(const TaskPtr &task)
const auto gotTranslation = !task->translated.isEmpty();
translated_->setVisible(gotTranslation);
const auto mustShowRecognized = showRecognized_ || !gotTranslation;
recognized_->setVisible(mustShowRecognized);
show();
adjustSize();
@ -83,11 +86,15 @@ void ResultWidget::show(const TaskPtr &task)
activateWindow();
}
void ResultWidget::changeFont(const QFont &font)
void ResultWidget::updateSettings(const QFont &font, bool showRecognized,
bool showCaptured)
{
// because of stylesheet
// explicit font change because of stylesheet
recognized_->setFont(font);
translated_->setFont(font);
image_->setVisible(showCaptured);
showRecognized_ = showRecognized;
}
bool ResultWidget::eventFilter(QObject *watched, QEvent *event)

View File

@ -14,7 +14,8 @@ public:
void show(const TaskPtr& task);
using QWidget::show;
void changeFont(const QFont& font);
void updateSettings(const QFont& font, bool showRecognized,
bool showCaptured);
bool eventFilter(QObject* watched, QEvent* event) override;
@ -22,4 +23,5 @@ private:
QLabel* image_;
QLabel* recognized_;
QLabel* translated_;
bool showRecognized_{true};
};

View File

@ -42,6 +42,8 @@ const QString qs_translators = "translators";
const QString qs_representationGroup = "Representation";
const QString qs_fontFamily = "fontFamily";
const QString qs_fontSize = "fontSize";
const QString qs_showRecognized = "showRecognized";
const QString qs_showCaptured = "showCaptured";
QString shuffle(const QString& source)
{
@ -183,6 +185,8 @@ void Settings::save() const
settings.setValue(qs_fontFamily, fontFamily);
settings.setValue(qs_fontSize, fontSize);
settings.setValue(qs_showRecognized, showRecognized);
settings.setValue(qs_showCaptured, showCaptured);
settings.endGroup();
@ -268,6 +272,8 @@ void Settings::load()
fontFamily = settings.value(qs_fontFamily, fontFamily).toString();
fontSize = std::clamp(settings.value(qs_fontSize, fontSize).toInt(), 6, 24);
showRecognized = settings.value(qs_showRecognized, showRecognized).toBool();
showCaptured = settings.value(qs_showCaptured, showCaptured).toBool();
settings.endGroup();
}

View File

@ -65,6 +65,8 @@ public:
ResultMode resultShowType{ResultMode::Widget}; // dialog
QString fontFamily;
int fontSize{11};
bool showRecognized{true};
bool showCaptured{true};
private:
bool isPortable_{false};

View File

@ -138,6 +138,8 @@ Settings SettingsEditor::settings() const
ui->trayRadio->isChecked() ? ResultMode::Tooltip : ResultMode::Widget;
settings.fontFamily = ui->resultFont->currentFont().family();
settings.fontSize = ui->resultFontSize->value();
settings.showRecognized = ui->showRecognized->isChecked();
settings.showCaptured = ui->showCaptured->isChecked();
settings.autoUpdateIntervalDays = ui->autoUpdateInterval->value();
@ -187,6 +189,8 @@ void SettingsEditor::setSettings(const Settings &settings)
ui->dialogRadio->setChecked(settings.resultShowType == ResultMode::Widget);
ui->resultFont->setCurrentFont(QFont(settings.fontFamily));
ui->resultFontSize->setValue(settings.fontSize);
ui->showRecognized->setChecked(settings.showRecognized);
ui->showCaptured->setChecked(settings.showCaptured);
ui->autoUpdateInterval->setValue(settings.autoUpdateIntervalDays);
}

View File

@ -429,13 +429,6 @@
<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">
@ -449,6 +442,13 @@
<item row="0" column="1">
<widget class="QFontComboBox" name="resultFont"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_18">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_19">
<property name="text">
@ -456,6 +456,20 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="showCaptured">
<property name="text">
<string>Show image</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="2">
<widget class="QCheckBox" name="showRecognized">
<property name="text">
<string>Show recognized</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>