diff --git a/Manager.cpp b/Manager.cpp index 62dd275..0efe195 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -1,13 +1,13 @@ #include "Manager.h" #include -#include #include #include #include #include #include #include +#include #include "Settings.h" #include "SettingsEditor.h" @@ -54,6 +54,9 @@ Manager::Manager(QObject *parent) : connect (this, SIGNAL (settingsEdited ()), recognizer, SLOT (applySettings ())); connect (this, SIGNAL (settingsEdited ()), translator, SLOT (applySettings ())); + connect (trayIcon_, SIGNAL (activated (QSystemTrayIcon::ActivationReason)), + SLOT (processTrayAction (QSystemTrayIcon::ActivationReason))); + trayIcon_->setContextMenu (trayContextMenu ()); trayIcon_->show (); @@ -65,6 +68,7 @@ QMenu*Manager::trayContextMenu() QMenu* menu = new QMenu (); captureAction_ = menu->addAction (tr ("Захват"), this, SLOT (capture ())); menu->addAction (tr ("Настройки"), this, SLOT (settings ())); + menu->addAction (tr ("О программе"), this, SLOT (about ())); menu->addAction (tr ("Выход"), this, SLOT (close ())); return menu; } @@ -82,6 +86,18 @@ void Manager::applySettings() GlobalActionHelper::makeGlobal (captureAction_); } +void Manager::processTrayAction(QSystemTrayIcon::ActivationReason reason) +{ + if (reason == QSystemTrayIcon::Trigger) + { + if (!lastMessage_.isEmpty ()) + { + trayIcon_->showMessage (tr ("Последний перевод"), lastMessage_, + QSystemTrayIcon::Information); + } + } +} + Manager::~Manager() { } @@ -111,11 +127,23 @@ void Manager::close() QApplication::quit (); } +void Manager::about() +{ + QString text = tr ("Программа для распознавания текста на экране.\n"\ + "Создана с использованием Qt, tesseract-ocr, Google Translate.\n" + "Автор: Gres (dariusiii@qip.ru)"); + + QMessageBox message (QMessageBox::Information, tr ("О программе"), text, + QMessageBox::Ok); + message.setIconPixmap (trayIcon_->icon ().pixmap (QSize (64, 64))); + message.exec (); +} + void Manager::showTranslation(QString sourceText, QString translatedText) { - QString message = sourceText + " - " + translatedText; + lastMessage_ = sourceText + " - " + translatedText; qDebug () << sourceText << translatedText; - trayIcon_->showMessage (tr ("Перевод"), message, QSystemTrayIcon::Information); + trayIcon_->showMessage (tr ("Перевод"), lastMessage_, QSystemTrayIcon::Information); } void Manager::showError(QString text) diff --git a/Manager.h b/Manager.h index b9d01ae..f1bfe46 100644 --- a/Manager.h +++ b/Manager.h @@ -1,12 +1,11 @@ #ifndef MANAGER_H #define MANAGER_H -#include #include +#include class QAction; class QMenu; -class QSystemTrayIcon; class SelectionDialog; @@ -26,9 +25,12 @@ class Manager : public QObject void capture (); void settings (); void close (); + void about (); void applySettings (); + void processTrayAction (QSystemTrayIcon::ActivationReason reason); + void showTranslation (QString sourceText, QString translatedText); void showError (QString text); @@ -39,7 +41,7 @@ class Manager : public QObject QSystemTrayIcon* trayIcon_; SelectionDialog* selection_; QAction* captureAction_; - + QString lastMessage_; }; #endif // MANAGER_H diff --git a/Recognizer.cpp b/Recognizer.cpp index 70be52f..38cbf99 100644 --- a/Recognizer.cpp +++ b/Recognizer.cpp @@ -21,6 +21,10 @@ void Recognizer::applySettings() tessDataDir_ = settings.value (settings_names::tessDataPlace, settings_values::tessDataPlace).toString (); + if (tessDataDir_.right (1) != "/") + { + tessDataDir_ += "/"; + } ocrLanguage_ = settings.value (settings_names::ocrLanguage, settings_values::ocrLanguage).toString (); imageScale_ = settings.value (settings_names::imageScale, diff --git a/SettingsEditor.ui b/SettingsEditor.ui index 1f3e150..ae51d16 100644 --- a/SettingsEditor.ui +++ b/SettingsEditor.ui @@ -7,7 +7,7 @@ 0 0 456 - 165 + 166 @@ -22,9 +22,15 @@ + + <html><head/><body><p>Сочетание клавиш для перехода в режим захвата.</p></body></html> + Захват + + captureEdit + @@ -41,9 +47,15 @@ + + <html><head/><body><p>Необходимо для распознавания.</p><p>Скачивается отсюда: <a href="https://code.google.com/p/tesseract-ocr/downloads/list"><span style=" text-decoration: underline; color:#0000ff;">https://code.google.com/p/tesseract-ocr/downloads/list</span></a></p></body></html> + Путь к tessdata + + tessdataEdit + @@ -58,16 +70,28 @@ + + <html><head/><body><p>Заполняется на основании содержания tessdata</p></body></html> + Язык распознавания + + ocrLangCombo + + + <html><head/><body><p>Масштабирование изображения для улучшения распознания. Больше - лучше (до определенных пределов), но медленнее.</p></body></html> + Увеличение масштаба + + imageScaleSpin + @@ -87,9 +111,15 @@ + + <html><head/><body><p>Язык, на который осуществляется перевод.</p></body></html> + Язык результата + + translateLangCombo + @@ -136,6 +166,15 @@ + + captureEdit + translateLangCombo + tessdataEdit + tessdataButton + ocrLangCombo + imageScaleSpin + buttonBox +