mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
* Popup now autohides in Windows normally.
This commit is contained in:
parent
9789b3892c
commit
2fa0c3b57b
|
@ -9,6 +9,7 @@
|
|||
#include <QPixmap>
|
||||
#include <QBitmap>
|
||||
#include <QMenu>
|
||||
#include <QMouseEvent>
|
||||
|
||||
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 );
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue