Added ability to show/hide captured image and recognized text
This commit is contained in:
		
							parent
							
								
									69f7d10c3a
								
							
						
					
					
						commit
						1f478bc48a
					
				@ -26,8 +26,10 @@ void Representer::updateSettings(const Settings &settings)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  mode_ = settings.resultShowType;
 | 
					  mode_ = settings.resultShowType;
 | 
				
			||||||
  font_ = QFont(settings.fontFamily, settings.fontSize);
 | 
					  font_ = QFont(settings.fontFamily, settings.fontSize);
 | 
				
			||||||
 | 
					  showRecognized_ = settings.showRecognized;
 | 
				
			||||||
 | 
					  showCaptured_ = settings.showCaptured;
 | 
				
			||||||
  if (widget_)
 | 
					  if (widget_)
 | 
				
			||||||
    widget_->changeFont(font_);
 | 
					    widget_->updateSettings(font_, showRecognized_, showCaptured_);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Representer::showTooltip(const TaskPtr &task)
 | 
					void Representer::showTooltip(const TaskPtr &task)
 | 
				
			||||||
@ -40,7 +42,7 @@ void Representer::showWidget(const TaskPtr &task)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  if (!widget_) {
 | 
					  if (!widget_) {
 | 
				
			||||||
    widget_ = std::make_unique<ResultWidget>();
 | 
					    widget_ = std::make_unique<ResultWidget>();
 | 
				
			||||||
    widget_->changeFont(font_);
 | 
					    widget_->updateSettings(font_, showRecognized_, showCaptured_);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  widget_->show(task);
 | 
					  widget_->show(task);
 | 
				
			||||||
 | 
				
			|||||||
@ -25,4 +25,6 @@ private:
 | 
				
			|||||||
  std::unique_ptr<ResultWidget> widget_;
 | 
					  std::unique_ptr<ResultWidget> widget_;
 | 
				
			||||||
  ResultMode mode_;
 | 
					  ResultMode mode_;
 | 
				
			||||||
  QFont font_;
 | 
					  QFont font_;
 | 
				
			||||||
 | 
					  bool showRecognized_{true};
 | 
				
			||||||
 | 
					  bool showCaptured_{true};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -66,6 +66,9 @@ void ResultWidget::show(const TaskPtr &task)
 | 
				
			|||||||
  const auto gotTranslation = !task->translated.isEmpty();
 | 
					  const auto gotTranslation = !task->translated.isEmpty();
 | 
				
			||||||
  translated_->setVisible(gotTranslation);
 | 
					  translated_->setVisible(gotTranslation);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  const auto mustShowRecognized = showRecognized_ || !gotTranslation;
 | 
				
			||||||
 | 
					  recognized_->setVisible(mustShowRecognized);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  show();
 | 
					  show();
 | 
				
			||||||
  adjustSize();
 | 
					  adjustSize();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -83,11 +86,15 @@ void ResultWidget::show(const TaskPtr &task)
 | 
				
			|||||||
  activateWindow();
 | 
					  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);
 | 
					  recognized_->setFont(font);
 | 
				
			||||||
  translated_->setFont(font);
 | 
					  translated_->setFont(font);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  image_->setVisible(showCaptured);
 | 
				
			||||||
 | 
					  showRecognized_ = showRecognized;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool ResultWidget::eventFilter(QObject *watched, QEvent *event)
 | 
					bool ResultWidget::eventFilter(QObject *watched, QEvent *event)
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,8 @@ public:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  void show(const TaskPtr& task);
 | 
					  void show(const TaskPtr& task);
 | 
				
			||||||
  using QWidget::show;
 | 
					  using QWidget::show;
 | 
				
			||||||
  void changeFont(const QFont& font);
 | 
					  void updateSettings(const QFont& font, bool showRecognized,
 | 
				
			||||||
 | 
					                      bool showCaptured);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  bool eventFilter(QObject* watched, QEvent* event) override;
 | 
					  bool eventFilter(QObject* watched, QEvent* event) override;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -22,4 +23,5 @@ private:
 | 
				
			|||||||
  QLabel* image_;
 | 
					  QLabel* image_;
 | 
				
			||||||
  QLabel* recognized_;
 | 
					  QLabel* recognized_;
 | 
				
			||||||
  QLabel* translated_;
 | 
					  QLabel* translated_;
 | 
				
			||||||
 | 
					  bool showRecognized_{true};
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
				
			|||||||
@ -42,6 +42,8 @@ const QString qs_translators = "translators";
 | 
				
			|||||||
const QString qs_representationGroup = "Representation";
 | 
					const QString qs_representationGroup = "Representation";
 | 
				
			||||||
const QString qs_fontFamily = "fontFamily";
 | 
					const QString qs_fontFamily = "fontFamily";
 | 
				
			||||||
const QString qs_fontSize = "fontSize";
 | 
					const QString qs_fontSize = "fontSize";
 | 
				
			||||||
 | 
					const QString qs_showRecognized = "showRecognized";
 | 
				
			||||||
 | 
					const QString qs_showCaptured = "showCaptured";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
QString shuffle(const QString& source)
 | 
					QString shuffle(const QString& source)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -183,6 +185,8 @@ void Settings::save() const
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  settings.setValue(qs_fontFamily, fontFamily);
 | 
					  settings.setValue(qs_fontFamily, fontFamily);
 | 
				
			||||||
  settings.setValue(qs_fontSize, fontSize);
 | 
					  settings.setValue(qs_fontSize, fontSize);
 | 
				
			||||||
 | 
					  settings.setValue(qs_showRecognized, showRecognized);
 | 
				
			||||||
 | 
					  settings.setValue(qs_showCaptured, showCaptured);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  settings.endGroup();
 | 
					  settings.endGroup();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -268,6 +272,8 @@ void Settings::load()
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fontFamily = settings.value(qs_fontFamily, fontFamily).toString();
 | 
					  fontFamily = settings.value(qs_fontFamily, fontFamily).toString();
 | 
				
			||||||
  fontSize = std::clamp(settings.value(qs_fontSize, fontSize).toInt(), 6, 24);
 | 
					  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();
 | 
					  settings.endGroup();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -65,6 +65,8 @@ public:
 | 
				
			|||||||
  ResultMode resultShowType{ResultMode::Widget};  // dialog
 | 
					  ResultMode resultShowType{ResultMode::Widget};  // dialog
 | 
				
			||||||
  QString fontFamily;
 | 
					  QString fontFamily;
 | 
				
			||||||
  int fontSize{11};
 | 
					  int fontSize{11};
 | 
				
			||||||
 | 
					  bool showRecognized{true};
 | 
				
			||||||
 | 
					  bool showCaptured{true};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
  bool isPortable_{false};
 | 
					  bool isPortable_{false};
 | 
				
			||||||
 | 
				
			|||||||
@ -138,6 +138,8 @@ Settings SettingsEditor::settings() const
 | 
				
			|||||||
      ui->trayRadio->isChecked() ? ResultMode::Tooltip : ResultMode::Widget;
 | 
					      ui->trayRadio->isChecked() ? ResultMode::Tooltip : ResultMode::Widget;
 | 
				
			||||||
  settings.fontFamily = ui->resultFont->currentFont().family();
 | 
					  settings.fontFamily = ui->resultFont->currentFont().family();
 | 
				
			||||||
  settings.fontSize = ui->resultFontSize->value();
 | 
					  settings.fontSize = ui->resultFontSize->value();
 | 
				
			||||||
 | 
					  settings.showRecognized = ui->showRecognized->isChecked();
 | 
				
			||||||
 | 
					  settings.showCaptured = ui->showCaptured->isChecked();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  settings.autoUpdateIntervalDays = ui->autoUpdateInterval->value();
 | 
					  settings.autoUpdateIntervalDays = ui->autoUpdateInterval->value();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -187,6 +189,8 @@ void SettingsEditor::setSettings(const Settings &settings)
 | 
				
			|||||||
  ui->dialogRadio->setChecked(settings.resultShowType == ResultMode::Widget);
 | 
					  ui->dialogRadio->setChecked(settings.resultShowType == ResultMode::Widget);
 | 
				
			||||||
  ui->resultFont->setCurrentFont(QFont(settings.fontFamily));
 | 
					  ui->resultFont->setCurrentFont(QFont(settings.fontFamily));
 | 
				
			||||||
  ui->resultFontSize->setValue(settings.fontSize);
 | 
					  ui->resultFontSize->setValue(settings.fontSize);
 | 
				
			||||||
 | 
					  ui->showRecognized->setChecked(settings.showRecognized);
 | 
				
			||||||
 | 
					  ui->showCaptured->setChecked(settings.showCaptured);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ui->autoUpdateInterval->setValue(settings.autoUpdateIntervalDays);
 | 
					  ui->autoUpdateInterval->setValue(settings.autoUpdateIntervalDays);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -429,13 +429,6 @@
 | 
				
			|||||||
          <string>Result window</string>
 | 
					          <string>Result window</string>
 | 
				
			||||||
         </property>
 | 
					         </property>
 | 
				
			||||||
         <layout class="QGridLayout" name="gridLayout_8">
 | 
					         <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">
 | 
					          <item row="1" column="1">
 | 
				
			||||||
           <widget class="QSpinBox" name="resultFontSize">
 | 
					           <widget class="QSpinBox" name="resultFontSize">
 | 
				
			||||||
            <property name="minimum">
 | 
					            <property name="minimum">
 | 
				
			||||||
@ -449,6 +442,13 @@
 | 
				
			|||||||
          <item row="0" column="1">
 | 
					          <item row="0" column="1">
 | 
				
			||||||
           <widget class="QFontComboBox" name="resultFont"/>
 | 
					           <widget class="QFontComboBox" name="resultFont"/>
 | 
				
			||||||
          </item>
 | 
					          </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">
 | 
					          <item row="1" column="0">
 | 
				
			||||||
           <widget class="QLabel" name="label_19">
 | 
					           <widget class="QLabel" name="label_19">
 | 
				
			||||||
            <property name="text">
 | 
					            <property name="text">
 | 
				
			||||||
@ -456,6 +456,20 @@
 | 
				
			|||||||
            </property>
 | 
					            </property>
 | 
				
			||||||
           </widget>
 | 
					           </widget>
 | 
				
			||||||
          </item>
 | 
					          </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>
 | 
					         </layout>
 | 
				
			||||||
        </widget>
 | 
					        </widget>
 | 
				
			||||||
       </item>
 | 
					       </item>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user