Merge pull request #207 from shenlebantongying/fix-popup

Overhaul ScanPopup
This commit is contained in:
xiaoyifang 2022-11-20 19:42:23 +08:00 committed by GitHub
commit 75a83b0f81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 169 additions and 328 deletions

View file

@ -227,17 +227,18 @@ Preferences::Preferences():
enableClipboardHotkey( true ),
clipboardHotkey( QKeySequence( "Ctrl+C,C" ) ),
enableScanPopup( true ),
startWithScanPopupOn( false ),
enableScanPopupModifiers( false ),
scanPopupModifiers( 0 ),
scanPopupAltMode( false ),
scanPopupAltModeSecs( 3 ),
ignoreOwnClipboardChanges( false ),
scanToMainWindow( false ),
ignoreDiacritics( false ),
ignorePunctuation( false ),
#ifdef HAVE_X11
// Enable both Clipboard and Selection by default so that X users can enjoy full
// power and disable optionally.
trackClipboardScan ( true ),
trackSelectionScan ( true ),
showScanFlag( false ),
#endif
pronounceOnLoadMain( false ),
@ -264,9 +265,6 @@ Preferences::Preferences():
, limitInputPhraseLength( false )
, inputPhraseLengthLimit( 1000 )
, maxDictionaryRefsInContextMenu ( 20 )
#ifndef Q_WS_X11
, trackClipboardChanges( false )
#endif
, synonymSearchEnabled( true )
{
}
@ -887,19 +885,17 @@ Class load()
if ( !preferences.namedItem( "clipboardHotkey" ).isNull() )
c.preferences.clipboardHotkey = QKeySequence::fromString( preferences.namedItem( "clipboardHotkey" ).toElement().text() );
c.preferences.enableScanPopup = ( preferences.namedItem( "enableScanPopup" ).toElement().text() == "1" );
c.preferences.startWithScanPopupOn = ( preferences.namedItem( "startWithScanPopupOn" ).toElement().text() == "1" );
c.preferences.enableScanPopupModifiers = ( preferences.namedItem( "enableScanPopupModifiers" ).toElement().text() == "1" );
c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() );
c.preferences.scanPopupAltMode = ( preferences.namedItem( "scanPopupAltMode" ).toElement().text() == "1" );
if ( !preferences.namedItem( "scanPopupAltModeSecs" ).isNull() )
c.preferences.scanPopupAltModeSecs = preferences.namedItem( "scanPopupAltModeSecs" ).toElement().text().toUInt();
c.preferences.ignoreOwnClipboardChanges = ( preferences.namedItem( "ignoreOwnClipboardChanges" ).toElement().text() == "1" );
c.preferences.scanToMainWindow = ( preferences.namedItem( "scanToMainWindow" ).toElement().text() == "1" );
c.preferences.ignoreDiacritics = ( preferences.namedItem( "ignoreDiacritics" ).toElement().text() == "1" );
if( !preferences.namedItem( "ignorePunctuation" ).isNull() )
c.preferences.ignorePunctuation = ( preferences.namedItem( "ignorePunctuation" ).toElement().text() == "1" );
#ifdef HAVE_X11
c.preferences.trackClipboardScan= ( preferences.namedItem( "trackClipboardScan" ).toElement().text() == "1" );
c.preferences.trackSelectionScan= ( preferences.namedItem( "trackSelectionScan" ).toElement().text() == "1" );
c.preferences.showScanFlag= ( preferences.namedItem( "showScanFlag" ).toElement().text() == "1" );
#endif
@ -1002,11 +998,6 @@ Class load()
if ( !preferences.namedItem( "maxDictionaryRefsInContextMenu" ).isNull() )
c.preferences.maxDictionaryRefsInContextMenu = preferences.namedItem( "maxDictionaryRefsInContextMenu" ).toElement().text().toUShort();
#ifndef Q_WS_X11
if ( !preferences.namedItem( "trackClipboardChanges" ).isNull() )
c.preferences.trackClipboardChanges = ( preferences.namedItem( "trackClipboardChanges" ).toElement().text() == "1" );
#endif
if ( !preferences.namedItem( "synonymSearchEnabled" ).isNull() )
c.preferences.synonymSearchEnabled = ( preferences.namedItem( "synonymSearchEnabled" ).toElement().text() == "1" );
@ -1748,10 +1739,6 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( c.preferences.clipboardHotkey.toKeySequence().toString() ) );
preferences.appendChild( opt );
opt = dd.createElement( "enableScanPopup" );
opt.appendChild( dd.createTextNode( c.preferences.enableScanPopup ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "startWithScanPopupOn" );
opt.appendChild( dd.createTextNode( c.preferences.startWithScanPopupOn ? "1":"0" ) );
preferences.appendChild( opt );
@ -1764,14 +1751,6 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( QString::number( c.preferences.scanPopupModifiers ) ) );
preferences.appendChild( opt );
opt = dd.createElement( "scanPopupAltMode" );
opt.appendChild( dd.createTextNode( c.preferences.scanPopupAltMode ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "scanPopupAltModeSecs" );
opt.appendChild( dd.createTextNode( QString::number( c.preferences.scanPopupAltModeSecs ) ) );
preferences.appendChild( opt );
opt = dd.createElement( "ignoreOwnClipboardChanges" );
opt.appendChild( dd.createTextNode( c.preferences.ignoreOwnClipboardChanges ? "1":"0" ) );
preferences.appendChild( opt );
@ -1789,6 +1768,14 @@ void save( Class const & c )
preferences.appendChild( opt );
#ifdef HAVE_X11
opt = dd.createElement( "trackClipboardScan" );
opt.appendChild( dd.createTextNode( c.preferences.trackClipboardScan ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "trackSelectionScan" );
opt.appendChild( dd.createTextNode( c.preferences.trackSelectionScan ? "1":"0" ) );
preferences.appendChild( opt );
opt = dd.createElement( "showScanFlag" );
opt.appendChild( dd.createTextNode( c.preferences.showScanFlag? "1":"0" ) );
preferences.appendChild( opt );
@ -1961,12 +1948,6 @@ void save( Class const & c )
opt.appendChild( dd.createTextNode( QString::number( c.preferences.maxDictionaryRefsInContextMenu ) ) );
preferences.appendChild( opt );
#ifndef Q_WS_X11
opt = dd.createElement( "trackClipboardChanges" );
opt.appendChild( dd.createTextNode( c.preferences.trackClipboardChanges ? "1" : "0" ) );
preferences.appendChild( opt );
#endif
opt = dd.createElement( "synonymSearchEnabled" );
opt.appendChild( dd.createTextNode( c.preferences.synonymSearchEnabled ? "1" : "0" ) );
preferences.appendChild( opt );

View file

@ -318,18 +318,17 @@ struct Preferences
bool enableClipboardHotkey;
HotKey clipboardHotkey;
bool enableScanPopup;
bool startWithScanPopupOn;
bool enableScanPopupModifiers;
unsigned long scanPopupModifiers; // Combination of KeyboardState::Modifier
bool scanPopupAltMode; // When you press modifier shortly after the selection
unsigned scanPopupAltModeSecs;
bool ignoreOwnClipboardChanges;
bool scanToMainWindow;
bool ignoreDiacritics;
bool ignorePunctuation;
#ifdef HAVE_X11
bool trackClipboardScan;
bool trackSelectionScan;
bool showScanFlag;
#endif
@ -370,9 +369,6 @@ struct Preferences
InputPhrase sanitizeInputPhrase( QString const & inputPhrase ) const;
unsigned short maxDictionaryRefsInContextMenu;
#ifndef Q_WS_X11
bool trackClipboardChanges;
#endif
bool synonymSearchEnabled;

View file

@ -27,7 +27,7 @@ public:
/// Returns true if all Modifiers present within the given mask are pressed
/// right now.
bool checkModifiersPressed( int mask );
bool static checkModifiersPressed( int mask );
};
#endif

View file

@ -49,6 +49,8 @@
#include "ui_authentication.h"
#include "resourceschemehandler.h"
#include "keyboardstate.hh"
#ifdef Q_OS_MAC
#include "macmouseover.hh"
#endif
@ -228,27 +230,22 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
translateBoxToolBarAction = navToolbar->addWidget( translateBoxWidget );
// scan popup
beforeScanPopupSeparator = navToolbar->addSeparator();
beforeScanPopupSeparator->setVisible( cfg.preferences.enableScanPopup );
navToolbar->widgetForAction( beforeScanPopupSeparator )->setObjectName( "beforeScanPopupSeparator" );
navToolbar->addSeparator();
enableScanPopup = navToolbar->addAction( QIcon( ":/icons/wizard.svg" ), tr( "Scan Popup" ) );
enableScanPopup->setCheckable( true );
enableScanPopup->setVisible( cfg.preferences.enableScanPopup );
navToolbar->widgetForAction( enableScanPopup )->setObjectName( "scanPopupButton" );
if( cfg.preferences.enableScanPopup && cfg.preferences.startWithScanPopupOn )
enableScanningAction = navToolbar->addAction( QIcon( ":/icons/wizard.svg" ), tr( "Enable Scanning" ) );
enableScanningAction->setCheckable( true );
navToolbar->widgetForAction( enableScanningAction )->setObjectName( "scanPopupButton" );
if( cfg.preferences.startWithScanPopupOn )
{
enableScanPopup->setIcon( QIcon( ":/icons/wizard-selected.svg" ) );
enableScanPopup->setChecked( true );
enableScanningAction->setIcon( QIcon( ":/icons/wizard-selected.svg" ) );
enableScanningAction->setChecked( true );
}
connect( enableScanPopup, SIGNAL( toggled( bool ) ),
connect( enableScanningAction, SIGNAL( toggled( bool ) ),
this, SLOT( scanEnableToggled( bool ) ) );
afterScanPopupSeparator = navToolbar->addSeparator();
afterScanPopupSeparator->setVisible( cfg.preferences.enableScanPopup );
navToolbar->widgetForAction( afterScanPopupSeparator )->setObjectName( "afterScanPopupSeparator" );
navToolbar->addSeparator();
// sound
navPronounce = navToolbar->addAction( QIcon( ":/icons/playsound_full.png" ), tr( "Pronounce Word (Alt+S)" ) );
@ -410,13 +407,8 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
// tray icon
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), SIGNAL( triggered() ),
this, SLOT( showMainWindow() ) );
trayIconMenu.addAction( enableScanPopup );
actTrackingClipboard = trayIconMenu.addAction( tr( "Tracking Clipboard" ) );
actTrackingClipboard->setCheckable(true);
actTrackingClipboard->setChecked(cfg.preferences.trackClipboardChanges);
// actTrackingClipboard->setVisible( cfg.preferences.enableScanPopup );
connect( actTrackingClipboard , SIGNAL( triggered(bool) ),
this, SLOT( trackingClipboard(bool) ) );
trayIconMenu.addAction( enableScanningAction );
trayIconMenu.addSeparator();
connect( trayIconMenu.addAction( tr( "&Quit" ) ), SIGNAL( triggered() ),
this, SLOT( quitApp() ) );
@ -918,16 +910,46 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
inspector.reset( new ArticleInspector( this ));
connect( QApplication::clipboard(), &QClipboard::dataChanged, this, &MainWindow::clipboardChange );
connect( QApplication::clipboard(), &QClipboard::changed, this, &MainWindow::clipboardChange );
}
void MainWindow::clipboardChange( )
void MainWindow::clipboardChange( QClipboard::Mode m)
{
qDebug() << "clipboard change ," << cfg.preferences.trackClipboardChanges << scanPopup.get();
if( scanPopup && cfg.preferences.trackClipboardChanges )
if( scanPopup && enableScanningAction->isChecked() )
{
scanPopup->translateWordFromClipboard();
}
#ifdef HAVE_X11
if(m == QClipboard::Clipboard){
if(!cfg.preferences.trackClipboardScan) return;
scanPopup->translateWordFromClipboard();
return;
}
if(m == QClipboard::Selection){
// Multiple ways to stoping a word from showing up when selecting
// Explictly disabled on preferences
if(!cfg.preferences.trackSelectionScan) return;
// Keyboard Modifier
if(cfg.preferences.enableScanPopupModifiers &&
!KeyboardState::checkModifiersPressed(cfg.preferences.scanPopupModifiers)){
return;
}
// Show a Flag instead of translate directly.
// And hand over the control of showing the popup to scanFlag
if ( cfg.preferences.showScanFlag ) {
scanPopup->showScanFlag();
return;
}
scanPopup->translateWordFromSelection();
}
#else
scanPopup ->translateWordFromClipboard();
#endif
}
}
void MainWindow::ctrlTabPressed()
@ -1198,7 +1220,7 @@ void MainWindow::updateTrayIcon()
if ( trayIcon )
{
// Update the icon to reflect the scanning mode
trayIcon->setIcon( enableScanPopup->isChecked() ?
trayIcon->setIcon( enableScanningAction->isChecked() ?
QIcon::fromTheme("goldendict-scan-tray", QIcon( ":/icons/programicon_scan.png" )) :
QIcon::fromTheme("goldendict-tray", QIcon( ":/icons/programicon_old.png" )) );
@ -1489,16 +1511,12 @@ void MainWindow::makeScanPopup()
{
scanPopup.reset();
if ( !cfg.preferences.enableScanPopup &&
!cfg.preferences.enableClipboardHotkey && !cfg.preferences.trackClipboardChanges )
return;
scanPopup = new ScanPopup( 0, cfg, articleNetMgr, audioPlayerFactory.player(),
dictionaries, groupInstances, history );
scanPopup->setStyleSheet( styleSheet() );
if ( cfg.preferences.enableScanPopup && enableScanPopup->isChecked() )
if ( enableScanningAction->isChecked() )
scanPopup->enableScanning();
connect( scanPopup.get(), SIGNAL(editGroupRequested( unsigned ) ),
@ -2186,9 +2204,7 @@ void MainWindow::editPreferences()
p.hideMenubar = cfg.preferences.hideMenubar;
p.searchInDock = cfg.preferences.searchInDock;
p.alwaysOnTop = cfg.preferences.alwaysOnTop;
#ifndef Q_WS_X11
p.trackClipboardChanges = cfg.preferences.trackClipboardChanges;
#endif
p.proxyServer.systemProxyUser = cfg.preferences.proxyServer.systemProxyUser;
p.proxyServer.systemProxyPassword = cfg.preferences.proxyServer.systemProxyPassword;
@ -2253,13 +2269,6 @@ void MainWindow::editPreferences()
audioPlayerFactory.setPreferences( cfg.preferences );
beforeScanPopupSeparator->setVisible( cfg.preferences.enableScanPopup );
enableScanPopup->setVisible( cfg.preferences.enableScanPopup );
afterScanPopupSeparator->setVisible( cfg.preferences.enableScanPopup );
if ( !cfg.preferences.enableScanPopup )
enableScanPopup->setChecked( false );
updateTrayIcon();
applyProxySettings();
@ -3173,8 +3182,6 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r )
void MainWindow::scanEnableToggled( bool on )
{
if ( !cfg.preferences.enableScanPopup )
return;
if ( scanPopup )
{
@ -3186,12 +3193,12 @@ void MainWindow::scanEnableToggled( bool on )
mainStatusBar->showMessage( tr( "Accessibility API is not enabled" ), 10000,
QPixmap( ":/icons/error.svg" ) );
#endif
enableScanPopup->setIcon(QIcon(":/icons/wizard-selected.svg"));
enableScanningAction->setIcon(QIcon(":/icons/wizard-selected.svg"));
}
else
{
scanPopup->disableScanning();
enableScanPopup->setIcon(QIcon(":/icons/wizard.svg"));
enableScanningAction->setIcon(QIcon(":/icons/wizard.svg"));
}
}
@ -3203,12 +3210,6 @@ void MainWindow::showMainWindow()
toggleMainWindow( true );
}
void MainWindow::trackingClipboard( bool on )
{
cfg.preferences.trackClipboardChanges = on;
makeScanPopup();
}
void MainWindow::visitHomepage()
{
QDesktopServices::openUrl( QUrl( "http://goldendict.org/" ) );

View file

@ -116,9 +116,8 @@ private:
addAllTabToFavoritesAction;
QToolBar * navToolbar;
MainStatusBar * mainStatusBar;
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
QAction * actTrackingClipboard;
QAction * beforeScanPopupSeparator, * afterScanPopupSeparator, * beforeOptionsSeparator;
QAction * navBack, * navForward, * navPronounce, * enableScanningAction;
QAction * beforeOptionsSeparator;
QAction * zoomIn, * zoomOut, * zoomBase;
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
QAction * addToFavorites, * beforeAddToFavoritesSeparator;
@ -416,8 +415,6 @@ private slots:
void showMainWindow();
void trackingClipboard(bool);
void visitHomepage();
void visitForum();
void openConfigFolder();
@ -487,7 +484,7 @@ private slots:
void showGDHelp();
void hideGDHelp();
void clipboardChange( );
void clipboardChange(QClipboard::Mode m);
void inspectElement( QWebEnginePage * );

View file

@ -16,9 +16,6 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
Config::Preferences const & p = cfg_.preferences;
ui.setupUi( this );
connect( ui.enableScanPopup, SIGNAL( toggled( bool ) ),
this, SLOT( enableScanPopupToggled( bool ) ) );
connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ),
this, SLOT( enableScanPopupModifiersToggled( bool ) ) );
@ -190,7 +187,6 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.enableClipboardHotkey->setChecked( p.enableClipboardHotkey );
ui.clipboardHotkey->setHotKey( p.clipboardHotkey );
ui.enableScanPopup->setChecked( p.enableScanPopup );
ui.startWithScanPopupOn->setChecked( p.startWithScanPopupOn );
ui.enableScanPopupModifiers->setChecked( p.enableScanPopupModifiers );
@ -205,8 +201,6 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
ui.leftShift->setChecked( p.scanPopupModifiers & KeyboardState::LeftShift );
ui.rightShift->setChecked( p.scanPopupModifiers & KeyboardState::RightShift );
ui.scanPopupAltMode->setChecked( p.scanPopupAltMode );
ui.scanPopupAltModeSecs->setValue( p.scanPopupAltModeSecs );
ui.ignoreOwnClipboardChanges->setChecked( p.ignoreOwnClipboardChanges );
ui.scanToMainWindow->setChecked( p.scanToMainWindow );
@ -255,8 +249,12 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
//Platform-specific options
#ifdef HAVE_X11
ui.showScanFlag->setChecked( p.showScanFlag);
ui.enableX11SelectionTrack->setChecked(p.trackSelectionScan);
ui.enableClipboardTrack ->setChecked(p.trackClipboardScan);
ui.showScanFlag->setChecked(p.showScanFlag);
#else
ui.enableX11SelectionTrack->hide();
ui.enableClipboardTrack->hide();
ui.showScanFlag->hide();
ui.ignoreOwnClipboardChanges->hide();
#endif
@ -407,7 +405,6 @@ Config::Preferences Preferences::getPreferences()
p.enableClipboardHotkey = ui.enableClipboardHotkey->isChecked();
p.clipboardHotkey = ui.clipboardHotkey->getHotKey();
p.enableScanPopup = ui.enableScanPopup->isChecked();
p.startWithScanPopupOn = ui.startWithScanPopupOn->isChecked();
p.enableScanPopupModifiers = ui.enableScanPopupModifiers->isChecked();
@ -422,11 +419,11 @@ Config::Preferences Preferences::getPreferences()
p.scanPopupModifiers += ui.leftShift->isChecked() ? KeyboardState::LeftShift: 0;
p.scanPopupModifiers += ui.rightShift->isChecked() ? KeyboardState::RightShift: 0;
p.scanPopupAltMode = ui.scanPopupAltMode->isChecked();
p.scanPopupAltModeSecs = ui.scanPopupAltModeSecs->value();
p.ignoreOwnClipboardChanges = ui.ignoreOwnClipboardChanges->isChecked();
p.scanToMainWindow = ui.scanToMainWindow->isChecked();
#ifdef HAVE_X11
p.trackSelectionScan = ui.enableX11SelectionTrack ->isChecked();
p.trackClipboardScan = ui.enableClipboardTrack ->isChecked();
p.showScanFlag= ui.showScanFlag->isChecked();
#endif
@ -572,14 +569,9 @@ Config::Preferences Preferences::getPreferences()
return p;
}
void Preferences::enableScanPopupToggled( bool b )
{
ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopupModifiers->isChecked() );
}
void Preferences::enableScanPopupModifiersToggled( bool b )
{
ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopup->isChecked() );
ui.scanPopupModifiers->setEnabled( b );
if( b )
ui.showScanFlag->setChecked( false );
}

