From fa64d450eab2703121084e6f19679d40fc267dc4 Mon Sep 17 00:00:00 2001 From: Xiao YiFang Date: Tue, 2 Aug 2022 22:27:14 +0800 Subject: [PATCH] opt: optimize the function in tracking clipboard in trayicon --- mainwindow.cc | 12 +++++++++++- mainwindow.hh | 2 ++ scanpopup.cc | 8 -------- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mainwindow.cc b/mainwindow.cc index e83b7398..91271300 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -411,7 +411,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ): actTrackingClipboard = trayIconMenu.addAction( tr( "Tracking Clipboard" ) ); actTrackingClipboard->setCheckable(true); actTrackingClipboard->setChecked(cfg.preferences.trackClipboardChanges); - actTrackingClipboard->setVisible( cfg.preferences.enableScanPopup ); +// actTrackingClipboard->setVisible( cfg.preferences.enableScanPopup ); connect( actTrackingClipboard , SIGNAL( triggered(bool) ), this, SLOT( trackingClipboard(bool) ) ); trayIconMenu.addSeparator(); @@ -918,6 +918,16 @@ MainWindow::MainWindow( Config::Class & cfg_ ): } inspector = new ArticleInspector( this ); + + connect( QApplication::clipboard(), &QClipboard::changed, this, &MainWindow::clipboardChange ); +} + +void MainWindow::clipboardChange( QClipboard::Mode mode ) +{ + if( scanPopup && cfg.preferences.trackClipboardChanges ) + { + scanPopup->translateWordFromClipboard(); + } } void MainWindow::ctrlTabPressed() diff --git a/mainwindow.hh b/mainwindow.hh index 683d9710..969479cb 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -487,6 +487,8 @@ private slots: void showGDHelp(); void hideGDHelp(); + void clipboardChange( QClipboard::Mode mode ); + signals: /// Set optional parts expand mode for all tabs void setExpandOptionalParts( bool expand ); diff --git a/scanpopup.cc b/scanpopup.cc index 2daf58c4..3289b928 100644 --- a/scanpopup.cc +++ b/scanpopup.cc @@ -514,14 +514,6 @@ void ScanPopup::delayShow() void ScanPopup::clipboardChanged( QClipboard::Mode m ) { - if( cfg.preferences.trackClipboardChanges ) - { - QString subtype = "plain"; - - handleInputWord( QApplication::clipboard()->text( subtype, m ) ); - return; - } - if( !isScanningEnabled ) return;