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
|
||||
checkForNewReleases( true ),
|
||||
disallowContentFromOtherSites( false ),
|
||||
zoomFactor( 1 )
|
||||
zoomFactor( 1 ),
|
||||
wordsZoomLevel( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -521,6 +522,9 @@ Class load() throw( exError )
|
|||
if ( !preferences.namedItem( "zoomFactor" ).isNull() )
|
||||
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" ) );
|
||||
if ( !preferences.namedItem( "mainWindowHotkey" ).isNull() )
|
||||
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 ) ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "wordsZoomLevel" );
|
||||
opt.appendChild( dd.createTextNode( QString::number( c.preferences.wordsZoomLevel ) ) );
|
||||
preferences.appendChild( opt );
|
||||
|
||||
opt = dd.createElement( "enableMainWindowHotkey" );
|
||||
opt.appendChild( dd.createTextNode( c.preferences.enableMainWindowHotkey ? "1":"0" ) );
|
||||
preferences.appendChild( opt );
|
||||
|
|
|
@ -165,6 +165,7 @@ struct Preferences
|
|||
bool disallowContentFromOtherSites;
|
||||
|
||||
qreal zoomFactor;
|
||||
int wordsZoomLevel;
|
||||
|
||||
Preferences();
|
||||
};
|
||||
|
|
|
@ -49,6 +49,9 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
ui.setupUi( this );
|
||||
|
||||
wordListDefaultFont = ui.wordList->font();
|
||||
translateLineDefaultFont = ui.translateLine->font();
|
||||
|
||||
// Make the search pane's titlebar
|
||||
|
||||
groupLabel.setText( tr( "Look up in:" ) );
|
||||
|
@ -94,8 +97,11 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
// zooming
|
||||
navToolbar->addSeparator();
|
||||
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->setShortcut( QKeySequence::ZoomOut );
|
||||
zoomBase = navToolbar->addAction( QIcon( ":/icons/icon32_zoombase.png" ), tr( "Normal Size" ) );
|
||||
zoomBase->setShortcut( QKeySequence( "Ctrl+0" ) );
|
||||
|
||||
connect( zoomIn, SIGNAL( triggered() ),
|
||||
this, SLOT( zoomin() ) );
|
||||
|
@ -104,6 +110,23 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
connect( zoomBase, SIGNAL( triggered() ),
|
||||
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
|
||||
connect( trayIconMenu.addAction( tr( "Show &Main Window" ) ), SIGNAL( activated() ),
|
||||
this, SLOT( showMainWindow() ) );
|
||||
|
@ -329,6 +352,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
|
|||
|
||||
// Update zoomers
|
||||
applyZoomFactor();
|
||||
applyWordsZoomLevel();
|
||||
|
||||
// Update autostart info
|
||||
setAutostart(cfg.preferences.autoStart);
|
||||
|
@ -1811,3 +1835,63 @@ void MainWindow::applyZoomFactor()
|
|||
if ( scanPopup.get() )
|
||||
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;
|
||||
GroupComboBox groupList;
|
||||
|
||||
/// Fonts saved before words zooming is in effect, so it could be reset back.
|
||||
QFont wordListDefaultFont, translateLineDefaultFont;
|
||||
|
||||
QAction escAction, focusTranslateLineAction, addTabAction, closeCurrentTabAction,
|
||||
switchToNextTabAction, switchToPrevTabAction, showDictBarNamesAction;
|
||||
QToolBar * navToolbar;
|
||||
QAction * navBack, * navForward, * navPronounce, * enableScanPopup;
|
||||
QAction * zoomIn, * zoomOut, * zoomBase;
|
||||
QAction * wordsZoomIn, * wordsZoomOut, * wordsZoomBase;
|
||||
QMenu trayIconMenu;
|
||||
QToolButton addTab;
|
||||
Config::Class & cfg;
|
||||
|
@ -180,6 +184,12 @@ private slots:
|
|||
void zoomout();
|
||||
void unzoom();
|
||||
|
||||
void doWordsZoomIn();
|
||||
void doWordsZoomOut();
|
||||
void doWordsZoomBase();
|
||||
|
||||
void applyWordsZoomLevel();
|
||||
|
||||
/// If editDictionaryGroup is specified, the dialog positions on that group
|
||||
/// initially.
|
||||
void editDictionaries( unsigned editDictionaryGroup = Instances::Group::NoGroupId );
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>653</width>
|
||||
<height>21</height>
|
||||
<height>23</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
|
@ -96,6 +96,12 @@
|
|||
<property name="title">
|
||||
<string>&View</string>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuZoom">
|
||||
<property name="title">
|
||||
<string>&Zoom</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menuZoom"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuHistory">
|
||||
<property name="title">
|
||||
|
|
Loading…
Reference in a new issue