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 <QDesktopWidget>
 | 
			
		||||
#include <QScreen>
 | 
			
		||||
#include <QDesktopWidget>
 | 
			
		||||
#include <QThread>
 | 
			
		||||
#include <QSettings>
 | 
			
		||||
#include <QClipboard>
 | 
			
		||||
@ -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<QScreen *> 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 () {
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include <QPixmap>
 | 
			
		||||
#include <QSystemTrayIcon>
 | 
			
		||||
#include <QMap>
 | 
			
		||||
 | 
			
		||||
#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<QString, SelectionDialog *> selections_;
 | 
			
		||||
    ResultDialog *resultDialog_;
 | 
			
		||||
    QAction *captureAction_;
 | 
			
		||||
    QAction *repeatAction_;
 | 
			
		||||
 | 
			
		||||
@ -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 ();
 | 
			
		||||
 | 
			
		||||
@ -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:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user