View file

@ -33,7 +33,6 @@ private:
private slots:
void enableScanPopupToggled( bool );
void enableScanPopupModifiersToggled( bool );
void showScanFlagToggled( bool b );

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>744</width>
<height>506</height>
<width>787</width>
<height>629</height>
</rect>
</property>
<property name="windowTitle">
@ -424,34 +424,48 @@ be the last ones.</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QGroupBox" name="enableScanPopup">
<widget class="QCheckBox" name="startWithScanPopupOn">
<property name="toolTip">
<string>When enabled, a translation popup window would be shown each time
you point your mouse on any word on the screen (Windows) or select
any word with mouse (Linux). When enabled, you can switch it on and
off from main window or tray icon.</string>
<string>Chooses whether the scan popup mode is on by default or not. If checked,
the program would always start with the scan popup active.</string>
</property>
<property name="text">
<string>Start with scan popup turned on</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scanToMainWindow">
<property name="toolTip">
<string>Send translated word to main window instead of to show it in popup window</string>
</property>
<property name="text">
<string>Send translated word to main window</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableClipboardTrack">
<property name="toolTip">
<string>Track clipboard changes when Scanning is enabled. Notice! You should always enable this unless you are on Linux.</string>
</property>
<property name="text">
<string>Track Clipboard change</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="enableX11SelectionTrack">
<property name="title">
<string>Enable scan popup functionality</string>
<string>Track Selection change</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QCheckBox" name="startWithScanPopupOn">
<property name="toolTip">
<string>Chooses whether the scan popup mode is on by default or not. If checked,
the program would always start with the scan popup active.</string>
</property>
<property name="text">
<string>Start with scan popup turned on</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableScanPopupModifiers">
<property name="toolTip">
@ -459,7 +473,7 @@ the program would always start with the scan popup active.</string>
in the pressed state when the word selection changes.</string>
</property>
<property name="text">
<string>Only show popup when all selected keys are kept pressed:</string>
<string>Only tack selection when all selected keys are kept pressed:</string>
</property>
</widget>
</item>
@ -638,67 +652,6 @@ in the pressed state when the word selection changes.</string>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QCheckBox" name="scanPopupAltMode">
<property name="toolTip">
<string>Normally, in order to activate a popup you have to
maintain the chosen keys pressed while you select
a word. With this enabled, the chosen keys may also
be pressed shortly after the selection is done.</string>
</property>
<property name="text">
<string>Keys may also be pressed afterwards, within</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="scanPopupAltModeSecs">
<property name="toolTip">
<string>To avoid false positives, the keys are only monitored
after the selection's done for a limited amount of
seconds, which is specified here.</string>
</property>
<property name="wrapping">
<bool>false</bool>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>99</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>secs</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="showScanFlag">
<property name="toolTip">
@ -722,16 +675,6 @@ seconds, which is specified here.</string>
</layout>
</widget>
</item>
<item>
<widget class="QCheckBox" name="scanToMainWindow">
<property name="toolTip">
<string>Send translated word to main window instead of to show it in popup window</string>
</property>
<property name="text">
<string>Send translated word to main window</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_6">
<property name="orientation">
@ -1844,8 +1787,6 @@ from Stardict, Babylon and GLS dictionaries</string>
<tabstop>closeToTray</tabstop>
<tabstop>cbAutostart</tabstop>
<tabstop>interfaceLanguage</tabstop>
<tabstop>startWithScanPopupOn</tabstop>
<tabstop>enableScanPopupModifiers</tabstop>
<tabstop>leftCtrl</tabstop>
<tabstop>rightShift</tabstop>
<tabstop>altKey</tabstop>
@ -1856,8 +1797,6 @@ from Stardict, Babylon and GLS dictionaries</string>
<tabstop>rightCtrl</tabstop>
<tabstop>leftShift</tabstop>
<tabstop>winKey</tabstop>
<tabstop>scanPopupAltMode</tabstop>
<tabstop>scanPopupAltModeSecs</tabstop>
<tabstop>useProxyServer</tabstop>
<tabstop>proxyType</tabstop>
<tabstop>proxyHost</tabstop>

