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.
@ -227,50 +226,61 @@ void ScanPopup::engagePopup()
/// Too large strings make window expand which is probably not what user /// Too large strings make window expand which is probably not what user
/// wants /// wants
ui.word->setText( elideInputWord() ); ui.word->setText( elideInputWord() );
if ( !isVisible() ) if ( !isVisible() )
{ {
// Decide where should the window land // Need to show the window
QPoint currentPos = QCursor::pos();
QRect desktop = QApplication::desktop()->screenGeometry(); if ( !ui.pinButton->isChecked() )
{
// Decide where should the window land
QSize windowSize = geometry().size(); QPoint currentPos = QCursor::pos();
int x, y; QRect desktop = QApplication::desktop()->screenGeometry();
/// Try the to-the-right placement QSize windowSize = geometry().size();
if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() )
x = currentPos.x() + 4; int x, y;
else
/// Try the to-the-left placement /// Try the to-the-right placement
if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() ) if ( currentPos.x() + 4 + windowSize.width() <= desktop.topRight().x() )
x = currentPos.x() - 4 - windowSize.width(); x = currentPos.x() + 4;
else else
// Center it /// Try the to-the-left placement
x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2; if ( currentPos.x() - 4 - windowSize.width() >= desktop.x() )
x = currentPos.x() - 4 - windowSize.width();
/// Try the to-the-buttom placement else
if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() ) // Center it
y = currentPos.y() + 15; x = desktop.x() + ( desktop.width() - windowSize.width() ) / 2;
else
/// Try the to-the-top placement /// Try the to-the-bottom placement
if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() ) if ( currentPos.y() + 15 + windowSize.height() <= desktop.bottomLeft().y() )
y = currentPos.y() - 15 - windowSize.height(); y = currentPos.y() + 15;
else else
// Center it /// Try the to-the-top placement
y = desktop.y() + ( desktop.height() - windowSize.height() ) / 2; if ( currentPos.y() - 15 - windowSize.height() >= desktop.y() )
y = currentPos.y() - 15 - windowSize.height();
move( x, y ); 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