fix: add a mini delay for selection clipboard

This commit is contained in:
shenleban tongying 2022-12-28 21:36:02 -05:00
parent a28aec3c9f
commit bdc43650bb
3 changed files with 9 additions and 17 deletions

View file

@ -915,7 +915,8 @@ void MainWindow::clipboardChange( QClipboard::Mode m)
return;
}
scanPopup->translateWordFromSelection();
// Use delay show to prevent multiple popups while selection in progress
scanPopup->selectionDelayTimer.start();
}
#else
scanPopup ->translateWordFromClipboard();

View file

@ -288,10 +288,11 @@ ScanPopup::ScanPopup( QWidget * parent,
translateWordFromSelection();
});
delayTimer.setSingleShot( true );
delayTimer.setInterval( 200 );
// Use delay show to prevent multiple popups while selection in progress
selectionDelayTimer.setSingleShot( true );
selectionDelayTimer.setInterval( 200 );
connect( &delayTimer, &QTimer::timeout, this, &ScanPopup::delayShow );
connect( &selectionDelayTimer, &QTimer::timeout, this, &ScanPopup::translateWordFromSelection );
#endif
applyZoomFactor();
@ -457,14 +458,6 @@ void ScanPopup::translateWord( QString const & word )
);
}
#ifdef HAVE_X11
void ScanPopup::delayShow()
{
QString subtype = "plain";
handleInputWord( QApplication::clipboard()->text( subtype, QClipboard::Selection ) );
}
#endif
[[deprecated("Favor the mainWindow's clipboardChanged ones")]]
void ScanPopup::clipboardChanged( QClipboard::Mode m )
{
@ -487,7 +480,7 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m )
if( m == QClipboard::Selection )
{
// Use delay show to prevent multiple popups while selection in progress
delayTimer.start();
selectionDelayTimer.start();
return;
}
#endif

View file

@ -58,6 +58,8 @@ public:
/// Interaction with scan flag window
void showScanFlag();
void hideScanFlag();
QTimer selectionDelayTimer;
#endif
signals:
@ -146,7 +148,6 @@ private:
#ifdef HAVE_X11
ScanFlag * scanFlag;
QTimer delayTimer;
#endif
bool mouseEnteredOnce;
@ -235,9 +236,6 @@ private slots:
void titleChanged( ArticleView *, QString const & title );
#ifdef HAVE_X11
void delayShow();
#endif
};
#endif