Merge pull request #290 from shenlebantongying/staged

fix remaining problems of scanpop clipboard on linux
This commit is contained in:
xiaoyifang 2022-12-29 14:09:09 +08:00 committed by GitHub
commit 12e8c796a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 82 deletions

View file

@ -890,11 +890,18 @@ void MainWindow::clipboardChange( QClipboard::Mode m)
if(m == QClipboard::Selection){ if(m == QClipboard::Selection){
// Multiple ways to stoping a word from showing up when selecting // Multiple ways to stopping a word from showing up when selecting
// Explictly disabled on preferences // Explicitly disabled on preferences
if(!cfg.preferences.trackSelectionScan) return; if(!cfg.preferences.trackSelectionScan) return;
// Explicitly disabled on preferences to ignore gd's own selection
if( cfg.preferences.ignoreOwnClipboardChanges
&& QApplication::clipboard()->ownsSelection() ){
return ;
}
// Keyboard Modifier // Keyboard Modifier
if(cfg.preferences.enableScanPopupModifiers && if(cfg.preferences.enableScanPopupModifiers &&
!KeyboardState::checkModifiersPressed(cfg.preferences.scanPopupModifiers)){ !KeyboardState::checkModifiersPressed(cfg.preferences.scanPopupModifiers)){
@ -908,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();
@ -1521,9 +1529,6 @@ void MainWindow::makeScanPopup()
scanPopup->setStyleSheet( styleSheet() ); scanPopup->setStyleSheet( styleSheet() );
if ( enableScanningAction->isChecked() )
scanPopup->enableScanning();
connect( scanPopup.get(), SIGNAL(editGroupRequested( unsigned ) ), connect( scanPopup.get(), SIGNAL(editGroupRequested( unsigned ) ),
this, SLOT(editDictionaries( unsigned )), Qt::QueuedConnection ); this, SLOT(editDictionaries( unsigned )), Qt::QueuedConnection );
@ -3168,7 +3173,6 @@ void MainWindow::scanEnableToggled( bool on )
{ {
if ( on ) if ( on )
{ {
scanPopup->enableScanning();
#ifdef Q_OS_MAC #ifdef Q_OS_MAC
if( !MacMouseOver::isAXAPIEnabled() ) if( !MacMouseOver::isAXAPIEnabled() )
mainStatusBar->showMessage( tr( "Accessibility API is not enabled" ), 10000, mainStatusBar->showMessage( tr( "Accessibility API is not enabled" ), 10000,
@ -3178,7 +3182,6 @@ void MainWindow::scanEnableToggled( bool on )
} }
else else
{ {
scanPopup->disableScanning();
enableScanningAction->setIcon(QIcon(":/icons/wizard.svg")); enableScanningAction->setIcon(QIcon(":/icons/wizard.svg"));
} }
} }

View file

@ -71,7 +71,6 @@ ScanPopup::ScanPopup( QWidget * parent,
History & history_ ): History & history_ ):
QMainWindow( parent ), QMainWindow( parent ),
cfg( cfg_ ), cfg( cfg_ ),
isScanningEnabled( false ),
allDictionaries( allDictionaries_ ), allDictionaries( allDictionaries_ ),
groups( groups_ ), groups( groups_ ),
history( history_ ), history( history_ ),
@ -288,10 +287,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();
@ -302,8 +302,6 @@ ScanPopup::~ScanPopup()
{ {
saveConfigData(); saveConfigData();
disableScanning();
ungrabGesture( Gestures::GDPinchGestureType ); ungrabGesture( Gestures::GDPinchGestureType );
ungrabGesture( Gestures::GDSwipeGestureType ); ungrabGesture( Gestures::GDSwipeGestureType );
} }
@ -317,22 +315,6 @@ void ScanPopup::saveConfigData()
cfg.popupWindowAlwaysOnTop = ui.onTopButton->isChecked(); cfg.popupWindowAlwaysOnTop = ui.onTopButton->isChecked();
} }
void ScanPopup::enableScanning()
{
if ( !isScanningEnabled )
{
isScanningEnabled = true;
}
}
void ScanPopup::disableScanning()
{
if ( isScanningEnabled )
{
isScanningEnabled = false;
}
}
void ScanPopup::inspectElementWhenPinned( QWebEnginePage * page ){ void ScanPopup::inspectElementWhenPinned( QWebEnginePage * page ){
if(cfg.pinPopupWindow) if(cfg.pinPopupWindow)
emit inspectSignal(page); emit inspectSignal(page);
@ -457,46 +439,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 )
{
if( !isScanningEnabled )
return;
#ifdef HAVE_X11
if( cfg.preferences.ignoreOwnClipboardChanges && ownsClipboardMode( m ) )
return;
if(m == QClipboard::Clipboard && !cfg.preferences.trackClipboardScan){
return;
}
if(m == QClipboard::Selection && !cfg.preferences.trackSelectionScan){
return;
}
if( m == QClipboard::Selection )
{
// Use delay show to prevent multiple popups while selection in progress
delayTimer.start();
return;
}
#endif
QString subtype = "plain";
handleInputWord( QApplication::clipboard()->text( subtype, m ) );
}
void ScanPopup::mouseHovered( QString const & str, bool forcePopup ) void ScanPopup::mouseHovered( QString const & str, bool forcePopup )
{ {
handleInputWord( str, forcePopup ); handleInputWord( str, forcePopup );

View file

@ -37,12 +37,6 @@ public:
~ScanPopup(); ~ScanPopup();
/// Enables scanning. When the object is created, the scanning is disabled
/// initially.
void enableScanning();
/// Disables scanning.
void disableScanning();
/// Applies current zoom factor to the popup's view. Should be called when /// Applies current zoom factor to the popup's view. Should be called when
/// it's changed. /// it's changed.
void applyZoomFactor(); void applyZoomFactor();
@ -58,6 +52,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:
@ -126,7 +122,6 @@ private:
void updateDictionaryBar(); void updateDictionaryBar();
Config::Class & cfg; Config::Class & cfg;
bool isScanningEnabled;
std::vector< sptr< Dictionary::Class > > const & allDictionaries; std::vector< sptr< Dictionary::Class > > const & allDictionaries;
std::vector< sptr< Dictionary::Class > > dictionariesUnmuted; std::vector< sptr< Dictionary::Class > > dictionariesUnmuted;
Instances::Groups const & groups; Instances::Groups const & groups;
@ -146,7 +141,6 @@ private:
#ifdef HAVE_X11 #ifdef HAVE_X11
ScanFlag * scanFlag; ScanFlag * scanFlag;
QTimer delayTimer;
#endif #endif
bool mouseEnteredOnce; bool mouseEnteredOnce;
@ -194,7 +188,6 @@ private:
void updateSuggestionList(); void updateSuggestionList();
void updateSuggestionList( QString const & text ); void updateSuggestionList( QString const & text );
private slots: private slots:
void clipboardChanged( QClipboard::Mode );
void mouseHovered( QString const & , bool forcePopup); void mouseHovered( QString const & , bool forcePopup);
void currentGroupChanged( int ); void currentGroupChanged( int );
void prefixMatchFinished(); void prefixMatchFinished();
@ -235,9 +228,6 @@ private slots:
void titleChanged( ArticleView *, QString const & title ); void titleChanged( ArticleView *, QString const & title );
#ifdef HAVE_X11
void delayShow();
#endif
}; };
#endif #endif