diff --git a/Manager.cpp b/Manager.cpp index 0f2eb5d..4ee2372 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -26,12 +26,13 @@ Manager::Manager (QObject *parent) : QObject (parent), - trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)), + trayIcon_ (new QSystemTrayIcon (this)), dictionary_ (new LanguageHelper), resultDialog_ (new ResultDialog (*dictionary_)), captureAction_ (NULL), repeatCaptureAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL), - useResultDialog_ (true), doTranslation_ (true) { + useResultDialog_ (true), doTranslation_ (true), itemProcessingCount_ (0) { + updateNormalIcon (); GlobalActionHelper::init (); qRegisterMetaType(); @@ -215,6 +216,8 @@ void Manager::handleSelection (ProcessingItem item) { item.translateLanguage = defaultTranslationLanguage_; } emit requestRecognize (item); + ++itemProcessingCount_; + updateNormalIcon (); if (!(item.modifiers & Qt::ControlModifier)) { emit closeSelections (); } @@ -279,7 +282,6 @@ void Manager::processTrayAction (QSystemTrayIcon::ActivationReason reason) { } void Manager::editRecognized (ProcessingItem item) { - ST_ASSERT (item.isValid ()); QString fixed = QInputDialog::getMultiLineText ( NULL, tr ("Правка"), tr ("Исправьте распознанный текст"), item.recognized); if (!fixed.isEmpty ()) { @@ -316,7 +318,13 @@ void Manager::copyLastImageToClipboard () { } void Manager::showResult (ProcessingItem item) { - ST_ASSERT (item.isValid ()); + --itemProcessingCount_; + if (!item.isValid ()) { + // delay because it can show error + QTimer::singleShot (3000, this, SLOT (updateNormalIcon ())); + return; + } + changeIcon (IconTypeSuccess); if (useResultDialog_) { resultDialog_->showResult (item); } @@ -329,5 +337,30 @@ void Manager::showResult (ProcessingItem item) { void Manager::showError (QString text) { qCritical () << text; + changeIcon (IconTypeError); trayIcon_->showMessage (tr ("Ошибка"), text, QSystemTrayIcon::Critical); } + +void Manager::changeIcon (int iconType, int timeoutMsec) { + QString fileName; + switch (iconType) { + case IconTypeSuccess: + fileName = ":/images/STIconGreen.png"; + break; + case IconTypeError: + fileName = ":/images/STIconRed.png"; + break; + default: + return; + } + trayIcon_->setIcon (QIcon (fileName)); + if (timeoutMsec > 0) { + QTimer::singleShot (timeoutMsec, this, SLOT (updateNormalIcon ())); + } +} + +void Manager::updateNormalIcon () { + QString fileName = itemProcessingCount_ > 0 + ? ":/images/STIconOrange.png" : ":/images/STIconBlue.png"; + trayIcon_->setIcon (QIcon (fileName)); +} diff --git a/Manager.h b/Manager.h index 710d6cb..adcf665 100644 --- a/Manager.h +++ b/Manager.h @@ -17,6 +17,10 @@ class LanguageHelper; class Manager : public QObject { Q_OBJECT + enum IconType { + IconTypeNormal, IconTypeWorking, IconTypeError, IconTypeSuccess + }; + public: explicit Manager (QObject *parent = 0); ~Manager (); @@ -46,9 +50,12 @@ class Manager : public QObject { void showResult (ProcessingItem item); void showError (QString text); + void updateNormalIcon (); + private: QMenu * trayContextMenu (); void updateActionsState (bool isEnabled = true); + void changeIcon (int iconType, int timeoutMsec = 3000); private: QSystemTrayIcon *trayIcon_; @@ -65,6 +72,7 @@ class Manager : public QObject { QList threads_; QString defaultTranslationLanguage_; bool doTranslation_; + int itemProcessingCount_; }; #endif // MANAGER_H diff --git a/Recources.qrc b/Recources.qrc index 920e5ba..67a7a5f 100644 --- a/Recources.qrc +++ b/Recources.qrc @@ -2,6 +2,9 @@ translations/translation_en.qm translations/translation_ru.qm - images/icon.png + images/STIconBlue.png + images/STIconGreen.png + images/STIconOrange.png + images/STIconRed.png diff --git a/images/STIconBlue.png b/images/STIconBlue.png new file mode 100644 index 0000000..7ca2c3c Binary files /dev/null and b/images/STIconBlue.png differ diff --git a/images/STIconGreen.png b/images/STIconGreen.png new file mode 100644 index 0000000..4892af1 Binary files /dev/null and b/images/STIconGreen.png differ diff --git a/images/STIconOrange.png b/images/STIconOrange.png new file mode 100644 index 0000000..9bfa7e6 Binary files /dev/null and b/images/STIconOrange.png differ diff --git a/images/STIconRed.png b/images/STIconRed.png new file mode 100644 index 0000000..672c573 Binary files /dev/null and b/images/STIconRed.png differ diff --git a/images/icon.ico b/images/icon.ico index a89f6ee..abbac3b 100644 Binary files a/images/icon.ico and b/images/icon.ico differ diff --git a/images/icon.png b/images/icon.png deleted file mode 100644 index 17fc2c5..0000000 Binary files a/images/icon.png and /dev/null differ