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.
@ -230,47 +229,58 @@ void ScanPopup::engagePopup()
if ( !isVisible() ) if ( !isVisible() )
{ {
// Decide where should the window land // Need to show the window
QPoint currentPos = QCursor::pos(); if ( !ui.pinButton->isChecked() )
{
// Decide where should the window land
QRect desktop = QApplication::desktop()->screenGeometry(); QPoint currentPos = QCursor::pos();
QSize windowSize = geometry().size(); QRect desktop = QApplication::desktop()->screenGeometry();
int x, y; QSize windowSize = geometry().size();
/// Try the to-the-right placement int x, y;
if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() )
x = currentPos.x() + 4;
else
/// Try the to-the-left placement
if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() )
x = currentPos.x() - 4 - windowSize.width();
else
// Center it
x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
/// Try the to-the-buttom placement /// Try the to-the-right placement
if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() ) if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() )
y = currentPos.y() + 15; x = currentPos.x() + 4;
else else
/// Try the to-the-top placement /// Try the to-the-left placement
if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() ) if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() )
y = currentPos.y() - 15 - windowSize.height(); x = currentPos.x() - 4 - windowSize.width();
else else
// Center it // Center it
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2; x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
move( x, y ); /// Try the to-the-bottom placement
if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() )
y = currentPos.y() + 15;
else
/// Try the to-the-top placement
if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() )
y = currentPos.y() - 15 - windowSize.height();
else
// Center it
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2;
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