From 5d5a39326534dcb2b1a26c72951a290f570b6651 Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Thu, 5 Feb 2009 20:55:00 +0000 Subject: [PATCH] + Basic preferences and their editing added. + Basic tray icon support added. + Program icon added (one of the Qt Linguist icons, actually). --- src/config.cc | 51 ++++++ src/config.hh | 14 ++ src/goldendict.pro | 8 +- src/icons/programicon.png | Bin 0 -> 1109 bytes src/main.cc | 5 +- src/mainwindow.cc | 81 +++++++++- src/mainwindow.hh | 12 ++ src/mainwindow.ui | 31 ++++ src/preferences.cc | 145 +++++++++++++++++ src/preferences.hh | 38 +++++ src/preferences.ui | 316 ++++++++++++++++++++++++++++++++++++++ src/resources.qrc | 1 + src/scanpopup.cc | 31 ++-- src/scanpopup.hh | 6 + 14 files changed, 723 insertions(+), 16 deletions(-) create mode 100644 src/icons/programicon.png create mode 100644 src/preferences.cc create mode 100644 src/preferences.hh create mode 100644 src/preferences.ui diff --git a/src/config.cc b/src/config.cc index 78efac4c..6c82ad07 100644 --- a/src/config.cc +++ b/src/config.cc @@ -36,6 +36,16 @@ namespace } } +Preferences::Preferences(): + enableTrayIcon( false ), + startToTray( false ), + enableScanPopup( false ), + enableScanPopupModifiers( false ), + scanPopupModifiers( 0 ) +{ +} + + Class load() throw( exError ) { QString configName = getConfigFileName(); @@ -113,6 +123,18 @@ Class load() throw( exError ) } } + QDomNode preferences = root.namedItem( "preferences" ); + + if ( !preferences.isNull() ) + { + c.preferences.enableTrayIcon = ( preferences.namedItem( "enableTrayIcon" ).toElement().text() == "1" ); + c.preferences.startToTray = ( preferences.namedItem( "startToTray" ).toElement().text() == "1" ); + c.preferences.closeToTray = ( preferences.namedItem( "closeToTray" ).toElement().text() == "1" ); + c.preferences.enableScanPopup = ( preferences.namedItem( "enableScanPopup" ).toElement().text() == "1" ); + c.preferences.enableScanPopupModifiers = ( preferences.namedItem( "enableScanPopupModifiers" ).toElement().text() == "1" ); + c.preferences.scanPopupModifiers = ( preferences.namedItem( "scanPopupModifiers" ).toElement().text().toULong() ); + } + return c; } @@ -180,6 +202,35 @@ void save( Class const & c ) throw( exError ) } } + { + QDomElement preferences = dd.createElement( "preferences" ); + root.appendChild( preferences ); + + QDomElement opt = dd.createElement( "enableTrayIcon" ); + opt.appendChild( dd.createTextNode( c.preferences.enableTrayIcon ? "1":"0" ) ); + preferences.appendChild( opt ); + + opt = dd.createElement( "startToTray" ); + opt.appendChild( dd.createTextNode( c.preferences.startToTray ? "1":"0" ) ); + preferences.appendChild( opt ); + + opt = dd.createElement( "closeToTray" ); + opt.appendChild( dd.createTextNode( c.preferences.closeToTray ? "1":"0" ) ); + preferences.appendChild( opt ); + + opt = dd.createElement( "enableScanPopup" ); + opt.appendChild( dd.createTextNode( c.preferences.enableScanPopup ? "1":"0" ) ); + preferences.appendChild( opt ); + + opt = dd.createElement( "enableScanPopupModifiers" ); + opt.appendChild( dd.createTextNode( c.preferences.enableScanPopupModifiers ? "1":"0" ) ); + preferences.appendChild( opt ); + + opt = dd.createElement( "scanPopupModifiers" ); + opt.appendChild( dd.createTextNode( QString::number( c.preferences.scanPopupModifiers ) ) ); + preferences.appendChild( opt ); + } + configFile.write( dd.toByteArray() ); } diff --git a/src/config.hh b/src/config.hh index a0533e0f..cf23cfe4 100644 --- a/src/config.hh +++ b/src/config.hh @@ -26,10 +26,24 @@ struct Group /// All the groups typedef vector< Group > Groups; +/// Various user preferences +struct Preferences +{ + bool enableTrayIcon; + bool startToTray; + bool closeToTray; + bool enableScanPopup; + bool enableScanPopupModifiers; + unsigned long scanPopupModifiers; // Combination of KeyboardState::Modifier + + Preferences(); +}; + struct Class { Paths paths; Groups groups; + Preferences preferences; }; DEF_EX( exError, "Error with the program's configuration", std::exception ) diff --git a/src/goldendict.pro b/src/goldendict.pro index 960ce4b6..a0b11f00 100644 --- a/src/goldendict.pro +++ b/src/goldendict.pro @@ -65,11 +65,12 @@ HEADERS += folding.hh \ groupcombobox.hh \ griparea.hh \ keyboardstate.hh \ - mouseover.hh + mouseover.hh \ + preferences.hh FORMS += groups.ui dictgroupwidget.ui mainwindow.ui sources.ui initializing.ui\ - groupselectorwidget.ui scanpopup.ui articleview.ui + groupselectorwidget.ui scanpopup.ui articleview.ui preferences.ui SOURCES += folding.cc main.cc dictionary.cc md5.c config.cc sources.cc \ mainwindow.cc utf8.cc file.cc bgl_babylon.cc bgl.cc initializing.cc \ @@ -78,7 +79,8 @@ SOURCES += folding.cc main.cc dictionary.cc md5.c config.cc sources.cc \ dsl.cc dsl_details.cc filetype.cc fsencoding.cc groups.cc \ groups_widgets.cc instances.cc article_maker.cc scanpopup.cc \ articleview.cc externalviewer.cc dictlock.cc wordfinder.cc \ - groupcombobox.cc griparea.cc keyboardstate.cc mouseover.cc + groupcombobox.cc griparea.cc keyboardstate.cc mouseover.cc \ + preferences.cc win32 { SOURCES += mouseover_win32/ThTypes.c diff --git a/src/icons/programicon.png b/src/icons/programicon.png new file mode 100644 index 0000000000000000000000000000000000000000..09ec4d33f7bb3ba78fe5d76832e230b570188eec GIT binary patch literal 1109 zcmV-b1giUqP)ZJNNHUCL|*bkSK|t+Pw-z^1@61g@yekOHXmP{IVCrZ3~xFKL|H+A zMtt!i1LCtzY03%^;M)_3=izMWrSIj}cD_0A)LVmV6Hih{ektE;XMr+phobIC8|Ca;!UL1ZCYk*l*=IX8JlzW(Nj%q`?)B@-7HKcW#ZVg^7-q* z5AV3hp2wDTJxiN4Gn9PDXBWxm=E!BPlUtZ!K6!;p7tWDOCs|2L$YL&;B+#6}u-E|% zHZ)L*XfZnl#86cb5frtE4=@rBO@amIPew8*%?~e`jCnc?`mE%*sV7JhPEB&(XiW$+rAwD+it>f972wZ zW4TziO>GW#t%h6|fbsEhcJKa}g9k^Lo}OmIzyOK$UBn(9!m_%Ecdm)_#DarBOTbXo zZp(_2@nWPFgiYKN}l6eSKk(tyLeN z+rSqjWMU3I(*1m@oQPsrL^}%1%qD*rJ)fPhn$Swn0KzR=qc5jen40AxaOU=j0BeB& zAT*M#>sdY2@4j!Ef!NqoZu00K)eFFHz$L)oP8!Gn+57(JE2T`JA8>)oA~MZ=c;J5( bng{G}W!lqy1LmiU00000NkvXXu0mjf$HfGj literal 0 HcmV?d00001 diff --git a/src/main.cc b/src/main.cc index 6cbb7a55..0b246d6a 100644 --- a/src/main.cc +++ b/src/main.cc @@ -2,6 +2,7 @@ * Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */ #include +#include #include "mainwindow.hh" #include "config.hh" @@ -9,6 +10,8 @@ int main( int argc, char ** argv ) { QApplication app( argc, argv ); + app.setWindowIcon( QIcon( ":/icons/programicon.png" ) ); + // Try loading a style sheet if there's one #if 1 @@ -21,8 +24,6 @@ int main( int argc, char ** argv ) MainWindow m; - m.show(); - return app.exec(); } diff --git a/src/mainwindow.cc b/src/mainwindow.cc index bec2485a..4eb9d896 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -4,6 +4,7 @@ #include "mainwindow.hh" #include "sources.hh" #include "groups.hh" +#include "preferences.hh" #include "bgl.hh" #include "stardict.hh" #include "lsa.hh" @@ -13,6 +14,7 @@ #include #include #include +#include #include #include @@ -22,6 +24,7 @@ using std::map; using std::pair; MainWindow::MainWindow(): + trayIcon( 0 ), addTab( this ), cfg( Config::load() ), articleMaker( dictionaries, groupInstances ), @@ -29,6 +32,12 @@ MainWindow::MainWindow(): wordFinder( this ), initializing( 0 ) { + // Show tray icon as early as possible so the user would be happy + updateTrayIcon(); + + if ( trayIcon ) + trayIcon->setToolTip( tr( "Loading..." ) ); + ui.setupUi( this ); // Make the toolbar @@ -60,12 +69,18 @@ MainWindow::MainWindow(): ui.tabWidget->setTabsClosable( true ); + connect( ui.quit, SIGNAL( activated() ), + qApp, SLOT( quit() ) ); + connect( ui.sources, SIGNAL( activated() ), this, SLOT( editSources() ) ); connect( ui.groups, SIGNAL( activated() ), this, SLOT( editGroups() ) ); + connect( ui.preferences, SIGNAL( activated() ), + this, SLOT( editPreferences() ) ); + connect( ui.translateLine, SIGNAL( textChanged( QString const & ) ), this, SLOT( translateInputChanged( QString const & ) ) ); @@ -80,6 +95,12 @@ MainWindow::MainWindow(): addNewTab(); ui.translateLine->setFocus(); + + updateTrayIcon(); + + // Only show window initially if it wasn't configured differently + if ( !cfg.preferences.enableTrayIcon || !cfg.preferences.startToTray ) + show(); } LoadDictionaries::LoadDictionaries( vector< string > const & allFiles_ ): @@ -131,6 +152,41 @@ void LoadDictionaries::indexingDictionary( string const & dictionaryName ) throw emit indexingDictionarySignal( QString::fromUtf8( dictionaryName.c_str() ) ); } +void MainWindow::updateTrayIcon() +{ + if ( !trayIcon && cfg.preferences.enableTrayIcon ) + { + // Need to show it + trayIcon = new QSystemTrayIcon( QIcon( ":/icons/programicon.png" ), this ); + trayIcon->show(); + + connect( trayIcon, SIGNAL( activated( QSystemTrayIcon::ActivationReason ) ), + this, SLOT( trayIconActivated( QSystemTrayIcon::ActivationReason ) ) ); + } + else + if ( trayIcon && !cfg.preferences.enableTrayIcon ) + { + // Need to hide it + delete trayIcon; + + trayIcon = 0; + } + + if ( trayIcon ) + trayIcon->setToolTip( "GoldenDict" ); +} + +void MainWindow::closeEvent( QCloseEvent * ev ) +{ + if ( cfg.preferences.enableTrayIcon && cfg.preferences.closeToTray ) + { + ev->ignore(); + hide(); + } + else + ev->accept(); +} + void MainWindow::makeDictionaries() { { @@ -255,7 +311,7 @@ void MainWindow::makeScanPopup() { scanPopup.reset(); - scanPopup = new ScanPopup( 0, articleNetMgr, dictionaries, groupInstances ); + scanPopup = new ScanPopup( 0, cfg, articleNetMgr, dictionaries, groupInstances ); } vector< sptr< Dictionary::Class > > const & MainWindow::getActiveDicts() @@ -379,6 +435,20 @@ void MainWindow::editGroups() makeScanPopup(); } +void MainWindow::editPreferences() +{ + Preferences preferences( this, cfg.preferences ); + + preferences.show(); + + if ( preferences.exec() == QDialog::Accepted ) + { + cfg.preferences = preferences.getPreferences(); + updateTrayIcon(); + Config::save( cfg ); + } +} + void MainWindow::translateInputChanged( QString const & newValue ) { QString req = newValue.trimmed(); @@ -539,3 +609,12 @@ void MainWindow::showTranslationFor( QString const & inWord ) //ui.tabWidget->setTabText( ui.tabWidget->indexOf(ui.tab), inWord.trimmed() ); } + +void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason ) +{ + if ( !isVisible() ) + show(); + else + hide(); +} + diff --git a/src/mainwindow.hh b/src/mainwindow.hh index 6be5750e..892ffafc 100644 --- a/src/mainwindow.hh +++ b/src/mainwindow.hh @@ -7,6 +7,7 @@ #include #include #include +#include #include "ui_mainwindow.h" #include "folding.hh" #include "config.hh" @@ -58,6 +59,8 @@ public: private: + QSystemTrayIcon * trayIcon; + Ui::MainWindow ui; QToolBar * navToolbar; QAction * navBack, * navForward; @@ -74,6 +77,12 @@ private: ::Initializing * initializing; + /// Creates, destroys or otherwise updates tray icon, according to the + /// current configuration and situation. + void updateTrayIcon(); + + void closeEvent( QCloseEvent * ); + void makeDictionaries(); void updateStatusLine(); void updateGroupList(); @@ -101,6 +110,7 @@ private slots: void editSources(); void editGroups(); + void editPreferences(); void indexingDictionary( QString dictionaryName ); void translateInputChanged( QString const & ); @@ -108,6 +118,8 @@ private slots: void wordListItemActivated( QListWidgetItem * ); void showTranslationFor( QString const & ); + + void trayIconActivated( QSystemTrayIcon::ActivationReason ); }; #endif diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 943311fe..b8399156 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -246,6 +246,7 @@ &File + @@ -253,9 +254,19 @@ + + + + + &Help + + + + + @@ -273,6 +284,26 @@ &Groups... + + + &Preferences... + + + + + Program's &website + + + + + &About + + + + + &Quit + + diff --git a/src/preferences.cc b/src/preferences.cc new file mode 100644 index 00000000..75a63180 --- /dev/null +++ b/src/preferences.cc @@ -0,0 +1,145 @@ +#include "preferences.hh" +#include "keyboardstate.hh" + +Preferences::Preferences( QWidget * parent, Config::Preferences const & p ): + QDialog( parent ) +{ + ui.setupUi( this ); + + connect( ui.enableScanPopup, SIGNAL( toggled( bool ) ), + this, SLOT( enableScanPopupToggled( bool ) ) ); + + connect( ui.enableScanPopupModifiers, SIGNAL( toggled( bool ) ), + this, SLOT( enableScanPopupModifiersToggled( 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 ) ) ); + + // Load values into form + + ui.enableTrayIcon->setChecked( p.enableTrayIcon ); + ui.startToTray->setChecked( p.startToTray ); + ui.closeToTray->setChecked( p.closeToTray ); + ui.enableScanPopup->setChecked( p.enableScanPopup ); + 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 ); + + // 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(); +#endif +} + +Config::Preferences Preferences::getPreferences() +{ + Config::Preferences p; + + p.enableTrayIcon = ui.enableTrayIcon->isChecked( ); + p.startToTray = ui.startToTray->isChecked( ); + p.closeToTray = ui.closeToTray->isChecked( ); + p.enableScanPopup = ui.enableScanPopup->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; + + 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() ); +} + +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 ); +} diff --git a/src/preferences.hh b/src/preferences.hh new file mode 100644 index 00000000..ccab0390 --- /dev/null +++ b/src/preferences.hh @@ -0,0 +1,38 @@ +#ifndef __PREFERENCES_HH_INCLUDED__ +#define __PREFERENCES_HH_INCLUDED__ + +#include +#include "config.hh" +#include "ui_preferences.h" + +/// Preferences dialog -- allows changing various program options. +class Preferences: public QDialog +{ + Q_OBJECT + +public: + + Preferences( QWidget * parent, Config::Preferences const & ); + + Config::Preferences getPreferences(); + +private: + + Ui::Preferences ui; + +private slots: + + void enableScanPopupToggled( bool ); + void enableScanPopupModifiersToggled( bool ); + + void wholeAltClicked( bool ); + void wholeCtrlClicked( bool ); + void wholeShiftClicked( bool ); + + void sideAltClicked( bool ); + void sideCtrlClicked( bool ); + void sideShiftClicked( bool ); +}; + +#endif + diff --git a/src/preferences.ui b/src/preferences.ui new file mode 100644 index 00000000..fa3dea00 --- /dev/null +++ b/src/preferences.ui @@ -0,0 +1,316 @@ + + + Preferences + + + + 0 + 0 + 400 + 395 + + + + Preferences + + + true + + + + + + When enabled, an icon appears in the sytem tray area which can be used +to open main window and perform other tasks. + + + Enable system tray icon + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + false + + + true + + + false + + + + + + With this on, the application starts directly to system tray without showing +its main window. + + + Start to system tray + + + + + + + With this on, an attempt to close main window would hide it instead of closing +the application. + + + Close to system tray + + + + + + + + + + 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. + + + Scan popup functionality + + + true + + + false + + + + + + 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: + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + 0 + + + + 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 + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + Preferences + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Preferences + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/resources.qrc b/src/resources.qrc index 2e7c92d6..9f43c0d3 100644 --- a/src/resources.qrc +++ b/src/resources.qrc @@ -8,5 +8,6 @@ icons/addtab.png icons/next.png icons/previous.png + icons/programicon.png diff --git a/src/scanpopup.cc b/src/scanpopup.cc index 57f4fc90..be3bcf5d 100644 --- a/src/scanpopup.cc +++ b/src/scanpopup.cc @@ -13,10 +13,12 @@ using std::wstring; ScanPopup::ScanPopup( QWidget * parent, - ArticleNetworkAccessManager & articleNetMgr, + Config::Class const & cfg_, + ArticleNetworkAccessManager & articleNetMgr, std::vector< sptr< Dictionary::Class > > const & allDictionaries_, Instances::Groups const & groups_ ): QDialog( parent ), + cfg( cfg_ ), allDictionaries( allDictionaries_ ), groups( groups_ ), wordFinder( this ) @@ -81,23 +83,23 @@ void ScanPopup::mouseHovered( QString const & str ) void ScanPopup::handleInputWord( QString const & str ) { + if ( !cfg.preferences.enableScanPopup ) + return; + // Check key modifiers -#ifdef Q_OS_WIN32 - if ( !checkModifiersPressed( Ctrl ) ) + if ( cfg.preferences.enableScanPopupModifiers && + !checkModifiersPressed( cfg.preferences.scanPopupModifiers ) ) return; -#else - if ( !checkModifiersPressed( Win ) ) - return; -#endif inputWord = str.trimmed(); if ( !inputWord.size() ) return; - setWindowTitle( inputWord ); - ui.word->setText( inputWord ); + /// Too large strings make window expand which is probably not what user + /// wants + ui.word->setText( elideInputWord() ); if ( !isVisible() ) { @@ -113,6 +115,12 @@ void ScanPopup::handleInputWord( QString const & str ) initiateTranslation(); } +QString ScanPopup::elideInputWord() +{ + return inputWord.size() > 32 ? inputWord.mid( 0, 32 ) + "..." : inputWord; +} + + void ScanPopup::currentGroupChanged( QString const & ) { if ( isVisible() ) @@ -236,7 +244,10 @@ void ScanPopup::initialWordClicked() void ScanPopup::pinButtonClicked( bool checked ) { if ( checked ) - setWindowFlags( Qt::Dialog ); + { + setWindowFlags( Qt::Dialog ); + setWindowTitle( elideInputWord() ); + } else setWindowFlags( Qt::Popup ); diff --git a/src/scanpopup.hh b/src/scanpopup.hh index b4d09b91..007141db 100644 --- a/src/scanpopup.hh +++ b/src/scanpopup.hh @@ -8,6 +8,7 @@ #include "articleview.hh" #include "wordfinder.hh" #include "keyboardstate.hh" +#include "config.hh" #include "ui_scanpopup.h" #include #include @@ -21,12 +22,14 @@ class ScanPopup: public QDialog, KeyboardState public: ScanPopup( QWidget * parent, + Config::Class const & cfg, ArticleNetworkAccessManager &, std::vector< sptr< Dictionary::Class > > const & allDictionaries, Instances::Groups const & ); private: + Config::Class const & cfg; std::vector< sptr< Dictionary::Class > > const & allDictionaries; Instances::Groups const & groups; Ui::ScanPopup ui; @@ -45,6 +48,9 @@ private: void popupWordlist( vector< QString > const &, QToolButton * button ); + /// Returns inputWord, chopped with appended ... if it's too long/ + QString elideInputWord(); + private slots: void clipboardChanged( QClipboard::Mode );