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; return;
} }
scanPopup->translateWordFromSelection(); // Use delay show to prevent multiple popups while selection in progress
scanPopup->selectionDelayTimer.start();
} }
#else #else
scanPopup ->translateWordFromClipboard(); scanPopup ->translateWordFromClipboard();

View file

@ -288,10 +288,11 @@ ScanPopup::ScanPopup( QWidget * parent,
translateWordFromSelection(); translateWordFromSelection();
}); });
delayTimer.setSingleShot( true ); // Use delay show to prevent multiple popups while selection in progress
delayTimer.setInterval( 200 ); selectionDelayTimer.setSingleShot( true );
selectionDelayTimer.setInterval( 200 );
connect( &delayTimer, &QTimer::timeout, this, &ScanPopup::delayShow ); connect( &selectionDelayTimer, &QTimer::timeout, this, &ScanPopup::translateWordFromSelection );
#endif #endif
applyZoomFactor(); 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")]] [[deprecated("Favor the mainWindow's clipboardChanged ones")]]
void ScanPopup::clipboardChanged( QClipboard::Mode m ) void ScanPopup::clipboardChanged( QClipboard::Mode m )
{ {
@ -487,7 +480,7 @@ void ScanPopup::clipboardChanged( QClipboard::Mode m )
if( m == QClipboard::Selection ) if( m == QClipboard::Selection )
{ {
// Use delay show to prevent multiple popups while selection in progress // Use delay show to prevent multiple popups while selection in progress
delayTimer.start(); selectionDelayTimer.start();
return; return;
} }
#endif #endif

View file

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