mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24:05 +00:00
+ Basic preferences and their editing added.
+ Basic tray icon support added. + Program icon added (one of the Qt Linguist icons, actually).
This commit is contained in:
parent
bbc9901cce
commit
5d5a393265
|
@ -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() );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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
|
||||
|
|
BIN
src/icons/programicon.png
Normal file
BIN
src/icons/programicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -2,6 +2,7 @@
|
|||
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
|
||||
|
||||
#include <QApplication>
|
||||
#include <QIcon>
|
||||
#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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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 <QMessageBox>
|
||||
#include <QIcon>
|
||||
#include <QToolBar>
|
||||
#include <QCloseEvent>
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <QMainWindow>
|
||||
#include <QThread>
|
||||
#include <QToolButton>
|
||||
#include <QSystemTrayIcon>
|
||||
#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
|
||||
|
|
|
@ -246,6 +246,7 @@
|
|||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="quit"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Edit">
|
||||
<property name="title">
|
||||
|
@ -253,9 +254,19 @@
|
|||
</property>
|
||||
<addaction name="sources"/>
|
||||
<addaction name="groups"/>
|
||||
<addaction name="preferences"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menu_Help">
|
||||
<property name="title">
|
||||
<string>&Help</string>
|
||||
</property>
|
||||
<addaction name="openWebsite"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="about"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menu_Edit"/>
|
||||
<addaction name="menu_Help"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
<action name="action_Preferences">
|
||||
|
@ -273,6 +284,26 @@
|
|||
<string>&Groups...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="preferences">
|
||||
<property name="text">
|
||||
<string>&Preferences...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="openWebsite">
|
||||
<property name="text">
|
||||
<string>Program's &website</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="about">
|
||||
<property name="text">
|
||||
<string>&About</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="quit">
|
||||
<property name="text">
|
||||
<string>&Quit</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
145
src/preferences.cc
Normal file
145
src/preferences.cc
Normal file
|
@ -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 );
|
||||
}
|
38
src/preferences.hh
Normal file
38
src/preferences.hh
Normal file
|
@ -0,0 +1,38 @@
|
|||
#ifndef __PREFERENCES_HH_INCLUDED__
|
||||
#define __PREFERENCES_HH_INCLUDED__
|
||||
|
||||
#include <QDialog>
|
||||
#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
|
||||
|
316
src/preferences.ui
Normal file
316
src/preferences.ui
Normal file
|
@ -0,0 +1,316 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Preferences</class>
|
||||
<widget class="QDialog" name="Preferences">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>395</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Preferences</string>
|
||||
</property>
|
||||
<property name="modal">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="enableTrayIcon">
|
||||
<property name="toolTip">
|
||||
<string>When enabled, an icon appears in the sytem tray area which can be used
|
||||
to open main window and perform other tasks.</string>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Enable system tray icon</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="startToTray">
|
||||
<property name="toolTip">
|
||||
<string>With this on, the application starts directly to system tray without showing
|
||||
its main window.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start to system tray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="closeToTray">
|
||||
<property name="toolTip">
|
||||
<string>With this on, an attempt to close main window would hide it instead of closing
|
||||
the application.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Close to system tray</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="enableScanPopup">
|
||||
<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>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Scan popup functionality</string>
|
||||
</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="enableScanPopupModifiers">
|
||||
<property name="toolTip">
|
||||
<string>With this enabled, the popup would only show up if all chosen keys are
|
||||
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>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="scanPopupModifiers">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="leftCtrl">
|
||||
<property name="toolTip">
|
||||
<string>Left Ctrl only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Left Ctrl</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QCheckBox" name="rightShift">
|
||||
<property name="toolTip">
|
||||
<string>Right Shift only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Right Shift</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QCheckBox" name="altKey">
|
||||
<property name="toolTip">
|
||||
<string>Alt key</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Alt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QCheckBox" name="ctrlKey">
|
||||
<property name="toolTip">
|
||||
<string>Ctrl key</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Ctrl</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="leftAlt">
|
||||
<property name="toolTip">
|
||||
<string>Left Alt only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Left Alt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="shiftKey">
|
||||
<property name="toolTip">
|
||||
<string>Shift key</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Shift</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="rightAlt">
|
||||
<property name="toolTip">
|
||||
<string>Right Alt only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Right Alt</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="rightCtrl">
|
||||
<property name="toolTip">
|
||||
<string>Right Ctrl only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Right Ctrl</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QCheckBox" name="leftShift">
|
||||
<property name="toolTip">
|
||||
<string>Left Shift only</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Left Shift</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QCheckBox" name="winKey">
|
||||
<property name="toolTip">
|
||||
<string>Windows key or Meta key</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Win/Meta</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::NoFrame</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<property name="margin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>Preferences</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>Preferences</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
|
@ -8,5 +8,6 @@
|
|||
<file>icons/addtab.png</file>
|
||||
<file>icons/next.png</file>
|
||||
<file>icons/previous.png</file>
|
||||
<file>icons/programicon.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -13,10 +13,12 @@
|
|||
using std::wstring;
|
||||
|
||||
ScanPopup::ScanPopup( QWidget * parent,
|
||||
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 );
|
||||
setWindowTitle( elideInputWord() );
|
||||
}
|
||||
else
|
||||
setWindowFlags( Qt::Popup );
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "articleview.hh"
|
||||
#include "wordfinder.hh"
|
||||
#include "keyboardstate.hh"
|
||||
#include "config.hh"
|
||||
#include "ui_scanpopup.h"
|
||||
#include <QDialog>
|
||||
#include <QClipboard>
|
||||
|
@ -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 );
|
||||
|
|
Loading…
Reference in a new issue