mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
Use polling instead of mouse grab for scan popup. This should fix problems with Windows 7 and such.
This commit is contained in:
parent
1624afafc4
commit
621d842394
103
scanpopup.cc
103
scanpopup.cc
|
@ -136,6 +136,11 @@ ScanPopup::ScanPopup( QWidget * parent,
|
|||
altModePollingTimer.setInterval( 50 );
|
||||
connect( &altModePollingTimer, SIGNAL( timeout() ),
|
||||
this, SLOT( altModePoll() ) );
|
||||
|
||||
mouseGrabPollTimer.setSingleShot( false );
|
||||
mouseGrabPollTimer.setInterval( 10 );
|
||||
connect( &mouseGrabPollTimer, SIGNAL( timeout() ),
|
||||
this, SLOT(mouseGrabPoll()) );
|
||||
}
|
||||
|
||||
ScanPopup::~ScanPopup()
|
||||
|
@ -407,52 +412,55 @@ bool ScanPopup::eventFilter( QObject * watched, QEvent * event )
|
|||
|
||||
if ( event->type() == QEvent::MouseMove )
|
||||
{
|
||||
// printf( "Object: %s\n", watched->objectName().toUtf8().data() );
|
||||
QMouseEvent * mouseEvent = ( QMouseEvent * ) event;
|
||||
|
||||
// printf( "Object: %s\n", watched->objectName().toUtf8().data() );
|
||||
|
||||
if ( geometry().contains( mouseEvent->globalPos() ) )
|
||||
{
|
||||
// printf( "got inside\n" );
|
||||
|
||||
hideTimer.stop();
|
||||
mouseEnteredOnce = true;
|
||||
uninterceptMouse();
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf( "outside\n" );
|
||||
// We're in grab mode and outside the window - calculate the
|
||||
// distance from it. We might want to hide it.
|
||||
|
||||
// When the mouse has entered once, we don't allow it stayng outside,
|
||||
// but we give a grace period for it to return.
|
||||
int proximity = mouseEnteredOnce ? 0 : 60;
|
||||
|
||||
// Note: watched == this ensures no other child objects popping out are
|
||||
// receiving this event, meaning there's basically nothing under the
|
||||
// cursor.
|
||||
if ( watched == this &&
|
||||
!frameGeometry().adjusted( -proximity, -proximity, proximity, proximity ).
|
||||
contains( mouseEvent->globalPos() ) )
|
||||
{
|
||||
// We've way too far from the window -- hide the popup
|
||||
|
||||
// If the mouse never entered the popup, hide the window instantly --
|
||||
// the user just moved the cursor further away from the window.
|
||||
|
||||
if ( !mouseEnteredOnce )
|
||||
hideWindow();
|
||||
else
|
||||
hideTimer.start();
|
||||
}
|
||||
}
|
||||
reactOnMouseMove( mouseEvent->globalPos() );
|
||||
}
|
||||
}
|
||||
|
||||
return QMainWindow::eventFilter( watched, event );
|
||||
}
|
||||
|
||||
void ScanPopup::reactOnMouseMove( QPoint const & p )
|
||||
{
|
||||
if ( geometry().contains( p ) )
|
||||
{
|
||||
// printf( "got inside\n" );
|
||||
|
||||
hideTimer.stop();
|
||||
mouseEnteredOnce = true;
|
||||
uninterceptMouse();
|
||||
}
|
||||
else
|
||||
{
|
||||
// printf( "outside\n" );
|
||||
// We're in grab mode and outside the window - calculate the
|
||||
// distance from it. We might want to hide it.
|
||||
|
||||
// When the mouse has entered once, we don't allow it stayng outside,
|
||||
// but we give a grace period for it to return.
|
||||
int proximity = mouseEnteredOnce ? 0 : 60;
|
||||
|
||||
// Note: watched == this ensures no other child objects popping out are
|
||||
// receiving this event, meaning there's basically nothing under the
|
||||
// cursor.
|
||||
if ( /*watched == this &&*/
|
||||
!frameGeometry().adjusted( -proximity, -proximity, proximity, proximity ).
|
||||
contains( p ) )
|
||||
{
|
||||
// We've way too far from the window -- hide the popup
|
||||
|
||||
// If the mouse never entered the popup, hide the window instantly --
|
||||
// the user just moved the cursor further away from the window.
|
||||
|
||||
if ( !mouseEnteredOnce )
|
||||
hideWindow();
|
||||
else
|
||||
hideTimer.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScanPopup::mousePressEvent( QMouseEvent * ev )
|
||||
{
|
||||
// With mouse grabs, the press can occur anywhere on the screen, which
|
||||
|
@ -687,19 +695,32 @@ void ScanPopup::interceptMouse()
|
|||
{
|
||||
if ( !mouseIntercepted )
|
||||
{
|
||||
grabMouse();
|
||||
// We used to grab the mouse -- but this doesn't always work reliably
|
||||
// (e.g. doesn't work at all in Windows 7 for some reason). Therefore
|
||||
// we use a polling timer now.
|
||||
|
||||
// grabMouse();
|
||||
mouseGrabPollTimer.start();
|
||||
|
||||
qApp->installEventFilter( this );
|
||||
|
||||
mouseIntercepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
void ScanPopup::mouseGrabPoll()
|
||||
{
|
||||
if ( mouseIntercepted )
|
||||
reactOnMouseMove( QCursor::pos() );
|
||||
}
|
||||
|
||||
void ScanPopup::uninterceptMouse()
|
||||
{
|
||||
if ( mouseIntercepted )
|
||||
{
|
||||
qApp->removeEventFilter( this );
|
||||
releaseMouse();
|
||||
mouseGrabPollTimer.stop();
|
||||
// releaseMouse();
|
||||
|
||||
mouseIntercepted = false;
|
||||
}
|
||||
|
|
13
scanpopup.hh
13
scanpopup.hh
|
@ -95,6 +95,8 @@ private:
|
|||
// this timer expires, the window gets hidden.
|
||||
QTimer altModeExpirationTimer, altModePollingTimer; // Timers for alt mode
|
||||
|
||||
QTimer mouseGrabPollTimer;
|
||||
|
||||
void handleInputWord( QString const & );
|
||||
void engagePopup( bool giveFocus = false );
|
||||
void initiateTranslation();
|
||||
|
@ -102,6 +104,11 @@ private:
|
|||
vector< sptr< Dictionary::Class > > const & getActiveDicts();
|
||||
|
||||
virtual bool eventFilter( QObject * watched, QEvent * event );
|
||||
|
||||
/// Called from event filter or from mouseGrabPoll to handle mouse event
|
||||
/// while it is being intercepted.
|
||||
void reactOnMouseMove( QPoint const & p );
|
||||
|
||||
virtual void mousePressEvent( QMouseEvent * );
|
||||
virtual void mouseMoveEvent( QMouseEvent * );
|
||||
virtual void mouseReleaseEvent( QMouseEvent * );
|
||||
|
@ -127,6 +134,12 @@ private slots:
|
|||
void altModeExpired();
|
||||
void altModePoll();
|
||||
|
||||
/// Called repeatedly once the popup is initially engaged and we monitor the
|
||||
/// mouse as it may move away from the window. This simulates mouse grab, in
|
||||
/// essense, but seems more reliable. Once the mouse enters the window, the
|
||||
/// polling stops.
|
||||
void mouseGrabPoll();
|
||||
|
||||
void pageLoaded( ArticleView * );
|
||||
|
||||
void escapePressed();
|
||||
|
|
Loading…
Reference in a new issue