2013-11-23 13:48:34 +07:00
|
|
|
#include "SettingsEditor.h"
|
|
|
|
#include "ui_SettingsEditor.h"
|
2014-04-04 21:39:10 +07:00
|
|
|
#include "LanguageHelper.h"
|
2013-11-23 13:48:34 +07:00
|
|
|
|
2013-11-24 19:43:37 +07:00
|
|
|
#include <QSettings>
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
|
|
|
#include "Settings.h"
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
SettingsEditor::SettingsEditor (const LanguageHelper &dictionary, QWidget *parent) :
|
|
|
|
QDialog (parent),
|
|
|
|
ui (new Ui::SettingsEditor), dictionary_ (dictionary),
|
|
|
|
buttonGroup_ (new QButtonGroup (this)) {
|
|
|
|
ui->setupUi (this);
|
2013-11-24 19:43:37 +07:00
|
|
|
|
2013-11-26 23:59:47 +07:00
|
|
|
buttonGroup_->addButton (ui->trayRadio, 0);
|
|
|
|
buttonGroup_->addButton (ui->dialogRadio, 1);
|
|
|
|
|
2013-11-24 19:43:37 +07:00
|
|
|
connect (ui->tessdataButton, SIGNAL (clicked ()), SLOT (openTessdataDialog ()));
|
2015-09-23 01:41:08 +07:00
|
|
|
connect (ui->tessdataEdit, SIGNAL (textChanged (const QString &)),
|
|
|
|
SLOT (initOcrLangCombo (const QString &)));
|
2013-11-24 19:43:37 +07:00
|
|
|
|
2014-04-04 21:39:10 +07:00
|
|
|
ui->translateLangCombo->addItems (dictionary_.translateLanguagesUi ());
|
2013-11-24 19:43:37 +07:00
|
|
|
loadSettings ();
|
|
|
|
loadState ();
|
2013-11-23 13:48:34 +07:00
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
SettingsEditor::~SettingsEditor () {
|
2013-11-24 19:43:37 +07:00
|
|
|
saveState ();
|
2013-11-23 13:48:34 +07:00
|
|
|
delete ui;
|
|
|
|
}
|
2013-11-24 19:43:37 +07:00
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::done (int result) {
|
|
|
|
if (result == QDialog::Accepted) {
|
2013-11-24 19:43:37 +07:00
|
|
|
saveSettings ();
|
|
|
|
emit settingsEdited ();
|
|
|
|
}
|
|
|
|
QDialog::done (result);
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::saveSettings () const {
|
2015-09-27 22:57:50 +07:00
|
|
|
using namespace settings_names;
|
2013-11-24 19:43:37 +07:00
|
|
|
QSettings settings;
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.beginGroup (guiGroup);
|
|
|
|
settings.setValue (captureHotkey, ui->captureEdit->keySequence ().toString ());
|
2015-09-29 22:14:56 +07:00
|
|
|
settings.setValue (repeatCaptureHotkey, ui->repeatCaptureEdit->keySequence ().toString ());
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.setValue (repeatHotkey, ui->repeatEdit->keySequence ().toString ());
|
|
|
|
settings.setValue (clipboardHotkey, ui->clipboardEdit->keySequence ().toString ());
|
|
|
|
settings.setValue (resultShowType, buttonGroup_->checkedId ());
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.endGroup ();
|
|
|
|
|
|
|
|
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.beginGroup (recogntionGroup);
|
|
|
|
settings.setValue (tessDataPlace, ui->tessdataEdit->text ());
|
2014-04-04 21:39:10 +07:00
|
|
|
QString ocrLanguage = dictionary_.ocrUiToCode (ui->ocrLangCombo->currentText ());
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.setValue (ocrLanguage, ocrLanguage);
|
|
|
|
settings.setValue (imageScale, ui->imageScaleSpin->value ());
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.endGroup ();
|
|
|
|
|
|
|
|
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.beginGroup (translationGroup);
|
2015-09-29 19:30:04 +07:00
|
|
|
settings.setValue (doTranslation, ui->doTranslationCombo->isChecked ());
|
2014-04-04 21:39:10 +07:00
|
|
|
QString trLanguage = dictionary_.translateUiToCode (ui->translateLangCombo->currentText ());
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.setValue (translationLanguage, trLanguage);
|
2014-04-04 21:39:10 +07:00
|
|
|
QString sourceLanguage = dictionary_.translateForOcrCode (ocrLanguage);
|
2015-09-27 22:57:50 +07:00
|
|
|
settings.setValue (sourceLanguage, sourceLanguage);
|
2015-10-08 22:36:02 +07:00
|
|
|
settings.setValue (translationTimeout, ui->translateTimeoutSpin->value ());
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.endGroup ();
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::openTessdataDialog () {
|
2013-11-24 19:43:37 +07:00
|
|
|
QString path = QFileDialog::getExistingDirectory (this, tr ("Путь к tessdata"));
|
2015-09-23 01:41:08 +07:00
|
|
|
if (path.isEmpty ()) {
|
2013-11-24 19:43:37 +07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QDir dir (path);
|
2015-09-23 01:41:08 +07:00
|
|
|
if (dir.dirName () == QString ("tessdata")) {
|
2013-11-24 19:43:37 +07:00
|
|
|
dir.cdUp ();
|
|
|
|
}
|
|
|
|
ui->tessdataEdit->setText (dir.path ());
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::loadSettings () {
|
2014-04-04 21:39:10 +07:00
|
|
|
#define GET(FIELD) settings.value (settings_names::FIELD, settings_values::FIELD)
|
2013-11-24 19:43:37 +07:00
|
|
|
QSettings settings;
|
2014-04-04 21:39:10 +07:00
|
|
|
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.beginGroup (settings_names::guiGroup);
|
2015-09-27 22:57:50 +07:00
|
|
|
ui->captureEdit->setKeySequence (QKeySequence (GET (captureHotkey).toString ()));
|
2015-09-29 22:14:56 +07:00
|
|
|
ui->repeatCaptureEdit->setKeySequence (QKeySequence (GET (repeatCaptureHotkey).toString ()));
|
2015-09-27 22:57:50 +07:00
|
|
|
ui->repeatEdit->setKeySequence (QKeySequence (GET (repeatHotkey).toString ()));
|
|
|
|
ui->clipboardEdit->setKeySequence (QKeySequence (GET (clipboardHotkey).toString ()));
|
2015-09-23 01:41:08 +07:00
|
|
|
QAbstractButton *button = buttonGroup_->button (GET (resultShowType).toInt ());
|
2013-11-26 23:59:47 +07:00
|
|
|
Q_CHECK_PTR (button);
|
|
|
|
button->setChecked (true);
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.endGroup ();
|
|
|
|
|
|
|
|
settings.beginGroup (settings_names::recogntionGroup);
|
2015-09-23 01:41:08 +07:00
|
|
|
ui->tessdataEdit->setText (GET (tessDataPlace).toString ());
|
|
|
|
QString ocrLanguage = dictionary_.ocrCodeToUi (GET (ocrLanguage).toString ());
|
2014-04-04 21:39:10 +07:00
|
|
|
ui->ocrLangCombo->setCurrentText (ocrLanguage);
|
2015-09-23 01:41:08 +07:00
|
|
|
ui->imageScaleSpin->setValue (GET (imageScale).toInt ());
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.endGroup ();
|
|
|
|
|
|
|
|
settings.beginGroup (settings_names::translationGroup);
|
2015-09-29 19:30:04 +07:00
|
|
|
ui->doTranslationCombo->setChecked (GET (doTranslation).toBool ());
|
2015-09-23 01:41:08 +07:00
|
|
|
QString trLanguage = dictionary_.translateCodeToUi (GET (translationLanguage).toString ());
|
2014-04-04 21:39:10 +07:00
|
|
|
ui->translateLangCombo->setCurrentText (trLanguage);
|
2015-10-08 22:36:02 +07:00
|
|
|
ui->translateTimeoutSpin->setValue (GET (translationTimeout).toInt ());
|
2013-11-24 19:43:37 +07:00
|
|
|
settings.endGroup ();
|
2014-04-04 21:39:10 +07:00
|
|
|
#undef GET
|
2013-11-24 19:43:37 +07:00
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::saveState () const {
|
2013-11-24 19:43:37 +07:00
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup (settings_names::guiGroup);
|
|
|
|
settings.setValue (objectName () + "_" + settings_names::geometry, saveGeometry ());
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::loadState () {
|
2013-11-24 19:43:37 +07:00
|
|
|
QSettings settings;
|
|
|
|
settings.beginGroup (settings_names::guiGroup);
|
|
|
|
restoreGeometry (settings.value (objectName () + "_" + settings_names::geometry).toByteArray ());
|
|
|
|
}
|
|
|
|
|
2015-09-23 01:41:08 +07:00
|
|
|
void SettingsEditor::initOcrLangCombo (const QString &path) {
|
2013-11-24 19:43:37 +07:00
|
|
|
ui->ocrLangCombo->clear ();
|
2014-04-04 22:01:04 +07:00
|
|
|
ui->ocrLangCombo->addItems (dictionary_.availableOcrLanguagesUi (path));
|
2013-11-24 19:43:37 +07:00
|
|
|
}
|