mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Add support for zooming fonts in word list and translate line.
This commit is contained in:
parent
da991187ed
commit
71519ff19b
10
config.cc
10
config.cc
|
@ -105,7 +105,8 @@ Preferences::Preferences():
|
||||||
#endif
|
#endif
|
||||||
checkForNewReleases( true ),
|
checkForNewReleases( true ),
|
||||||
disallowContentFromOtherSites( false ),
|
disallowContentFromOtherSites( false ),
|
||||||
zoomFactor( 1 )
|
zoomFactor( 1 ),
|
||||||
|
wordsZoomLevel( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -521,6 +522,9 @@ Class load() throw( exError )
|
||||||
if ( !preferences.namedItem( "zoomFactor" ).isNull() )
|
if ( !preferences.namedItem( "zoomFactor" ).isNull() )
|
||||||
c.preferences.zoomFactor = preferences.namedItem( "zoomFactor" ).toElement().text().toDouble();
|
c.preferences.zoomFactor = preferences.namedItem( "zoomFactor" ).toElement().text().toDouble();
|
||||||
|
|
||||||
|
if ( !preferences.namedItem( "wordsZoomLevel" ).isNull() )
|
||||||
|
c.preferences.wordsZoomLevel = preferences.namedItem( "wordsZoomLevel" ).toElement().text().toInt();
|
||||||
|
|
||||||
applyBoolOption( c.preferences.enableMainWindowHotkey, preferences.namedItem( "enableMainWindowHotkey" ) );
|
applyBoolOption( c.preferences.enableMainWindowHotkey, preferences.namedItem( "enableMainWindowHotkey" ) );
|
||||||
if ( !preferences.namedItem( "mainWindowHotkey" ).isNull() )
|
if ( !preferences.namedItem( "mainWindowHotkey" ).isNull() )
|
||||||
c.preferences.mainWindowHotkey = QKeySequence::fromString( preferences.namedItem( "mainWindowHotkey" ).toElement().text() );
|
c.preferences.mainWindowHotkey = QKeySequence::fromString( preferences.namedItem( "mainWindowHotkey" ).toElement().text() );
|
||||||
|
@ -926,6 +930,10 @@ void save( Class const & c ) throw( exError )
|
||||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.zoomFactor ) ) );
|
opt.appendChild( dd.createTextNode( QString::number( c.preferences.zoomFactor ) ) );
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
|
opt = dd.createElement( "wordsZoomLevel" );
|
||||||
|
opt.appendChild( dd.createTextNode( QString::number( c.preferences.wordsZoomLevel ) ) );
|
||||||
|
preferences.appendChild( opt );
|
||||||
|
|
||||||
opt = dd.createElement( "enableMainWindowHotkey" );
|
opt = dd.createElement( "enableMainWindowHotkey" );
|
||||||
opt.appendChild( dd.createTextNode( c.preferences.enableMainWindowHotkey ? "1":"0" ) );
|
opt.appendChild( dd.createTextNode( c.preferences.enableMainWindowHotkey ? "1":"0" ) );
|
||||||
preferences.appendChild( opt );
|
preferences.appendChild( opt );
|
||||||
|
|
|
@ -165,6 +165,7 @@ struct Preferences
|
||||||
bool disallowContentFromOtherSites;
|
bool disallowContentFromOtherSites;
|
||||||
|
|
||||||
qreal zoomFactor;
|
qreal zoomFactor;
|
||||||
|
int wordsZoomLevel;
|
||||||
|
|
||||||
Preferences();
|
Preferences();
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,6 +49,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
|
|
||||||
ui.setupUi( this );
|
ui.setupUi( this );
|
||||||
|
|
||||||
|
wordListDefaultFont = ui.wordList->font();
|
||||||
|
translateLineDefaultFont = ui.translateLine->font();
|
||||||
|
|
||||||
// Make the search pane's titlebar
|
// Make the search pane's titlebar
|
||||||
|
|
||||||
groupLabel.setText( tr( "Look up in:" ) );
|
groupLabel.setText( tr( "Look up in:" ) );
|
||||||
|
@ -94,8 +97,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
// zooming
|
// zooming
|
||||||
navToolbar->addSeparator();
|
navToolbar->addSeparator();
|
||||||
zoomIn = navToolbar->addAction( QIcon( ":/icons/icon32_zoomin.png" ), tr( "Zoom In" ) );
|
zoomIn = navToolbar->addAction( QIcon( ":/icons/icon32_zoomin.png" ), tr( "Zoom In" ) );
|
||||||
|
zoomIn->setShortcut( QKeySequence::ZoomIn );
|
||||||
zoomOut = navToolbar->addAction( QIcon( ":/icons/icon32_zoomout.png" ), tr( "Zoom Out" ) );
|
zoomOut = navToolbar->addAction( QIcon( ":/icons/icon32_zoomout.png" ), tr( "Zoom Out" ) );
|
||||||
|
zoomOut->setShortcut( QKeySequence::ZoomOut );
|
||||||
zoomBase = navToolbar->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Normal Size" ) );
|
zoomBase = navToolbar->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Normal Size" ) );
|
||||||
|
zoomBase->setShortcut( QKeySequence( "Ctrl+0" ) );
|
||||||
|
|
||||||
connect( zoomIn, SIGNAL( triggered() ),
|
connect( zoomIn, SIGNAL( triggered() ),
|
||||||
this, SLOT( zoomin() ) );
|
this, SLOT( zoomin() ) );
|
||||||
|
@ -104,6 +110,23 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
connect( zoomBase, SIGNAL( triggered() ),
|
connect( zoomBase, SIGNAL( triggered() ),
|
||||||
this, SLOT( unzoom() ) );
|
this, SLOT( unzoom() ) );
|
||||||
|
|
||||||
|
ui.menuZoom->addAction( zoomIn );
|
||||||
|
ui.menuZoom->addAction( zoomOut );
|
||||||
|
ui.menuZoom->addAction( zoomBase );
|
||||||
|
|
||||||
|
ui.menuZoom->addSeparator();
|
||||||
|
|
||||||
|
wordsZoomIn = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoomin.png" ), tr( "Words Zoom In" ) );
|
||||||
|
wordsZoomIn->setShortcut( QKeySequence( "Alt++" ) );
|
||||||
|
wordsZoomOut = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoomout.png" ), tr( "Words Zoom Out" ) );
|
||||||
|
wordsZoomOut->setShortcut( QKeySequence( "Alt+-" ) );
|
||||||
|
wordsZoomBase = ui.menuZoom->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Words Normal Size" ) );
|
||||||
|
wordsZoomBase->setShortcut( QKeySequence( "Alt+0" ) );
|
||||||
|
|
||||||
|
connect( wordsZoomIn, SIGNAL(triggered()), this, SLOT(doWordsZoomIn()) );
|
||||||
|
connect( wordsZoomOut, SIGNAL(triggered()), this, SLOT(doWordsZoomOut()) );
|
||||||
|
connect( wordsZoomBase, SIGNAL(triggered()), this, SLOT(doWordsZoomBase()) );
|
||||||
|
|
||||||
// tray icon
|
// tray icon
|
||||||
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), SIGNAL( activated() ),
|
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), SIGNAL( activated() ),
|
||||||
this, SLOT( showMainWindow() ) );
|
this, SLOT( showMainWindow() ) );
|
||||||
|
@ -329,6 +352,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
||||||
|
|
||||||
// Update zoomers
|
// Update zoomers
|
||||||
applyZoomFactor();
|
applyZoomFactor();
|
||||||
|
applyWordsZoomLevel();
|
||||||
|
|
||||||
// Update autostart info
|
// Update autostart info
|
||||||
setAutostart(cfg.preferences.autoStart);
|
setAutostart(cfg.preferences.autoStart);
|
||||||
|
@ -1811,3 +1835,63 @@ void MainWindow::applyZoomFactor()
|
||||||
if ( scanPopup.get() )
|
if ( scanPopup.get() )
|
||||||
scanPopup->applyZoomFactor();
|
scanPopup->applyZoomFactor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::doWordsZoomIn()
|
||||||
|
{
|
||||||
|
++cfg.preferences.wordsZoomLevel;
|
||||||
|
|
||||||
|
applyWordsZoomLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::doWordsZoomOut()
|
||||||
|
{
|
||||||
|
--cfg.preferences.wordsZoomLevel;
|
||||||
|
|
||||||
|
applyWordsZoomLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::doWordsZoomBase()
|
||||||
|
{
|
||||||
|
cfg.preferences.wordsZoomLevel = 0;
|
||||||
|
|
||||||
|
applyWordsZoomLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::applyWordsZoomLevel()
|
||||||
|
{
|
||||||
|
QFont font( wordListDefaultFont );
|
||||||
|
|
||||||
|
int ps = font.pointSize();
|
||||||
|
|
||||||
|
if ( cfg.preferences.wordsZoomLevel != 0 )
|
||||||
|
{
|
||||||
|
ps += cfg.preferences.wordsZoomLevel;
|
||||||
|
|
||||||
|
if ( ps < 1 )
|
||||||
|
ps = 1;
|
||||||
|
|
||||||
|
font.setPointSize( ps );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ui.wordList->font().pointSize() != ps )
|
||||||
|
ui.wordList->setFont( font );
|
||||||
|
|
||||||
|
font = translateLineDefaultFont;
|
||||||
|
|
||||||
|
ps = font.pointSize();
|
||||||
|
|
||||||
|
if ( cfg.preferences.wordsZoomLevel != 0 )
|
||||||
|
{
|
||||||
|
ps += cfg.preferences.wordsZoomLevel;
|
||||||
|
|
||||||
|
if ( ps < 1 )
|
||||||
|
ps = 1;
|
||||||
|
|
||||||
|
font.setPointSize( ps );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ui.translateLine->font().pointSize() != ps )
|
||||||
|
ui.translateLine->setFont( font );
|
||||||
|
|
||||||
|
wordsZoomBase->setEnabled( cfg.preferences.wordsZoomLevel != 0 );
|
||||||
|
}
|
||||||
|
|
|
@ -54,11 +54,15 @@ private:
|
||||||
QLabel groupLabel;
|
QLabel groupLabel;
|
||||||
GroupComboBox groupList;
|
GroupComboBox groupList;
|
||||||
|
|
||||||
|
/// Fonts saved before words zooming is in effect, so it could be reset back.
|
||||||
|
QFont wordListDefaultFont, translateLineDefaultFont;
|
||||||
|
|
||||||
QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction,
|
QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction,
|
||||||
switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction;
|
switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction;
|
||||||
QToolBar * navToolbar;
|
QToolBar * navToolbar;
|
||||||
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
|
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
|
||||||
QAction * zoomIn, * zoomOut, * zoomBase;
|
QAction * zoomIn, * zoomOut, * zoomBase;
|
||||||
|
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
||||||
QMenu trayIconMenu;
|
QMenu trayIconMenu;
|
||||||
QToolButton addTab;
|
QToolButton addTab;
|
||||||
Config::Class & cfg;
|
Config::Class & cfg;
|
||||||
|
@ -180,6 +184,12 @@ private slots:
|
||||||
void zoomout();
|
void zoomout();
|
||||||
void unzoom();
|
void unzoom();
|
||||||
|
|
||||||
|
void doWordsZoomIn();
|
||||||
|
void doWordsZoomOut();
|
||||||
|
void doWordsZoomBase();
|
||||||
|
|
||||||
|
void applyWordsZoomLevel();
|
||||||
|
|
||||||
/// If editDictionaryGroup is specified, the dialog positions on that group
|
/// If editDictionaryGroup is specified, the dialog positions on that group
|
||||||
/// initially.
|
/// initially.
|
||||||
void editDictionaries( unsigned editDictionaryGroup = Instances::Group::NoGroupId );
|
void editDictionaries( unsigned editDictionaryGroup = Instances::Group::NoGroupId );
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>653</width>
|
<width>653</width>
|
||||||
<height>21</height>
|
<height>23</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QMenu" name="menuFile">
|
<widget class="QMenu" name="menuFile">
|
||||||
|
@ -96,6 +96,12 @@
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>&View</string>
|
<string>&View</string>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QMenu" name="menuZoom">
|
||||||
|
<property name="title">
|
||||||
|
<string>&Zoom</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
<addaction name="menuZoom"/>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenu" name="menuHistory">
|
<widget class="QMenu" name="menuHistory">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
|
|
Loading…
Reference in a new issue