Add ability to apply settings without closing dialog
This commit is contained in:
		
							parent
							
								
									032895830c
								
							
						
					
					
						commit
						83232bfc76
					
				@ -185,6 +185,12 @@ void Manager::translated(const TaskPtr &task)
 | 
			
		||||
  representer_->represent(task);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Manager::applySettings(const Settings &settings)
 | 
			
		||||
{
 | 
			
		||||
  updateSettings(settings);
 | 
			
		||||
  settings.save();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Manager::fatalError(const QString &text)
 | 
			
		||||
{
 | 
			
		||||
  tray_->blockActions(false);
 | 
			
		||||
@ -216,7 +222,7 @@ void Manager::showLast()
 | 
			
		||||
 | 
			
		||||
void Manager::settings()
 | 
			
		||||
{
 | 
			
		||||
  SettingsEditor editor(*updater_);
 | 
			
		||||
  SettingsEditor editor(*this, *updater_);
 | 
			
		||||
 | 
			
		||||
  Settings settings;
 | 
			
		||||
  settings.load();
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,7 @@ public:
 | 
			
		||||
  void corrected(const TaskPtr &task);
 | 
			
		||||
  void translated(const TaskPtr &task);
 | 
			
		||||
 | 
			
		||||
  void applySettings(const Settings &settings);
 | 
			
		||||
  void fatalError(const QString &text);
 | 
			
		||||
  void capture();
 | 
			
		||||
  void repeatCapture();
 | 
			
		||||
 | 
			
		||||
@ -93,7 +93,7 @@ void cleanupOutdated(QSettings& settings)
 | 
			
		||||
 | 
			
		||||
}  // namespace
 | 
			
		||||
 | 
			
		||||
Settings::Settings()
 | 
			
		||||
void Settings::save() const
 | 
			
		||||
{
 | 
			
		||||
  const auto baseDataPath =
 | 
			
		||||
      QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
 | 
			
		||||
 | 
			
		||||
@ -21,9 +21,7 @@ enum class AutoUpdate { Disabled, Daily, Weekly, Monthly };
 | 
			
		||||
class Settings
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
  Settings();
 | 
			
		||||
 | 
			
		||||
  void save();
 | 
			
		||||
  void save() const;
 | 
			
		||||
  void load();
 | 
			
		||||
 | 
			
		||||
  QString captureHotkey{"Ctrl+Alt+Z"};
 | 
			
		||||
 | 
			
		||||
@ -1,5 +1,7 @@
 | 
			
		||||
#include "settingseditor.h"
 | 
			
		||||
#include "debug.h"
 | 
			
		||||
#include "languagecodes.h"
 | 
			
		||||
#include "manager.h"
 | 
			
		||||
#include "ui_settingseditor.h"
 | 
			
		||||
#include "updates.h"
 | 
			
		||||
#include "widgetstate.h"
 | 
			
		||||
@ -9,12 +11,16 @@
 | 
			
		||||
#include <QSortFilterProxyModel>
 | 
			
		||||
#include <QStringListModel>
 | 
			
		||||
 | 
			
		||||
SettingsEditor::SettingsEditor(update::Loader &updater)
 | 
			
		||||
SettingsEditor::SettingsEditor(Manager &manager, update::Loader &updater)
 | 
			
		||||
  : ui(new Ui::SettingsEditor)
 | 
			
		||||
  , manager_(manager)
 | 
			
		||||
  , updater_(updater)
 | 
			
		||||
{
 | 
			
		||||
  ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
  connect(ui->buttonBox, &QDialogButtonBox::clicked,  //
 | 
			
		||||
          this, &SettingsEditor::handleButtonBoxClicked);
 | 
			
		||||
 | 
			
		||||
  {
 | 
			
		||||
    auto model = new QStringListModel(this);
 | 
			
		||||
    model->setStringList({tr("General"), tr("Recognition"), tr("Correction"),
 | 
			
		||||
@ -248,3 +254,22 @@ void SettingsEditor::adjustUpdatesView()
 | 
			
		||||
  updateTesseractLanguages();
 | 
			
		||||
  updateTranslators();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void SettingsEditor::handleButtonBoxClicked(QAbstractButton *button)
 | 
			
		||||
{
 | 
			
		||||
  if (!button)
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
  if (button == ui->buttonBox->button(QDialogButtonBox::Ok)) {
 | 
			
		||||
    accept();
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (button == ui->buttonBox->button(QDialogButtonBox::Cancel)) {
 | 
			
		||||
    reject();
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if (button == ui->buttonBox->button(QDialogButtonBox::Apply)) {
 | 
			
		||||
    manager_.applySettings(settings());
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -8,13 +8,14 @@ namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class SettingsEditor;
 | 
			
		||||
}
 | 
			
		||||
class QAbstractButton;
 | 
			
		||||
 | 
			
		||||
class SettingsEditor : public QDialog
 | 
			
		||||
{
 | 
			
		||||
  Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
  explicit SettingsEditor(update::Loader &updater);
 | 
			
		||||
  SettingsEditor(Manager &manager, update::Loader &updater);
 | 
			
		||||
  ~SettingsEditor();
 | 
			
		||||
 | 
			
		||||
  Settings settings() const;
 | 
			
		||||
@ -26,8 +27,10 @@ private:
 | 
			
		||||
  void updateTranslators();
 | 
			
		||||
  void updateTranslationLanguages();
 | 
			
		||||
  void adjustUpdatesView();
 | 
			
		||||
  void handleButtonBoxClicked(QAbstractButton *button);
 | 
			
		||||
 | 
			
		||||
  Ui::SettingsEditor *ui;
 | 
			
		||||
  Manager &manager_;
 | 
			
		||||
  update::Loader &updater_;
 | 
			
		||||
  QStringList enabledTranslators_;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -20,7 +20,7 @@
 | 
			
		||||
      <enum>Qt::Horizontal</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="standardButtons">
 | 
			
		||||
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
      <set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
@ -541,38 +541,5 @@
 | 
			
		||||
  <tabstop>proxySaveCheck</tabstop>
 | 
			
		||||
 </tabstops>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>SettingsEditor</receiver>
 | 
			
		||||
   <slot>accept()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>256</x>
 | 
			
		||||
     <y>447</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>157</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>rejected()</signal>
 | 
			
		||||
   <receiver>SettingsEditor</receiver>
 | 
			
		||||
   <slot>reject()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>324</x>
 | 
			
		||||
     <y>447</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>286</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
 </connections>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user