From 468a6fd039f4ac8c6f6ad69492ba63af51c3ac12 Mon Sep 17 00:00:00 2001 From: Gres Date: Fri, 9 Oct 2015 23:34:24 +0300 Subject: [PATCH] SettingsEditor updated. Added rescent translator settings. --- SettingsEditor.cpp | 42 +++- SettingsEditor.h | 2 + SettingsEditor.ui | 507 +++++++++++++++++++++++++-------------------- 3 files changed, 325 insertions(+), 226 deletions(-) diff --git a/SettingsEditor.cpp b/SettingsEditor.cpp index 0fc694f..1f452eb 100644 --- a/SettingsEditor.cpp +++ b/SettingsEditor.cpp @@ -1,15 +1,17 @@ #include "SettingsEditor.h" #include "ui_SettingsEditor.h" #include "LanguageHelper.h" +#include "TranslatorHelper.h" #include #include +#include #include "Settings.h" SettingsEditor::SettingsEditor (const LanguageHelper &dictionary, QWidget *parent) : QDialog (parent), - ui (new Ui::SettingsEditor), dictionary_ (dictionary), + ui (new Ui::SettingsEditor), translatorHelper_ (new TranslatorHelper), dictionary_ (dictionary), buttonGroup_ (new QButtonGroup (this)) { ui->setupUi (this); @@ -27,6 +29,7 @@ SettingsEditor::SettingsEditor (const LanguageHelper &dictionary, QWidget *paren SettingsEditor::~SettingsEditor () { saveState (); + delete translatorHelper_; delete ui; } @@ -52,19 +55,32 @@ void SettingsEditor::saveSettings () const { settings.beginGroup (recogntionGroup); settings.setValue (tessDataPlace, ui->tessdataEdit->text ()); - QString ocrLanguage = dictionary_.ocrUiToCode (ui->ocrLangCombo->currentText ()); - settings.setValue (ocrLanguage, ocrLanguage); + QString ocrLanguageVal = dictionary_.ocrUiToCode (ui->ocrLangCombo->currentText ()); + settings.setValue (ocrLanguage, ocrLanguageVal); settings.setValue (imageScale, ui->imageScaleSpin->value ()); settings.endGroup (); settings.beginGroup (translationGroup); - settings.setValue (doTranslation, ui->doTranslationCombo->isChecked ()); + settings.setValue (doTranslation, ui->doTranslationCheck->isChecked ()); + settings.setValue (translationDebugMode, ui->translatorDebugCheck->isChecked ()); QString trLanguage = dictionary_.translateUiToCode (ui->translateLangCombo->currentText ()); settings.setValue (translationLanguage, trLanguage); - QString sourceLanguage = dictionary_.translateForOcrCode (ocrLanguage); - settings.setValue (sourceLanguage, sourceLanguage); + QString sourceLanguageVal = dictionary_.translateForOcrCode (ocrLanguage); + settings.setValue (sourceLanguage, sourceLanguageVal); settings.setValue (translationTimeout, ui->translateTimeoutSpin->value ()); + + {//Translators + QStringList enabled; + for (int i = 0, end = ui->translatorList->count (); i < end; ++i) { + QListWidgetItem *item = ui->translatorList->item (i); + if (item->checkState () == Qt::Checked) { + enabled << item->text (); + } + } + translatorHelper_->setEnabledTranslators (enabled); + } + settings.endGroup (); } @@ -102,10 +118,22 @@ void SettingsEditor::loadSettings () { settings.endGroup (); settings.beginGroup (settings_names::translationGroup); - ui->doTranslationCombo->setChecked (GET (doTranslation).toBool ()); + ui->doTranslationCheck->setChecked (GET (doTranslation).toBool ()); + ui->translatorDebugCheck->setChecked (GET (translationDebugMode).toBool ()); QString trLanguage = dictionary_.translateCodeToUi (GET (translationLanguage).toString ()); ui->translateLangCombo->setCurrentText (trLanguage); ui->translateTimeoutSpin->setValue (GET (translationTimeout).toInt ()); + + {// Translators + QStringList enabled; + ui->translatorList->addItems (translatorHelper_->possibleTranslators (enabled)); + for (int i = 0, end = ui->translatorList->count (); i < end; ++i) { + QListWidgetItem *item = ui->translatorList->item (i); + Qt::CheckState state = enabled.contains (item->text ()) ? Qt::Checked : Qt::Unchecked; + item->setCheckState (state); + } + } + settings.endGroup (); #undef GET } diff --git a/SettingsEditor.h b/SettingsEditor.h index 2fb0861..0558bc2 100644 --- a/SettingsEditor.h +++ b/SettingsEditor.h @@ -9,6 +9,7 @@ namespace Ui { class SettingsEditor; } class LanguageHelper; +class TranslatorHelper; class SettingsEditor : public QDialog { Q_OBJECT @@ -35,6 +36,7 @@ class SettingsEditor : public QDialog { private: Ui::SettingsEditor *ui; + TranslatorHelper *translatorHelper_; const LanguageHelper &dictionary_; QButtonGroup *buttonGroup_; }; diff --git a/SettingsEditor.ui b/SettingsEditor.ui index c255e6a..c74df95 100644 --- a/SettingsEditor.ui +++ b/SettingsEditor.ui @@ -6,92 +6,15 @@ 0 0 - 603 - 296 + 509 + 338 Настройки - - - - - Qt::Vertical - - - - 20 - 1 - - - - - - - - Распознавание - - - - - - <html><head/><body><p>Необходимо для распознавания.</p><p>Скачивается отсюда: <a href="https://github.com/tesseract-ocr/tessdata"><span style=" text-decoration: underline; color:#7593bc;">https://github.com/tesseract-ocr/tessdata</span></a></p><p>&quot;./&quot; означает, что папка &quot;tessdata&quot; находится в одной директории с исполняемым файлом программы.</p></body></html> - - - Путь к tessdata - - - tessdataEdit - - - - - - - - - - ... - - - - - - - <html><head/><body><p>Заполняется на основании содержания tessdata</p></body></html> - - - Язык распознавания - - - ocrLangCombo - - - - - - - <html><head/><body><p>Масштабирование изображения для улучшения распознания. Больше - лучше (до определенных пределов), но медленнее и потребляет больше памяти.</p><p>Рекомендуемые значения от 5 до 10.</p></body></html> - - - Увеличение масштаба - - - imageScaleSpin - - - - - - - - - - - - - + + Qt::Horizontal @@ -101,154 +24,300 @@ - - - - Вывод результата + + + + 0 - - - - - Трей - - - - - - - Окно - - - true - - - - - - - - - - Горячие клавиши - - - - - - <html><head/><body><p>Сочетание клавиш для перехода в режим захвата.</p></body></html> - - - Захватить - - - - - - - - - - <html><head/><body><p>Сочетание клавиш для перехода в режим захвата, но с использованием последнего использованного, а не текущего, изображения.</p></body></html> - - - Захватить повторно - - - - - - - - - - <html><head/><body><p>Сочетание клавиш для повторного отображения последнего результата.</p></body></html> - - - Показать - - - - - - - - - - <html><head/><body><p>Сочетание клавиш для копирования последнего результата в буфер обмена.</p></body></html> - - - Скопировать - - - - - - - - - - - - - Перевод - - - - - - <html><head/><body><p>Необходимо ли переводить (вкл) распознанный текст.</p></body></html> - - - Переводить текст - - - - - - - <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> - - - Максимальное время перевода: - - - - - - - сек. - - - - - - - <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> - - - Язык результата: - - - translateLangCombo - - - - - - - + + + Общее + + + + + + Горячие клавиши + + + + + + <html><head/><body><p>Сочетание клавиш для перехода в режим захвата.</p></body></html> + + + Захватить + + + + + + + + + + <html><head/><body><p>Сочетание клавиш для перехода в режим захвата, но с использованием последнего использованного, а не текущего, изображения.</p></body></html> + + + Захватить повторно + + + + + + + + + + <html><head/><body><p>Сочетание клавиш для повторного отображения последнего результата.</p></body></html> + + + Показать + + + + + + + + + + <html><head/><body><p>Сочетание клавиш для копирования последнего результата в буфер обмена.</p></body></html> + + + Скопировать + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 270 + + + + + + + + Вывод результата + + + + + + Трей + + + + + + + Окно + + + true + + + + + + + + + + + Распознавание + + + + + + <html><head/><body><p>Необходимо для распознавания.</p><p>Скачивается отсюда: <a href="https://github.com/tesseract-ocr/tessdata"><span style=" text-decoration: underline; color:#7593bc;">https://github.com/tesseract-ocr/tessdata</span></a></p><p>&quot;./&quot; означает, что папка &quot;tessdata&quot; находится в одной директории с исполняемым файлом программы.</p></body></html> + + + Путь к tessdata + + + tessdataEdit + + + + + + + + + + ... + + + + + + + <html><head/><body><p>Заполняется на основании содержания tessdata</p></body></html> + + + Язык распознавания + + + ocrLangCombo + + + + + + + + + + <html><head/><body><p>Масштабирование изображения для улучшения распознания. Больше - лучше (до определенных пределов), но медленнее и потребляет больше памяти.</p><p>Рекомендуемые значения от 5 до 10.</p></body></html> + + + Увеличение масштаба + + + imageScaleSpin + + + + + + + + + + Qt::Vertical + + + + 20 + 132 + + + + + + + + + Перевод + + + + + + <html><head/><body><p>Необходимо ли переводить (вкл) распознанный текст.</p></body></html> + + + Переводить текст + + + + + + + <html><head/><body><p>Отображает окно переводчика. Следует использовать только для разработки переводчиков.</p></body></html> + + + Режим отладки + + + + + + + <html><head/><body><p>Максимальное время, которое может быть затрачено на перевод, чтобы он не считался &quot;зависшим&quot;.</p></body></html> + + + Максимальное время перевода: + + + + + + + <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> + + + Язык результата: + + + translateLangCombo + + + + + + + Переводчики: + + + Qt::AlignCenter + + + + + + + + + + сек. + + + + + + + <html><head/><body><p>Отображены в порядке убывания приоритета.</p></body></html> + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + + + + + - translateLangCombo + tabWidget + captureEdit + repeatCaptureEdit + repeatEdit + clipboardEdit + trayRadio + dialogRadio tessdataEdit tessdataButton ocrLangCombo imageScaleSpin - buttonBox + doTranslationCheck + translatorDebugCheck + translateTimeoutSpin + translateLangCombo + translatorList