From 2fa0c3b57b07945abc801b0501b3c2f52c3bd89c Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Fri, 6 Feb 2009 13:05:25 +0000 Subject: [PATCH] * Popup now autohides in Windows normally. --- src/scanpopup.cc | 38 +++++++++++++++++++++++++++++++++++++- src/scanpopup.hh | 3 +++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/scanpopup.cc b/src/scanpopup.cc index be3bcf5d..bcfb3260 100644 --- a/src/scanpopup.cc +++ b/src/scanpopup.cc @@ -9,6 +9,7 @@ #include #include #include +#include using std::wstring; @@ -21,7 +22,8 @@ ScanPopup::ScanPopup( QWidget * parent, cfg( cfg_ ), allDictionaries( allDictionaries_ ), groups( groups_ ), - wordFinder( this ) + wordFinder( this ), + mouseEnteredOnce( false ) { ui.setupUi( this ); definition = new ArticleView( ui.outerFrame, articleNetMgr, groups, true ), @@ -33,6 +35,12 @@ ScanPopup::ScanPopup( QWidget * parent, ui.groupList->fill( groups ); setWindowFlags( Qt::Popup ); + #ifdef Q_OS_WIN32 + // On Windows, leaveEvent() doesn't seem to work with popups and we're trying + // to emulate it. + setMouseTracking( true ); + #endif + #if 0 // Experimental code to give window a non-rectangular shape (i.e. // balloon) using a colorkey mask. QPixmap pixMask( size() ); @@ -109,6 +117,8 @@ void ScanPopup::handleInputWord( QString const & str ) show(); + mouseEnteredOnce = false; // Windows-only + QApplication::processEvents(); // Make window appear immediately no matter what } @@ -141,6 +151,32 @@ vector< sptr< Dictionary::Class > > const & ScanPopup::getActiveDicts() groups[ currentGroup ].dictionaries; } +void ScanPopup::mouseMoveEvent( QMouseEvent * event ) +{ + #ifdef Q_OS_WIN32 + if ( !ui.pinButton->isChecked() ) + { + if ( !mouseEnteredOnce ) + { + // We're waiting for mouse to enter window + if ( geometry().contains( event->globalPos() ) ) + mouseEnteredOnce = true; + } + else + { + // We're waiting for mouse to leave window + if ( !geometry().contains( event->globalPos() ) ) + { + mouseEnteredOnce = false; + hide(); + } + } + } + #endif + + QDialog::mouseMoveEvent( event ); +} + void ScanPopup::leaveEvent( QEvent * event ) { QDialog::leaveEvent( event ); diff --git a/src/scanpopup.hh b/src/scanpopup.hh index 007141db..ddb4ee3c 100644 --- a/src/scanpopup.hh +++ b/src/scanpopup.hh @@ -39,11 +39,14 @@ private: vector< QString > diacriticMatches, prefixMatches; + bool mouseEnteredOnce; + void handleInputWord( QString const & ); void initiateTranslation(); vector< sptr< Dictionary::Class > > const & getActiveDicts(); + virtual void mouseMoveEvent( QMouseEvent * event ); virtual void leaveEvent( QEvent * event ); void popupWordlist( vector< QString > const &, QToolButton * button );