diff --git a/Manager.cpp b/Manager.cpp index fd6656e..3932fc1 100644 --- a/Manager.cpp +++ b/Manager.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -24,7 +25,6 @@ Manager::Manager (QObject *parent) : QObject (parent), trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)), dictionary_ (new LanguageHelper), - selection_ (new SelectionDialog (*dictionary_)), resultDialog_ (new ResultDialog), captureAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL), useResultDialog_ (true) { @@ -33,7 +33,7 @@ Manager::Manager (QObject *parent) : // Recognizer Recognizer *recognizer = new Recognizer; - connect (selection_, SIGNAL (selected (ProcessingItem)), + connect (this, SIGNAL (selected (ProcessingItem)), recognizer, SLOT (recognize (ProcessingItem))); connect (recognizer, SIGNAL (error (QString)), SLOT (showError (QString))); @@ -61,12 +61,7 @@ Manager::Manager (QObject *parent) : connect (translator, SIGNAL (translated (ProcessingItem)), SLOT (showResult (ProcessingItem))); - connect (this, SIGNAL (showPixmap (QPixmap)), - selection_, SLOT (setPixmap (QPixmap))); - - connect (this, SIGNAL (settingsEdited ()), selection_, SLOT (updateMenu ())); connect (this, SIGNAL (settingsEdited ()), this, SLOT (applySettings ())); - selection_->setWindowIcon (trayIcon_->icon ()); resultDialog_->setWindowIcon (trayIcon_->icon ()); @@ -136,13 +131,24 @@ Manager::~Manager () { void Manager::capture () { QList screens = QApplication::screens (); - ST_ASSERT (!screens.isEmpty ()); - QScreen *screen = screens.first (); - Q_CHECK_PTR (screen); - WId desktopId = QApplication::desktop ()->winId (); - QPixmap pixmap = screen->grabWindow (desktopId); - ST_ASSERT (!pixmap.isNull ()); - emit showPixmap (pixmap); + foreach (QScreen * screen, screens) { + QRect geometry = screen->availableGeometry (); + QPixmap pixmap = screen->grabWindow (0, geometry.x (), geometry.y (), + geometry.width (), geometry.height ()); + QString name = screen->name (); + if (!selections_.contains (name)) { + SelectionDialog *selection = new SelectionDialog (*dictionary_); + 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 (rejected ()), SIGNAL (closeSelections ())); + selections_[name] = selection; + } + SelectionDialog *selection = selections_[name]; + selection->setPixmap (pixmap, geometry); + } } void Manager::settings () { diff --git a/Manager.h b/Manager.h index 4f4eba0..d105e69 100644 --- a/Manager.h +++ b/Manager.h @@ -3,6 +3,7 @@ #include #include +#include #include "ProcessingItem.h" @@ -21,7 +22,8 @@ class Manager : public QObject { ~Manager (); signals: - void showPixmap (QPixmap pixmap); + void selected (ProcessingItem item); + void closeSelections (); void settingsEdited (); private slots: @@ -46,7 +48,8 @@ class Manager : public QObject { private: QSystemTrayIcon *trayIcon_; LanguageHelper *dictionary_; - SelectionDialog *selection_; + //! Selection dialogs for each screen. Key - screen name. + QMap selections_; ResultDialog *resultDialog_; QAction *captureAction_; QAction *repeatAction_; diff --git a/SelectionDialog.cpp b/SelectionDialog.cpp index 58b7e81..4705bf2 100644 --- a/SelectionDialog.cpp +++ b/SelectionDialog.cpp @@ -120,20 +120,20 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) { ST_ASSERT (!item.sourceLanguage.isEmpty ()); } emit selected (item); - accept (); } } } return QDialog::eventFilter (object, event); } -void SelectionDialog::setPixmap (QPixmap pixmap) { +void SelectionDialog::setPixmap (QPixmap pixmap, const QRect &showGeometry) { ST_ASSERT (!pixmap.isNull ()); + ST_ASSERT (!showGeometry.isEmpty ()); currentPixmap_ = pixmap; QPalette palette = this->palette (); palette.setBrush (this->backgroundRole (), pixmap); this->setPalette (palette); - this->resize (pixmap.size ()); + this->setGeometry (showGeometry); show (); setFocus (); diff --git a/SelectionDialog.h b/SelectionDialog.h index 178ff2d..1d3c814 100644 --- a/SelectionDialog.h +++ b/SelectionDialog.h @@ -23,9 +23,11 @@ class SelectionDialog : public QDialog { signals: void selected (ProcessingItem pixmap); + void nothingSelected (); public slots: - void setPixmap (QPixmap pixmap); + //! Show pixmap with given geometry. + void setPixmap (QPixmap pixmap, const QRect &showGeometry); void updateMenu (); private: