Added base support of multi-screen systems.
This commit is contained in:
parent
d46eb9c5bd
commit
256e812401
34
Manager.cpp
34
Manager.cpp
@ -5,6 +5,7 @@
|
|||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <QDesktopWidget>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
@ -24,7 +25,6 @@ Manager::Manager (QObject *parent) :
|
|||||||
QObject (parent),
|
QObject (parent),
|
||||||
trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)),
|
trayIcon_ (new QSystemTrayIcon (QIcon (":/images/icon.png"), this)),
|
||||||
dictionary_ (new LanguageHelper),
|
dictionary_ (new LanguageHelper),
|
||||||
selection_ (new SelectionDialog (*dictionary_)),
|
|
||||||
resultDialog_ (new ResultDialog),
|
resultDialog_ (new ResultDialog),
|
||||||
captureAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL),
|
captureAction_ (NULL), repeatAction_ (NULL), clipboardAction_ (NULL),
|
||||||
useResultDialog_ (true) {
|
useResultDialog_ (true) {
|
||||||
@ -33,7 +33,7 @@ Manager::Manager (QObject *parent) :
|
|||||||
|
|
||||||
// Recognizer
|
// Recognizer
|
||||||
Recognizer *recognizer = new Recognizer;
|
Recognizer *recognizer = new Recognizer;
|
||||||
connect (selection_, SIGNAL (selected (ProcessingItem)),
|
connect (this, SIGNAL (selected (ProcessingItem)),
|
||||||
recognizer, SLOT (recognize (ProcessingItem)));
|
recognizer, SLOT (recognize (ProcessingItem)));
|
||||||
connect (recognizer, SIGNAL (error (QString)),
|
connect (recognizer, SIGNAL (error (QString)),
|
||||||
SLOT (showError (QString)));
|
SLOT (showError (QString)));
|
||||||
@ -61,12 +61,7 @@ Manager::Manager (QObject *parent) :
|
|||||||
connect (translator, SIGNAL (translated (ProcessingItem)),
|
connect (translator, SIGNAL (translated (ProcessingItem)),
|
||||||
SLOT (showResult (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 ()));
|
connect (this, SIGNAL (settingsEdited ()), this, SLOT (applySettings ()));
|
||||||
selection_->setWindowIcon (trayIcon_->icon ());
|
|
||||||
resultDialog_->setWindowIcon (trayIcon_->icon ());
|
resultDialog_->setWindowIcon (trayIcon_->icon ());
|
||||||
|
|
||||||
|
|
||||||
@ -136,13 +131,24 @@ Manager::~Manager () {
|
|||||||
|
|
||||||
void Manager::capture () {
|
void Manager::capture () {
|
||||||
QList<QScreen *> screens = QApplication::screens ();
|
QList<QScreen *> screens = QApplication::screens ();
|
||||||
ST_ASSERT (!screens.isEmpty ());
|
foreach (QScreen * screen, screens) {
|
||||||
QScreen *screen = screens.first ();
|
QRect geometry = screen->availableGeometry ();
|
||||||
Q_CHECK_PTR (screen);
|
QPixmap pixmap = screen->grabWindow (0, geometry.x (), geometry.y (),
|
||||||
WId desktopId = QApplication::desktop ()->winId ();
|
geometry.width (), geometry.height ());
|
||||||
QPixmap pixmap = screen->grabWindow (desktopId);
|
QString name = screen->name ();
|
||||||
ST_ASSERT (!pixmap.isNull ());
|
if (!selections_.contains (name)) {
|
||||||
emit showPixmap (pixmap);
|
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 () {
|
void Manager::settings () {
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
|
#include <QMap>
|
||||||
|
|
||||||
#include "ProcessingItem.h"
|
#include "ProcessingItem.h"
|
||||||
|
|
||||||
@ -21,7 +22,8 @@ class Manager : public QObject {
|
|||||||
~Manager ();
|
~Manager ();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void showPixmap (QPixmap pixmap);
|
void selected (ProcessingItem item);
|
||||||
|
void closeSelections ();
|
||||||
void settingsEdited ();
|
void settingsEdited ();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
@ -46,7 +48,8 @@ class Manager : public QObject {
|
|||||||
private:
|
private:
|
||||||
QSystemTrayIcon *trayIcon_;
|
QSystemTrayIcon *trayIcon_;
|
||||||
LanguageHelper *dictionary_;
|
LanguageHelper *dictionary_;
|
||||||
SelectionDialog *selection_;
|
//! Selection dialogs for each screen. Key - screen name.
|
||||||
|
QMap<QString, SelectionDialog *> selections_;
|
||||||
ResultDialog *resultDialog_;
|
ResultDialog *resultDialog_;
|
||||||
QAction *captureAction_;
|
QAction *captureAction_;
|
||||||
QAction *repeatAction_;
|
QAction *repeatAction_;
|
||||||
|
@ -120,20 +120,20 @@ bool SelectionDialog::eventFilter (QObject *object, QEvent *event) {
|
|||||||
ST_ASSERT (!item.sourceLanguage.isEmpty ());
|
ST_ASSERT (!item.sourceLanguage.isEmpty ());
|
||||||
}
|
}
|
||||||
emit selected (item);
|
emit selected (item);
|
||||||
accept ();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return QDialog::eventFilter (object, event);
|
return QDialog::eventFilter (object, event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SelectionDialog::setPixmap (QPixmap pixmap) {
|
void SelectionDialog::setPixmap (QPixmap pixmap, const QRect &showGeometry) {
|
||||||
ST_ASSERT (!pixmap.isNull ());
|
ST_ASSERT (!pixmap.isNull ());
|
||||||
|
ST_ASSERT (!showGeometry.isEmpty ());
|
||||||
currentPixmap_ = pixmap;
|
currentPixmap_ = pixmap;
|
||||||
QPalette palette = this->palette ();
|
QPalette palette = this->palette ();
|
||||||
palette.setBrush (this->backgroundRole (), pixmap);
|
palette.setBrush (this->backgroundRole (), pixmap);
|
||||||
this->setPalette (palette);
|
this->setPalette (palette);
|
||||||
this->resize (pixmap.size ());
|
this->setGeometry (showGeometry);
|
||||||
|
|
||||||
show ();
|
show ();
|
||||||
setFocus ();
|
setFocus ();
|
||||||
|
@ -23,9 +23,11 @@ class SelectionDialog : public QDialog {
|
|||||||
|
|
||||||
signals:
|
signals:
|
||||||
void selected (ProcessingItem pixmap);
|
void selected (ProcessingItem pixmap);
|
||||||
|
void nothingSelected ();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPixmap (QPixmap pixmap);
|
//! Show pixmap with given geometry.
|
||||||
|
void setPixmap (QPixmap pixmap, const QRect &showGeometry);
|
||||||
void updateMenu ();
|
void updateMenu ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
Reference in New Issue
Block a user