View file

@ -4,29 +4,28 @@
#include "ui_scanflag.h"
#include <QScreen>
static Qt::WindowFlags popupWindowFlags =
Qt::ToolTip | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint
| Qt::WindowDoesNotAcceptFocus
;
ScanFlag::ScanFlag(QWidget *parent) :
QMainWindow(parent)
{
ui.setupUi( this );
setWindowFlags( popupWindowFlags );
setWindowFlags( Qt::ToolTip
| Qt::FramelessWindowHint
| Qt::WindowStaysOnTopHint
| Qt::WindowDoesNotAcceptFocus);
setAttribute(Qt::WA_X11DoNotAcceptFocus);
hideTimer.setSingleShot( true );
hideTimer.setInterval( 1500 );
hideTimer.setInterval( 1000 );
connect( &hideTimer, SIGNAL( timeout() ),
this, SLOT( hideWindow() ) );
connect( &hideTimer, &QTimer::timeout,
this, [=]{ hideWindow();
});
connect( ui.pushButton, SIGNAL( clicked( bool ) ),
this, SLOT( pushButtonClicked() ) );
connect( ui.pushButton, &QPushButton::clicked,
this, &ScanFlag::pushButtonClicked );
}
ScanFlag::~ScanFlag()
@ -37,7 +36,7 @@ void ScanFlag::pushButtonClicked()
{
hideTimer.stop();
hide();
emit showScanPopup();
emit requestScanPopup();
}
void ScanFlag::hideWindow()

