diff --git a/preferences.cc b/preferences.cc index 7ca904c6..d8102939 100644 --- a/preferences.cc +++ b/preferences.cc @@ -19,9 +19,32 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ): connect( ui.enableScanPopup, SIGNAL( toggled( bool ) ), this, SLOT( enableScanPopupToggled( bool ) ) ); + connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ), + this, SLOT( enableScanPopupModifiersToggled( bool ) ) ); + connect( ui.showScanFlag, SIGNAL( toggled( bool ) ), this, SLOT( showScanFlagToggled( bool ) ) ); + connect( ui.altKey, SIGNAL( clicked( bool ) ), + this, SLOT( wholeAltClicked( bool ) ) ); + connect( ui.ctrlKey, SIGNAL( clicked( bool ) ), + this, SLOT( wholeCtrlClicked( bool ) ) ); + connect( ui.shiftKey, SIGNAL( clicked( bool ) ), + this, SLOT( wholeShiftClicked( bool ) ) ); + + connect( ui.leftAlt, SIGNAL( clicked( bool ) ), + this, SLOT( sideAltClicked( bool ) ) ); + connect( ui.rightAlt, SIGNAL( clicked( bool ) ), + this, SLOT( sideAltClicked( bool ) ) ); + connect( ui.leftCtrl, SIGNAL( clicked( bool ) ), + this, SLOT( sideCtrlClicked( bool ) ) ); + connect( ui.rightCtrl, SIGNAL( clicked( bool ) ), + this, SLOT( sideCtrlClicked( bool ) ) ); + connect( ui.leftShift, SIGNAL( clicked( bool ) ), + this, SLOT( sideShiftClicked( bool ) ) ); + connect( ui.rightShift, SIGNAL( clicked( bool ) ), + this, SLOT( sideShiftClicked( bool ) ) ); + connect( ui.buttonBox, SIGNAL( helpRequested() ), this, SLOT( helpRequested() ) ); @@ -169,7 +192,21 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ): ui.enableScanPopup->setChecked( p.enableScanPopup ); ui.startWithScanPopupOn->setChecked( p.startWithScanPopupOn ); + ui.enableScanPopupModifiers->setChecked( p.enableScanPopupModifiers ); + ui.altKey->setChecked( p.scanPopupModifiers & KeyboardState::Alt ); + ui.ctrlKey->setChecked( p.scanPopupModifiers & KeyboardState::Ctrl ); + ui.shiftKey->setChecked( p.scanPopupModifiers & KeyboardState::Shift ); + ui.winKey->setChecked( p.scanPopupModifiers & KeyboardState::Win ); + ui.leftAlt->setChecked( p.scanPopupModifiers & KeyboardState::LeftAlt ); + ui.rightAlt->setChecked( p.scanPopupModifiers & KeyboardState::RightAlt ); + ui.leftCtrl->setChecked( p.scanPopupModifiers & KeyboardState::LeftCtrl ); + ui.rightCtrl->setChecked( p.scanPopupModifiers & KeyboardState::RightCtrl ); + 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 ); @@ -199,6 +236,22 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ): // Different platforms have different keys available +#ifdef Q_OS_WIN32 + ui.winKey->hide(); +#else + ui.leftAlt->hide(); + ui.rightAlt->hide(); + ui.leftCtrl->hide(); + ui.rightCtrl->hide(); + ui.leftShift->hide(); + ui.rightShift->hide(); +#ifdef Q_OS_MAC + ui.altKey->setText( "Opt" ); + ui.winKey->setText( "Ctrl" ); + ui.ctrlKey->setText( "Cmd" ); +#endif +#endif + //Platform-specific options #ifdef HAVE_X11 @@ -356,7 +409,21 @@ Config::Preferences Preferences::getPreferences() p.enableScanPopup = ui.enableScanPopup->isChecked(); p.startWithScanPopupOn = ui.startWithScanPopupOn->isChecked(); + p.enableScanPopupModifiers = ui.enableScanPopupModifiers->isChecked(); + p.scanPopupModifiers += ui.altKey->isChecked() ? KeyboardState::Alt : 0; + p.scanPopupModifiers += ui.ctrlKey->isChecked() ? KeyboardState::Ctrl: 0; + p.scanPopupModifiers += ui.shiftKey->isChecked() ? KeyboardState::Shift: 0; + p.scanPopupModifiers += ui.winKey->isChecked() ? KeyboardState::Win: 0; + p.scanPopupModifiers += ui.leftAlt->isChecked() ? KeyboardState::LeftAlt: 0; + p.scanPopupModifiers += ui.rightAlt->isChecked() ? KeyboardState::RightAlt: 0; + p.scanPopupModifiers += ui.leftCtrl->isChecked() ? KeyboardState::LeftCtrl: 0; + p.scanPopupModifiers += ui.rightCtrl->isChecked() ? KeyboardState::RightCtrl: 0; + 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 @@ -507,7 +574,7 @@ Config::Preferences Preferences::getPreferences() void Preferences::enableScanPopupToggled( bool b ) { - ui.scanPopupModifiers->setEnabled( b ); + ui.scanPopupModifiers->setEnabled( b && ui.enableScanPopupModifiers->isChecked() ); } void Preferences::enableScanPopupModifiersToggled( bool b ) @@ -517,6 +584,58 @@ void Preferences::enableScanPopupModifiersToggled( bool b ) ui.showScanFlag->setChecked( false ); } +void Preferences::showScanFlagToggled( bool b ) +{ + if( b ) + ui.enableScanPopupModifiers->setChecked( false ); +} + + + +void Preferences::wholeAltClicked( bool b ) +{ + if ( b ) + { + ui.leftAlt->setChecked( false ); + ui.rightAlt->setChecked( false ); + } +} + +void Preferences::wholeCtrlClicked( bool b ) +{ + if ( b ) + { + ui.leftCtrl->setChecked( false ); + ui.rightCtrl->setChecked( false ); + } +} + +void Preferences::wholeShiftClicked( bool b ) +{ + if ( b ) + { + ui.leftShift->setChecked( false ); + ui.rightShift->setChecked( false ); + } +} + +void Preferences::sideAltClicked( bool ) +{ + if ( ui.leftAlt->isChecked() || ui.rightAlt->isChecked() ) + ui.altKey->setChecked( false ); +} + +void Preferences::sideCtrlClicked( bool ) +{ + if ( ui.leftCtrl->isChecked() || ui.rightCtrl->isChecked() ) + ui.ctrlKey->setChecked( false ); +} + +void Preferences::sideShiftClicked( bool ) +{ + if ( ui.leftShift->isChecked() || ui.rightShift->isChecked() ) + ui.shiftKey->setChecked( false ); +} void Preferences::on_enableMainWindowHotkey_toggled( bool checked ) { ui.mainWindowHotkey->setEnabled( checked ); diff --git a/preferences.hh b/preferences.hh index 6c7af8e1..73147c81 100644 --- a/preferences.hh +++ b/preferences.hh @@ -35,6 +35,15 @@ private slots: void enableScanPopupToggled( bool ); void enableScanPopupModifiersToggled( bool ); + void showScanFlagToggled( bool b ); + + void wholeAltClicked( bool ); + void wholeCtrlClicked( bool ); + void wholeShiftClicked( bool ); + + void sideAltClicked( bool ); + void sideCtrlClicked( bool ); + void sideShiftClicked( bool ); void on_enableMainWindowHotkey_toggled( bool checked ); void on_enableClipboardHotkey_toggled( bool checked ); diff --git a/preferences.ui b/preferences.ui index dca026a2..07184512 100644 --- a/preferences.ui +++ b/preferences.ui @@ -452,6 +452,17 @@ the program would always start with the scan popup active. + + + + With this enabled, the popup would only show up if all chosen keys are +in the pressed state when the word selection changes. + + + Only show popup when all selected keys are kept pressed: + + + @@ -476,9 +487,218 @@ the program would always start with the scan popup active. 0 + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Left Ctrl only + + + Left Ctrl + + + + + + + Right Shift only + + + Right Shift + + + + + + + Alt key + + + Alt + + + + + + + Ctrl key + + + Ctrl + + + + + + + Left Alt only + + + Left Alt + + + + + + + Shift key + + + Shift + + + + + + + Right Alt only + + + Right Alt + + + + + + + Right Ctrl only + + + Right Ctrl + + + + + + + Left Shift only + + + Left Shift + + + + + + + Windows key or Meta key + + + Win/Meta + + + + + + + + + QFrame::NoFrame + + + QFrame::Raised + + + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + + + 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. + + + Keys may also be pressed afterwards, within + + + + + + + To avoid false positives, the keys are only monitored +after the selection's done for a limited amount of +seconds, which is specified here. + + + false + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 1 + + + 99 + + + + + + + secs + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -1625,6 +1845,19 @@ from Stardict, Babylon and GLS dictionaries cbAutostart interfaceLanguage startWithScanPopupOn + enableScanPopupModifiers + leftCtrl + rightShift + altKey + ctrlKey + leftAlt + shiftKey + rightAlt + rightCtrl + leftShift + winKey + scanPopupAltMode + scanPopupAltModeSecs useProxyServer proxyType proxyHost