* Popup now autohides in Windows normally.

This commit is contained in:
Konstantin Isakov 2009-02-06 13:05:25 +00:00
parent 9789b3892c
commit 2fa0c3b57b
2 changed files with 40 additions and 1 deletions

View file

@ -9,6 +9,7 @@
#include <QPixmap> #include <QPixmap>
#include <QBitmap> #include <QBitmap>
#include <QMenu> #include <QMenu>
#include <QMouseEvent>
using std::wstring; using std::wstring;
@ -21,7 +22,8 @@ ScanPopup::ScanPopup( QWidget * parent,
cfg( cfg_ ), cfg( cfg_ ),
allDictionaries( allDictionaries_ ), allDictionaries( allDictionaries_ ),
groups( groups_ ), groups( groups_ ),
wordFinder( this ) wordFinder( this ),
mouseEnteredOnce( false )
{ {
ui.setupUi( this ); ui.setupUi( this );
definition = new ArticleView( ui.outerFrame, articleNetMgr, groups, true ), definition = new ArticleView( ui.outerFrame, articleNetMgr, groups, true ),
@ -33,6 +35,12 @@ ScanPopup::ScanPopup( QWidget * parent,
ui.groupList->fill( groups ); ui.groupList->fill( groups );
setWindowFlags( Qt::Popup ); 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. #if 0 // Experimental code to give window a non-rectangular shape (i.e.
// balloon) using a colorkey mask. // balloon) using a colorkey mask.
QPixmap pixMask( size() ); QPixmap pixMask( size() );
@ -109,6 +117,8 @@ void ScanPopup::handleInputWord( QString const & str )
show(); show();
mouseEnteredOnce = false; // Windows-only
QApplication::processEvents(); // Make window appear immediately no matter what QApplication::processEvents(); // Make window appear immediately no matter what
} }
@ -141,6 +151,32 @@ vector< sptr< Dictionary::Class > > const & ScanPopup::getActiveDicts()
groups[ currentGroup ].dictionaries; 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 ) void ScanPopup::leaveEvent( QEvent * event )
{ {
QDialog::leaveEvent( event ); QDialog::leaveEvent( event );

View file

@ -39,11 +39,14 @@ private:
vector< QString > diacriticMatches, prefixMatches; vector< QString > diacriticMatches, prefixMatches;
bool mouseEnteredOnce;
void handleInputWord( QString const & ); void handleInputWord( QString const & );
void initiateTranslation(); void initiateTranslation();
vector< sptr< Dictionary::Class > > const & getActiveDicts(); vector< sptr< Dictionary::Class > > const & getActiveDicts();
virtual void mouseMoveEvent( QMouseEvent * event );
virtual void leaveEvent( QEvent * event ); virtual void leaveEvent( QEvent * event );
void popupWordlist( vector< QString > const &, QToolButton * button ); void popupWordlist( vector< QString > const &, QToolButton * button );