Icons updated. Now use 4 icon types depending on internal state.

This commit is contained in:
Gres 2015-10-10 19:07:25 +03:00
parent 811b232c81
commit 45978ec013
9 changed files with 49 additions and 5 deletions

View File

@ -26,12 +26,13 @@
Manager::Manager (QObject *parent) : Manager::Manager (QObject *parent) :
QObject (parent), QObject (parent),
trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)), trayIcon_ (new QSystemTrayIcon (this)),
dictionary_ (new LanguageHelper), dictionary_ (new LanguageHelper),
resultDialog_ (new ResultDialog (*dictionary_)), resultDialog_ (new ResultDialog (*dictionary_)),
captureAction_ (NULL), repeatCaptureAction_ (NULL), captureAction_ (NULL), repeatCaptureAction_ (NULL),
repeatAction_ (NULL), clipboardAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL),
useResultDialog_ (true), doTranslation_ (true) { useResultDialog_ (true), doTranslation_ (true), itemProcessingCount_ (0) {
updateNormalIcon ();
GlobalActionHelper::init (); GlobalActionHelper::init ();
qRegisterMetaType<ProcessingItem>(); qRegisterMetaType<ProcessingItem>();
@ -215,6 +216,8 @@ void Manager::handleSelection (ProcessingItem item) {
item.translateLanguage = defaultTranslationLanguage_; item.translateLanguage = defaultTranslationLanguage_;
} }
emit requestRecognize (item); emit requestRecognize (item);
++itemProcessingCount_;
updateNormalIcon ();
if (!(item.modifiers & Qt::ControlModifier)) { if (!(item.modifiers & Qt::ControlModifier)) {
emit closeSelections (); emit closeSelections ();
} }
@ -279,7 +282,6 @@ void Manager::processTrayAction (QSystemTrayIcon::ActivationReason reason) {
} }
void Manager::editRecognized (ProcessingItem item) { void Manager::editRecognized (ProcessingItem item) {
ST_ASSERT (item.isValid ());
QString fixed = QInputDialog::getMultiLineText ( QString fixed = QInputDialog::getMultiLineText (
NULL, tr ("Правка"), tr ("Исправьте распознанный текст"), item.recognized); NULL, tr ("Правка"), tr ("Исправьте распознанный текст"), item.recognized);
if (!fixed.isEmpty ()) { if (!fixed.isEmpty ()) {
@ -316,7 +318,13 @@ void Manager::copyLastImageToClipboard () {
} }
void Manager::showResult (ProcessingItem item) { 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_) { if (useResultDialog_) {
resultDialog_->showResult (item); resultDialog_->showResult (item);
} }
@ -329,5 +337,30 @@ void Manager::showResult (ProcessingItem item) {
void Manager::showError (QString text) { void Manager::showError (QString text) {
qCritical () << text; qCritical () << text;
changeIcon (IconTypeError);
trayIcon_->showMessage (tr ("Ошибка"), text, QSystemTrayIcon::Critical); 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));
}

View File

@ -17,6 +17,10 @@ class LanguageHelper;
class Manager : public QObject { class Manager : public QObject {
Q_OBJECT Q_OBJECT
enum IconType {
IconTypeNormal, IconTypeWorking, IconTypeError, IconTypeSuccess
};
public: public:
explicit Manager (QObject *parent = 0); explicit Manager (QObject *parent = 0);
~Manager (); ~Manager ();
@ -46,9 +50,12 @@ class Manager : public QObject {
void showResult (ProcessingItem item); void showResult (ProcessingItem item);
void showError (QString text); void showError (QString text);
void updateNormalIcon ();
private: private:
QMenu * trayContextMenu (); QMenu * trayContextMenu ();
void updateActionsState (bool isEnabled = true); void updateActionsState (bool isEnabled = true);
void changeIcon (int iconType, int timeoutMsec = 3000);
private: private:
QSystemTrayIcon *trayIcon_; QSystemTrayIcon *trayIcon_;
@ -65,6 +72,7 @@ class Manager : public QObject {
QList<QThread *> threads_; QList<QThread *> threads_;
QString defaultTranslationLanguage_; QString defaultTranslationLanguage_;
bool doTranslation_; bool doTranslation_;
int itemProcessingCount_;
}; };
#endif // MANAGER_H #endif // MANAGER_H

View File

@ -2,6 +2,9 @@
<qresource prefix="/"> <qresource prefix="/">
<file>translations/translation_en.qm</file> <file>translations/translation_en.qm</file>
<file>translations/translation_ru.qm</file> <file>translations/translation_ru.qm</file>
<file>images/icon.png</file> <file>images/STIconBlue.png</file>
<file>images/STIconGreen.png</file>
<file>images/STIconOrange.png</file>
<file>images/STIconRed.png</file>
</qresource> </qresource>
</RCC> </RCC>

BIN
images/STIconBlue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

BIN
images/STIconGreen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

BIN
images/STIconOrange.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
images/STIconRed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.5 KiB