From fb1d25f91416912ba191bbb061cfc01243ecd4b5 Mon Sep 17 00:00:00 2001 From: Gres Date: Wed, 30 Sep 2015 19:49:10 +0300 Subject: [PATCH] Added possibility to select image several times without closing SelectionDialog. --- Manager.cpp | 13 ++++++++++--- Manager.h | 3 ++- ProcessingItem.h | 2 ++ ResultDialog.cpp | 5 +++-- ScreenTranslator.pro | 5 +++-- SelectionDialog.cpp | 4 +++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Manager.cpp b/Manager.cpp index 2dddab5..ecbbfec 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -34,7 +34,7 @@ Manager::Manager (QObject *parent) : // Recognizer Recognizer *recognizer = new Recognizer; - connect (this, SIGNAL (selected (ProcessingItem)), + connect (this, SIGNAL (requestRecognize (ProcessingItem)), recognizer, SLOT (recognize (ProcessingItem))); connect (recognizer, SIGNAL (recognized (ProcessingItem)), SIGNAL (recognized (ProcessingItem))); @@ -188,8 +188,8 @@ void Manager::capture () { selection->setWindowIcon (trayIcon_->icon ()); connect (this, SIGNAL (closeSelections ()), selection, SLOT (close ())); connect (this, SIGNAL (settingsEdited ()), selection, SLOT (updateMenu ())); - connect (selection, SIGNAL (selected (ProcessingItem)), SIGNAL (selected (ProcessingItem))); - connect (selection, SIGNAL (selected (ProcessingItem)), SIGNAL (closeSelections ())); + connect (selection, SIGNAL (selected (ProcessingItem)), + SLOT (handleSelection (ProcessingItem))); connect (selection, SIGNAL (rejected ()), SIGNAL (closeSelections ())); selections_[name] = selection; } @@ -199,6 +199,13 @@ void Manager::capture () { updateActionsState (); } +void Manager::handleSelection (ProcessingItem item) { + emit requestRecognize (item); + if (!(item.modifiers & Qt::ControlModifier)) { + emit closeSelections (); + } +} + void Manager::repeatCapture () { if (selections_.isEmpty ()) { return; diff --git a/Manager.h b/Manager.h index be0ba46..ba06f6d 100644 --- a/Manager.h +++ b/Manager.h @@ -22,7 +22,7 @@ class Manager : public QObject { ~Manager (); signals: - void selected (ProcessingItem item); + void requestRecognize (ProcessingItem item); void recognized (ProcessingItem item); void requestTranslate (ProcessingItem item); void closeSelections (); @@ -41,6 +41,7 @@ class Manager : public QObject { void processTrayAction (QSystemTrayIcon::ActivationReason reason); + void handleSelection (ProcessingItem item); void showResult (ProcessingItem item); void showError (QString text); diff --git a/ProcessingItem.h b/ProcessingItem.h index 914673c..7d6ca8c 100644 --- a/ProcessingItem.h +++ b/ProcessingItem.h @@ -12,6 +12,8 @@ struct ProcessingItem { QString ocrLanguage; QString sourceLanguage; + Qt::KeyboardModifiers modifiers; + bool isValid () const; }; Q_DECLARE_METATYPE (ProcessingItem) diff --git a/ResultDialog.cpp b/ResultDialog.cpp index e263a0c..85c615f 100644 --- a/ResultDialog.cpp +++ b/ResultDialog.cpp @@ -10,7 +10,7 @@ ResultDialog::ResultDialog (QWidget *parent) : isShowAtCapturePos_ (true) { ui->setupUi (this); setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | - Qt::WindowStaysOnTopHint); + Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); installEventFilter (this); } @@ -21,7 +21,8 @@ ResultDialog::~ResultDialog () { bool ResultDialog::eventFilter (QObject *object, QEvent *event) { Q_UNUSED (object); - if (event->type () == QEvent::MouseButtonRelease) { + if (event->type () == QEvent::MouseButtonRelease || + event->type () == QEvent::WindowDeactivate) { hide (); } return QDialog::eventFilter (object, event); diff --git a/ScreenTranslator.pro b/ScreenTranslator.pro index 2ad6709..8af33c0 100644 --- a/ScreenTranslator.pro +++ b/ScreenTranslator.pro @@ -19,7 +19,7 @@ win32{ linux{ QT += x11extras INCLUDEPATH += ../linux/include - LIBS += -L../linux/lib -lX11 + LIBS += -L../linux/lib -lX11 -Wl,-rpath,. } LIBS += -ltesseract -llept @@ -70,4 +70,5 @@ OTHER_FILES += \ app.rc \ images/icon.ico \ README.md \ - uncrustify.cfg + uncrustify.cfg\ + TODO.md diff --git a/SelectionDialog.cpp b/SelectionDialog.cpp index f2b04ad..3bbc9e8 100644 --- a/SelectionDialog.cpp +++ b/SelectionDialog.cpp @@ -14,7 +14,7 @@ SelectionDialog::SelectionDialog (const LanguageHelper &dictionary, QWidget *par languageMenu_ (new QMenu) { ui->setupUi (this); setWindowFlags (Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint | - Qt::WindowStaysOnTopHint); + Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); ui->label->setAutoFillBackground (false); ui->label->installEventFilter (this); @@ -101,6 +101,7 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) { } QPoint endPos = mouseEvent->pos (); QRect selection = QRect (startSelectPos_, endPos).normalized (); + startSelectPos_ = currentSelectPos_ = QPoint (); QPixmap selectedPixmap = currentPixmap_.copy (selection); if (selectedPixmap.width () < 3 || selectedPixmap.height () < 3) { reject (); @@ -109,6 +110,7 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) { ProcessingItem item; item.source = selectedPixmap; item.screenPos = pos () + selection.topLeft (); + item.modifiers = mouseEvent->modifiers (); if (mouseEvent->button () == Qt::RightButton && !languageMenu_->children ().isEmpty ()) {