From 9a1ceff5d8907d0fde19c3a10d05d782c4784a78 Mon Sep 17 00:00:00 2001 From: Abs62 Date: Wed, 16 Nov 2011 16:52:25 +0400 Subject: [PATCH] 1. Add button to scan popup window to send translated word into main window 2. Add option to use main window instead of scan popup window --- config.cc | 6 ++++++ config.hh | 1 + mainwindow.cc | 9 +++++++++ mainwindow.hh | 1 + preferences.cc | 2 ++ preferences.ui | 10 ++++++++++ scanpopup.cc | 19 +++++++++++++++++++ scanpopup.hh | 3 +++ scanpopup.ui | 17 +++++++++++++++++ 9 files changed, 68 insertions(+) diff --git a/config.cc b/config.cc index 32f4b86c..347bb107 100644 --- a/config.cc +++ b/config.cc @@ -107,6 +107,7 @@ Preferences::Preferences(): scanPopupUseUIAutomation( true ), scanPopupUseIAccessibleEx( true ), scanPopupUseGDMessage( true ), + scanToMainWindow( false ), pronounceOnLoadMain( false ), pronounceOnLoadPopup( false ), #ifdef Q_WS_WIN @@ -602,6 +603,7 @@ Class load() throw( exError ) c.preferences.scanPopupAltMode = ( preferences.namedItem( "scanPopupAltMode" ).toElement().text() == "1" ); if ( !preferences.namedItem( "scanPopupAltModeSecs" ).isNull() ) c.preferences.scanPopupAltModeSecs = preferences.namedItem( "scanPopupAltModeSecs" ).toElement().text().toUInt(); + c.preferences.scanToMainWindow = ( preferences.namedItem( "scanToMainWindow" ).toElement().text() == "1" ); c.preferences.scanPopupUseUIAutomation = ( preferences.namedItem( "scanPopupUseUIAutomation" ).toElement().text() == "1" ); c.preferences.scanPopupUseIAccessibleEx = ( preferences.namedItem( "scanPopupUseIAccessibleEx" ).toElement().text() == "1" ); c.preferences.scanPopupUseGDMessage = ( preferences.namedItem( "scanPopupUseGDMessage" ).toElement().text() == "1" ); @@ -1114,6 +1116,10 @@ void save( Class const & c ) throw( exError ) opt.appendChild( dd.createTextNode( QString::number( c.preferences.scanPopupAltModeSecs ) ) ); preferences.appendChild( opt ); + opt = dd.createElement( "scanToMainWindow" ); + opt.appendChild( dd.createTextNode( c.preferences.scanToMainWindow ? "1":"0" ) ); + preferences.appendChild( opt ); + opt = dd.createElement( "scanPopupUseUIAutomation" ); opt.appendChild( dd.createTextNode( c.preferences.scanPopupUseUIAutomation ? "1":"0" ) ); preferences.appendChild( opt ); diff --git a/config.hh b/config.hh index 5420e48f..e6150a50 100644 --- a/config.hh +++ b/config.hh @@ -162,6 +162,7 @@ struct Preferences bool scanPopupUseUIAutomation; bool scanPopupUseIAccessibleEx; bool scanPopupUseGDMessage; + bool scanToMainWindow; // Whether the word should be pronounced on page load, in main window/popup bool pronounceOnLoadMain, pronounceOnLoadPopup; diff --git a/mainwindow.cc b/mainwindow.cc index 458d64f6..1f093005 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -806,6 +806,8 @@ void MainWindow::makeScanPopup() connect( scanPopup.get(), SIGNAL(editGroupRequested( unsigned )), this,SLOT(editDictionaries( unsigned )), Qt::QueuedConnection ); + connect( scanPopup.get(), SIGNAL(sendWordToMainWindow( QString const & )), + this,SLOT(wordReceived( QString const & )), Qt::QueuedConnection ); } vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts() @@ -2465,3 +2467,10 @@ ArticleView * MainWindow::getCurrentArticleView() } return 0; } + +void MainWindow::wordReceived( const QString & word) +{ + toggleMainWindow( true ); + ui.translateLine->setText( word ); + translateInputFinished(); +} diff --git a/mainwindow.hh b/mainwindow.hh index 30941997..6de0c071 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -46,6 +46,7 @@ public slots: void messageFromAnotherInstanceReceived( QString const & ); void showStatusBarMessage ( QString const &, int, QPixmap const & ); + void wordReceived( QString const & ); private: diff --git a/preferences.cc b/preferences.cc index d7172833..a699ff36 100644 --- a/preferences.cc +++ b/preferences.cc @@ -118,6 +118,7 @@ Preferences::Preferences( QWidget * parent, Config::Preferences const & p ): ui.scanPopupAltMode->setChecked( p.scanPopupAltMode ); ui.scanPopupAltModeSecs->setValue( p.scanPopupAltModeSecs ); + ui.scanToMainWindow->setChecked( p.scanToMainWindow ); ui.scanPopupUseUIAutomation->setChecked( p.scanPopupUseUIAutomation ); ui.scanPopupUseIAccessibleEx->setChecked( p.scanPopupUseIAccessibleEx ); ui.scanPopupUseGDMessage->setChecked( p.scanPopupUseGDMessage ); @@ -232,6 +233,7 @@ Config::Preferences Preferences::getPreferences() p.scanPopupAltMode = ui.scanPopupAltMode->isChecked(); p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value(); + p.scanToMainWindow = ui.scanToMainWindow->isChecked(); p.scanPopupUseUIAutomation = ui.scanPopupUseUIAutomation->isChecked(); p.scanPopupUseIAccessibleEx = ui.scanPopupUseIAccessibleEx->isChecked(); p.scanPopupUseGDMessage = ui.scanPopupUseGDMessage->isChecked(); diff --git a/preferences.ui b/preferences.ui index f6d5d26b..ea322ce8 100644 --- a/preferences.ui +++ b/preferences.ui @@ -545,6 +545,16 @@ seconds, which is specified here. + + + + Send translated word to main window instead of to show it in popup window + + + Send translated word to main window + + + diff --git a/scanpopup.cc b/scanpopup.cc index 038eeb79..35a94bdf 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -296,6 +296,13 @@ void ScanPopup::handleInputWord( QString const & str ) void ScanPopup::engagePopup( bool giveFocus ) { + if( cfg.preferences.scanToMainWindow ) + { + // Send translated word to main window istead of show popup + emit sendWordToMainWindow( inputWord ); + return; + } + /// Too large strings make window expand which is probably not what user /// wants ui.word->setText( elideInputWord() ); @@ -776,3 +783,15 @@ void ScanPopup::mutedDictionariesChanged() if ( dictionaryBar.toggleViewAction()->isChecked() ) definition->updateMutedContents(); } + +void ScanPopup::on_sendWordButton_clicked() +{ + if ( !isVisible() ) + return; + if( !ui.pinButton->isChecked() ) + { + definition->closeSearch(); + hideWindow(); + } + emit sendWordToMainWindow( definition->getTitle() ); +} diff --git a/scanpopup.hh b/scanpopup.hh index 4cf09eaf..5076050a 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -47,6 +47,8 @@ signals: /// Forwarded from the dictionary bar, so that main window could act on this. void editGroupRequested( unsigned id ); + /// Send word to main window + void sendWordToMainWindow( QString const & word ); public slots: @@ -132,6 +134,7 @@ private slots: void pinButtonClicked( bool checked ); void on_showDictionaryBar_clicked( bool checked ); void showStatusBarMessage ( QString const &, int, QPixmap const & ); + void on_sendWordButton_clicked(); void hideTimerExpired(); void altModeExpired(); diff --git a/scanpopup.ui b/scanpopup.ui index 6a445584..948c9b38 100644 --- a/scanpopup.ui +++ b/scanpopup.ui @@ -104,6 +104,23 @@ + + + + Send word to main window (Alt+W) + + + ... + + + + :/icons/programicon.png:/icons/programicon.png + + + Alt+W + + +