diff --git a/mainwindow.cc b/mainwindow.cc index f4199187..4f0bbe43 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -874,6 +874,11 @@ void MainWindow::makeScanPopup() connect( scanPopup.get(), SIGNAL( forceAddWordToHistory( const QString & ) ), this, SLOT( forceAddWordToHistory( const QString & ) ) ); + +#ifdef Q_OS_WIN32 + connect( scanPopup.get(), SIGNAL( isGoldenDictWindow( HWND ) ), + this, SLOT( isGoldenDictWindow( HWND ) ) ); +#endif } vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts() @@ -3027,4 +3032,9 @@ bool MainWindow::winEvent( MSG * message, long * result ) return true; } +bool MainWindow::isGoldenDictWindow( HWND hwnd ) +{ + return hwnd == (HWND)winId(); +} + #endif diff --git a/mainwindow.hh b/mainwindow.hh index 8b2fcf23..b93b90a9 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -356,6 +356,10 @@ signals: protected: unsigned gdAskMessage; bool winEvent( MSG * message, long * result ); + +private slots: + /// Return true while scanning GoldenDict window + bool isGoldenDictWindow( HWND hwnd ); #endif }; diff --git a/mouseover.cc b/mouseover.cc index cf2362ab..539f4d8c 100644 --- a/mouseover.cc +++ b/mouseover.cc @@ -201,6 +201,8 @@ LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd, UINT msg, int wordSeqPos = 0; QString wordSeq; + HWND hwnd = GlobalData->LastWND; + if( GlobalData->CurMod.WordLen == 0) { if( ( res & GD_FLAG_METHOD_UI_AUTOMATION ) == 0 ) @@ -317,7 +319,9 @@ LRESULT CALLBACK MouseOver::eventHandler( HWND hwnd, UINT msg, } } - emit instance().hovered( word ); + bool forcePopup = false; + forcePopup = emit instance().isGoldenDictWindow( hwnd ); + emit instance().hovered( word, forcePopup ); return 0; } diff --git a/mouseover.hh b/mouseover.hh index 9b0d6acb..995b47c9 100644 --- a/mouseover.hh +++ b/mouseover.hh @@ -37,7 +37,12 @@ public: signals: /// Emitted when there was some text under cursor which was hovered over. - void hovered( QString const & ); + void hovered( QString const &, bool forcePopup ); + +#ifdef Q_OS_WIN32 + /// Ask for source window is GoldenDict window + bool isGoldenDictWindow( HWND hwnd ); +#endif private: diff --git a/scanpopup.cc b/scanpopup.cc index c7e1d53d..575b7587 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -152,8 +152,13 @@ ScanPopup::ScanPopup( QWidget * parent, connect( QApplication::clipboard(), SIGNAL( changed( QClipboard::Mode ) ), this, SLOT( clipboardChanged( QClipboard::Mode ) ) ); - connect( &MouseOver::instance(), SIGNAL( hovered( QString const & ) ), - this, SLOT( mouseHovered( QString const & ) ) ); + connect( &MouseOver::instance(), SIGNAL( hovered( QString const &, bool ) ), + this, SLOT( mouseHovered( QString const &, bool ) ) ); + +#ifdef Q_OS_WIN32 + connect( &MouseOver::instance(), SIGNAL( isGoldenDictWindow( HWND ) ), + this, SIGNAL( isGoldenDictWindow( HWND ) ) ); +#endif hideTimer.setSingleShot( true ); hideTimer.setInterval( 400 ); @@ -252,10 +257,12 @@ void ScanPopup::translateWord( QString const & word ) altModeExpirationTimer.stop(); inputWord = str; - engagePopup( + engagePopup( false, #ifdef Q_WS_WIN true // We only focus popup under Windows when activated via Ctrl+C+C // -- on Linux it already has an implicit focus +#else + false #endif ); } @@ -272,12 +279,12 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m ) handleInputWord( QApplication::clipboard()->text( subtype, m ) ); } -void ScanPopup::mouseHovered( QString const & str ) +void ScanPopup::mouseHovered( QString const & str, bool forcePopup ) { - handleInputWord( str ); + handleInputWord( str, forcePopup ); } -void ScanPopup::handleInputWord( QString const & str ) +void ScanPopup::handleInputWord( QString const & str, bool forcePopup ) { QString sanitizedStr = gd::toQString( Folding::trimWhitespaceOrPunct( gd::toWString( str ) ) ); @@ -316,12 +323,12 @@ void ScanPopup::handleInputWord( QString const & str ) } inputWord = pendingInputWord; - engagePopup(); + engagePopup( forcePopup ); } -void ScanPopup::engagePopup( bool giveFocus ) +void ScanPopup::engagePopup( bool forcePopup, bool giveFocus ) { - if( cfg.preferences.scanToMainWindow ) + if( cfg.preferences.scanToMainWindow && !forcePopup ) { // Send translated word to main window istead of show popup emit sendWordToMainWindow( inputWord ); @@ -726,7 +733,7 @@ void ScanPopup::altModePoll() altModeExpirationTimer.stop(); inputWord = pendingInputWord; - engagePopup(); + engagePopup( false ); } } diff --git a/scanpopup.hh b/scanpopup.hh index 62954975..5b0f7586 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -61,6 +61,11 @@ signals: /// Signal to add word to history even if history is disabled void forceAddWordToHistory( const QString & word); +#ifdef Q_OS_WIN32 + /// Ask for source window is current translate tab + bool isGoldenDictWindow( HWND hwnd ); +#endif + public slots: /// Translates the word from the clipboard, showing the window etc. @@ -112,8 +117,8 @@ private: QTimer mouseGrabPollTimer; - void handleInputWord( QString const & ); - void engagePopup( bool giveFocus = false ); + void handleInputWord( QString const & , bool forcePopup = false ); + void engagePopup( bool forcePopup, bool giveFocus = false ); void initiateTranslation(); vector< sptr< Dictionary::Class > > const & getActiveDicts(); @@ -137,7 +142,7 @@ private: private slots: void clipboardChanged( QClipboard::Mode ); - void mouseHovered( QString const & ); + void mouseHovered( QString const & , bool forcePopup); void currentGroupChanged( QString const & ); void prefixMatchFinished(); void on_wordListButton_clicked();