diff --git a/mainwindow.cc b/mainwindow.cc index e7f7ce1b..961e3e05 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -890,11 +890,18 @@ void MainWindow::clipboardChange( QClipboard::Mode m) 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; + // Explicitly disabled on preferences to ignore gd's own selection + + if( cfg.preferences.ignoreOwnClipboardChanges + && QApplication::clipboard()->ownsSelection() ){ + return ; + } + // Keyboard Modifier if(cfg.preferences.enableScanPopupModifiers && !KeyboardState::checkModifiersPressed(cfg.preferences.scanPopupModifiers)){ @@ -908,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(); @@ -1521,9 +1529,6 @@ void MainWindow::makeScanPopup() scanPopup->setStyleSheet( styleSheet() ); - if ( enableScanningAction->isChecked() ) - scanPopup->enableScanning(); - connect( scanPopup.get(), SIGNAL(editGroupRequested( unsigned ) ), this, SLOT(editDictionaries( unsigned )), Qt::QueuedConnection ); @@ -3168,7 +3173,6 @@ void MainWindow::scanEnableToggled( bool on ) { if ( on ) { - scanPopup->enableScanning(); #ifdef Q_OS_MAC if( !MacMouseOver::isAXAPIEnabled() ) mainStatusBar->showMessage( tr( "Accessibility API is not enabled" ), 10000, @@ -3178,7 +3182,6 @@ void MainWindow::scanEnableToggled( bool on ) } else { - scanPopup->disableScanning(); enableScanningAction->setIcon(QIcon(":/icons/wizard.svg")); } } diff --git a/scanpopup.cc b/scanpopup.cc index 12805fa3..eae092c2 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -71,7 +71,6 @@ ScanPopup::ScanPopup( QWidget * parent, History & history_ ): QMainWindow( parent ), cfg( cfg_ ), - isScanningEnabled( false ), allDictionaries( allDictionaries_ ), groups( groups_ ), history( history_ ), @@ -288,10 +287,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(); @@ -302,8 +302,6 @@ ScanPopup::~ScanPopup() { saveConfigData(); - disableScanning(); - ungrabGesture( Gestures::GDPinchGestureType ); ungrabGesture( Gestures::GDSwipeGestureType ); } @@ -317,22 +315,6 @@ void ScanPopup::saveConfigData() cfg.popupWindowAlwaysOnTop = ui.onTopButton->isChecked(); } -void ScanPopup::enableScanning() -{ - if ( !isScanningEnabled ) - { - isScanningEnabled = true; - } -} - -void ScanPopup::disableScanning() -{ - if ( isScanningEnabled ) - { - isScanningEnabled = false; - } -} - void ScanPopup::inspectElementWhenPinned( QWebEnginePage * page ){ if(cfg.pinPopupWindow) 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 ) { handleInputWord( str, forcePopup ); diff --git a/scanpopup.hh b/scanpopup.hh index 12f1b6fa..6e18e048 100644 --- a/scanpopup.hh +++ b/scanpopup.hh @@ -36,12 +36,6 @@ public: History & ); ~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 /// it's changed. @@ -58,6 +52,8 @@ public: /// Interaction with scan flag window void showScanFlag(); void hideScanFlag(); + + QTimer selectionDelayTimer; #endif signals: @@ -126,7 +122,6 @@ private: void updateDictionaryBar(); Config::Class & cfg; - bool isScanningEnabled; std::vector< sptr< Dictionary::Class > > const & allDictionaries; std::vector< sptr< Dictionary::Class > > dictionariesUnmuted; Instances::Groups const & groups; @@ -146,7 +141,6 @@ private: #ifdef HAVE_X11 ScanFlag * scanFlag; - QTimer delayTimer; #endif bool mouseEnteredOnce; @@ -194,7 +188,6 @@ private: void updateSuggestionList(); void updateSuggestionList( QString const & text ); private slots: - void clipboardChanged( QClipboard::Mode ); void mouseHovered( QString const & , bool forcePopup); void currentGroupChanged( int ); void prefixMatchFinished(); @@ -235,9 +228,6 @@ private slots: void titleChanged( ArticleView *, QString const & title ); -#ifdef HAVE_X11 - void delayShow(); -#endif }; #endif