From 64867e9f1b9adedc40ecb5c5bebd39b78cce4cfb Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Fri, 31 Jul 2009 11:40:54 +0000 Subject: [PATCH] The following patches made by Dmitry E. Oboukhov applied: * Middle click on the tray icon translates current selection * Middle click on the main window also translates current selection * When editing groups, double click on the dictionary adds it to the current group. --- src/groups.cc | 2 ++ src/mainwindow.cc | 38 +++++++++++++++++++++++++++++++++----- src/mainwindow.hh | 2 ++ src/scanpopup.cc | 15 ++++++++++++--- src/scanpopup.hh | 5 +++++ 5 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/groups.cc b/src/groups.cc index 3f74bc40..16467a7b 100644 --- a/src/groups.cc +++ b/src/groups.cc @@ -36,6 +36,8 @@ Groups::Groups( QWidget * parent, this, SLOT( removeAll() ) ); connect( ui.addDictsToGroup, SIGNAL( clicked() ), this, SLOT( addToGroup() ) ); + connect( ui.dictionaries, SIGNAL( doubleClicked(const QModelIndex &) ), + this, SLOT( addToGroup() ) ); connect( ui.removeDictsFromGroup, SIGNAL( clicked() ), this, SLOT( removeFromGroup() ) ); diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 62852520..9aaad4b0 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -274,6 +274,22 @@ MainWindow::MainWindow( Config::Class & cfg_ ): doDeferredInit( dictionaries ); } +void MainWindow::mousePressEvent( QMouseEvent *event) +{ + if (event->button() != Qt::MidButton) + return QMainWindow::mousePressEvent(event); + // middle clicked + QString subtype = "plain"; + + QString str = QApplication::clipboard()->text(subtype, + QClipboard::Selection); + ui.translateLine->setText(str); + + QKeyEvent ev(QEvent::Type(6)/*QEvent::KeyPress*/, Qt::Key_Enter, + Qt::NoModifier); + QApplication::sendEvent(ui.translateLine, &ev); +} + MainWindow::~MainWindow() { // Save MainWindow state and geometry @@ -1273,11 +1289,23 @@ void MainWindow::latestReleaseReplyReady() void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r ) { - if ( r == QSystemTrayIcon::Trigger ) - { - // Left click toggles the visibility of main window - toggleMainWindow(); - } + switch(r) { + case QSystemTrayIcon::Trigger: + // Left click toggles the visibility of main window + toggleMainWindow(); + break; + + case QSystemTrayIcon::MiddleClick: + // Middle mouse click on Tray translates selection + // it is functional like as stardict + if ( scanPopup.get() ) { + scanPopup->translateWordFromSelection(); + } + break; + default: + break; + + } } void MainWindow::scanEnableToggled( bool on ) diff --git a/src/mainwindow.hh b/src/mainwindow.hh index cbc7d845..c4fddf2f 100644 --- a/src/mainwindow.hh +++ b/src/mainwindow.hh @@ -108,6 +108,8 @@ private: void applyZoomFactor(); + void mousePressEvent ( QMouseEvent * event ); + private slots: void hotKeyActivated( int ); diff --git a/src/scanpopup.cc b/src/scanpopup.cc index 3a226027..5f8d5d47 100644 --- a/src/scanpopup.cc +++ b/src/scanpopup.cc @@ -141,12 +141,21 @@ void ScanPopup::applyZoomFactor() void ScanPopup::translateWordFromClipboard() { - printf( "translating from clipboard\n" ); + return translateWordFromClipboard(QClipboard::Clipboard); +} + +void ScanPopup::translateWordFromSelection() +{ + return translateWordFromClipboard(QClipboard::Selection); +} + +void ScanPopup::translateWordFromClipboard(QClipboard::Mode m) +{ + printf( "translating from clipboard or selection\n" ); QString subtype = "plain"; - QString str = QApplication::clipboard()->text( subtype, - QClipboard::Clipboard ); + QString str = QApplication::clipboard()->text( subtype, m); str = pendingInputWord = gd::toQString( Folding::trimWhitespaceOrPunct( gd::toWString( str ) ) ); diff --git a/src/scanpopup.hh b/src/scanpopup.hh index d2bf1e18..0fc6bb18 100644 --- a/src/scanpopup.hh +++ b/src/scanpopup.hh @@ -43,9 +43,14 @@ public slots: /// Translates the word from the clipboard, showing the window etc. void translateWordFromClipboard(); + /// Translates the word from the clipboard selection + void translateWordFromSelection(); private: + // Translates the word from the clipboard or the clipboard selection + void translateWordFromClipboard(QClipboard::Mode m); + Config::Class & cfg; bool isScanningEnabled; std::vector< sptr< Dictionary::Class > > const & allDictionaries;