Scanpopup fixes, patch by a forum member "dmdmdm".

Some further adjustments were made by me (ikm).
This commit is contained in:
Konstantin Isakov 2009-12-27 15:00:59 +03:00
parent 7a03248aad
commit 1094b44d8b
2 changed files with 48 additions and 63 deletions

View file

@ -29,7 +29,6 @@ ScanPopup::ScanPopup( QWidget * parent,
history( history_ ), history( history_ ),
escapeAction( this ), escapeAction( this ),
wordFinder( this ), wordFinder( this ),
mouseEnteredOnce( false ),
hideTimer( this ) hideTimer( this )
{ {
ui.setupUi( this ); ui.setupUi( this );
@ -49,7 +48,7 @@ ScanPopup::ScanPopup( QWidget * parent,
ui.groupList->fill( groups ); ui.groupList->fill( groups );
ui.groupList->setCurrentGroup( cfg.lastPopupGroupId ); ui.groupList->setCurrentGroup( cfg.lastPopupGroupId );
setWindowFlags( Qt::Popup ); setWindowFlags( Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
if ( cfg.lastPopupSize.isValid() ) if ( cfg.lastPopupSize.isValid() )
resize( cfg.lastPopupSize ); resize( cfg.lastPopupSize );
@ -57,7 +56,7 @@ ScanPopup::ScanPopup( QWidget * parent,
#ifdef Q_OS_WIN32 #ifdef Q_OS_WIN32
// On Windows, leaveEvent() doesn't seem to work with popups and we're trying // On Windows, leaveEvent() doesn't seem to work with popups and we're trying
// to emulate it. // to emulate it.
setMouseTracking( true ); //setMouseTracking( true );
#endif #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.
@ -229,6 +228,10 @@ void ScanPopup::engagePopup()
ui.word->setText( elideInputWord() ); ui.word->setText( elideInputWord() );
if ( !isVisible() ) if ( !isVisible() )
{
// Need to show the window
if ( !ui.pinButton->isChecked() )
{ {
// Decide where should the window land // Decide where should the window land
@ -251,7 +254,7 @@ void ScanPopup::engagePopup()
// Center it // Center it
x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2; x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
/// Try the to-the-buttom placement /// Try the to-the-bottom placement
if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() ) if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() )
y = currentPos.y() + 15; y = currentPos.y() + 15;
else else
@ -263,14 +266,21 @@ void ScanPopup::engagePopup()
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2; y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2;
move( x, y ); move( x, y );
}
show(); show();
mouseEnteredOnce = false; // Windows-only
// This produced some funky mouse grip-related bugs so we commented it out // This produced some funky mouse grip-related bugs so we commented it out
//QApplication::processEvents(); // Make window appear immediately no matter what //QApplication::processEvents(); // Make window appear immediately no matter what
} }
else
if ( ui.pinButton->isChecked() )
{
// Pinned-down window isn't always on top, so we need to raise it
show();
activateWindow();
raise();
}
initiateTranslation(); initiateTranslation();
} }
@ -333,30 +343,7 @@ void ScanPopup::mouseMoveEvent( QMouseEvent * event )
move( pos() + delta ); move( pos() + delta );
} }
#ifdef Q_OS_WIN32
else
if ( !ui.pinButton->isChecked() )
{
if ( !mouseEnteredOnce )
{
// We're waiting for mouse to enter window
if ( geometry().contains( event->globalPos() ) )
{
mouseEnteredOnce = true;
hideTimer.stop();
}
}
else
{
// We're waiting for mouse to leave window
if ( !geometry().contains( event->globalPos() ) )
{
mouseEnteredOnce = false;
hideTimer.start();
}
}
}
#endif
QDialog::mouseMoveEvent( event ); QDialog::mouseMoveEvent( event );
} }
@ -438,7 +425,7 @@ void ScanPopup::on_wordListButton_clicked()
QMenu menu( this ); QMenu menu( this );
unsigned total = results.size() < 20 ? results.size() : 20; unsigned total = results.size() < 40 ? results.size() : 40;
for( unsigned x = 0; x < total; ++x ) for( unsigned x = 0; x < total; ++x )
{ {
@ -474,7 +461,7 @@ void ScanPopup::pinButtonClicked( bool checked )
hideTimer.stop(); hideTimer.stop();
} }
else else
setWindowFlags( Qt::Popup ); setWindowFlags( Qt::Tool | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
show(); show();
} }

View file

@ -64,8 +64,6 @@ private:
QString pendingInputWord, inputWord; QString pendingInputWord, inputWord;
WordFinder wordFinder; WordFinder wordFinder;
bool mouseEnteredOnce;
QPoint startPos; // For window moving QPoint startPos; // For window moving
QTimer hideTimer; // When mouse leaves the window, a grace period is QTimer hideTimer; // When mouse leaves the window, a grace period is