View file

@ -2,7 +2,6 @@
#define SCAN_FLAG_H
#include "config.hh"
#include <QMainWindow>
#include <QTimer>
#include "ui_scanflag.h"
@ -16,18 +15,17 @@ public:
~ScanFlag();
void showScanFlag();
void pushButtonClicked();
void hideWindow();
signals:
void showScanPopup ();
void requestScanPopup ();
private:
Ui::ScanFlag ui;
QTimer hideTimer;
private slots:
void showScanFlag();
void pushButtonClicked();
void hideWindow();
};
#endif // SCAN_FLAG_H

View file

@ -278,11 +278,6 @@ ScanPopup::ScanPopup( QWidget * parent,
connect( definition, SIGNAL( titleChanged( ArticleView *, QString const & ) ),
this, SLOT( titleChanged( ArticleView *, QString const & ) ) );
connect( QApplication::clipboard(),
SIGNAL( changed( QClipboard::Mode ) ),
this,
SLOT( clipboardChanged( QClipboard::Mode ) ) );
#ifdef Q_OS_MAC
connect( &MouseOver::instance(), SIGNAL( hovered( QString const &, bool ) ),
this, SLOT( mouseHovered( QString const &, bool ) ) );
@ -294,18 +289,6 @@ ScanPopup::ScanPopup( QWidget * parent,
connect( &hideTimer, SIGNAL( timeout() ),
this, SLOT( hideTimerExpired() ) );
altModeExpirationTimer.setSingleShot( true );
altModeExpirationTimer.setInterval( cfg.preferences.scanPopupAltModeSecs * 1000 );
connect( &altModeExpirationTimer, SIGNAL( timeout() ),
this, SLOT( altModeExpired() ) );
// This one polls constantly for modifiers while alt mode lasts
altModePollingTimer.setSingleShot( false );
altModePollingTimer.setInterval( 50 );
connect( &altModePollingTimer, SIGNAL( timeout() ),
this, SLOT( altModePoll() ) );
mouseGrabPollTimer.setSingleShot( false );
mouseGrabPollTimer.setInterval( 10 );
connect( &mouseGrabPollTimer, SIGNAL( timeout() ),
@ -322,14 +305,10 @@ ScanPopup::ScanPopup( QWidget * parent,
#ifdef HAVE_X11
scanFlag = new ScanFlag( this );
connect( this, SIGNAL( showScanFlag( bool ) ),
scanFlag, SLOT( showScanFlag() ) );
connect( this, SIGNAL( hideScanFlag() ),
scanFlag, SLOT( hideWindow() ) );
connect( scanFlag, SIGNAL( showScanPopup() ),
this, SLOT( showEngagePopup() ) );
connect( scanFlag, &ScanFlag::requestScanPopup,
this, [=]{
translateWordFromSelection();
});
delayTimer.setSingleShot( true );
delayTimer.setInterval( 200 );
@ -486,10 +465,6 @@ void ScanPopup::translateWord( QString const & word )
if ( !pendingInputPhrase.isValid() )
return; // Nothing there
// In case we had any timers engaged before, cancel them now.
altModePollingTimer.stop();
altModeExpirationTimer.stop();
#ifdef HAVE_X11
emit hideScanFlag();
#endif
@ -513,21 +488,25 @@ void ScanPopup::delayShow()
}
#endif
[[deprecated("Favor the mainWindow's clipboardChanged ones")]]
void ScanPopup::clipboardChanged( QClipboard::Mode m )
{
// if( !cfg.preferences.trackClipboardChanges )
// return;
if( !isScanningEnabled && !cfg.preferences.trackClipboardChanges)
if( !isScanningEnabled )
return;
#ifdef HAVE_X11
if( cfg.preferences.ignoreOwnClipboardChanges && ownsClipboardMode( m ) )
return;
#endif
GD_DPRINTF( "clipboard changed\n" );
if(m == QClipboard::Clipboard && !cfg.preferences.trackClipboardScan){
return;
}
if(m == QClipboard::Selection && !cfg.preferences.trackSelectionScan){
return;
}
#ifdef HAVE_X11
if( m == QClipboard::Selection )
{
// Use delay show to prevent multiple popups while selection in progress
@ -546,6 +525,7 @@ void ScanPopup::mouseHovered( QString const & str, bool forcePopup )
handleInputWord( str, forcePopup );
}
[[deprecated]]
void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
{
Config::InputPhrase sanitizedPhrase = cfg.preferences.sanitizeInputPhrase( str );
@ -559,39 +539,15 @@ void ScanPopup::handleInputWord( QString const & str, bool forcePopup )
pendingInputPhrase = sanitizedPhrase;
if ( !pendingInputPhrase.isValid() )
{
if ( cfg.preferences.scanPopupAltMode )
{
// In case we had any timers engaged before, cancel them now, since
// we're not going to translate anything anymore.
altModePollingTimer.stop();
altModeExpirationTimer.stop();
}
return;
}
#ifdef HAVE_X11
if ( cfg.preferences.showScanFlag ) {
inputPhrase = pendingInputPhrase;
emit showScanFlag( forcePopup );
emit showScanFlag();
return;
}
#endif
// Check key modifiers
if ( cfg.preferences.enableScanPopupModifiers && !checkModifiersPressed( cfg.preferences.scanPopupModifiers ) )
{
if ( cfg.preferences.scanPopupAltMode )
{
altModePollingTimer.start();
altModeExpirationTimer.start();
}
return;
}
inputPhrase = pendingInputPhrase;
engagePopup( forcePopup );
}
@ -1123,31 +1079,6 @@ void ScanPopup::hideTimerExpired()
hideWindow();
}
void ScanPopup::altModeExpired()
{
// The alt mode duration has expired, so there's no need to poll for modifiers
// anymore.
altModePollingTimer.stop();
}
void ScanPopup::altModePoll()
{
if ( !pendingInputPhrase.isValid() )
{
altModePollingTimer.stop();
altModeExpirationTimer.stop();
}
else
if ( checkModifiersPressed( cfg.preferences.scanPopupModifiers ) )
{
altModePollingTimer.stop();
altModeExpirationTimer.stop();
inputPhrase = pendingInputPhrase;
engagePopup( false );
}
}
void ScanPopup::pageLoaded( ArticleView * )
{
if( !isVisible() )
@ -1342,3 +1273,13 @@ void ScanPopup::titleChanged( ArticleView *, QString const & title )
ui.sendWordToFavoritesButton->setIcon( isWordPresentedInFavorites( title, groupId ) ?
blueStarIcon : starIcon );
}
#ifdef HAVE_X11
void ScanPopup::showScanFlag(){
scanFlag->showScanFlag();
}
void ScanPopup::hideScanFlag(){
scanFlag->hideWindow();
}
#endif

View file

@ -53,6 +53,13 @@ public:
void setDictionaryIconSize();
void saveConfigData();
#ifdef HAVE_X11
/// Interaction with scan flag window
void showScanFlag();
void hideScanFlag();
#endif
signals:
/// Forwarded from the dictionary bar, so that main window could act on this.
@ -79,12 +86,6 @@ signals:
/// Check is word already presented in Favorites
bool isWordPresentedInFavorites( QString const & word, unsigned groupId );
#ifdef HAVE_X11
/// Interaction with scan flag window
void showScanFlag( bool forcePopup );
void hideScanFlag();
#endif
#ifdef Q_OS_WIN32
/// Ask for source window is current translate tab
bool isGoldenDictWindow( HWND hwnd );
@ -156,7 +157,6 @@ private:
QTimer hideTimer; // When mouse leaves the window, a grace period is
// given for it to return back. If it doesn't before
// this timer expires, the window gets hidden.
QTimer altModeExpirationTimer, altModePollingTimer; // Timers for alt mode
QTimer mouseGrabPollTimer;
@ -208,8 +208,6 @@ private slots:
void on_goForwardButton_clicked();
void hideTimerExpired();
void altModeExpired();
void altModePoll();
/// Called repeatedly once the popup is initially engaged and we monitor the
/// mouse as it may move away from the window. This simulates mouse grab, in