From 71519ff19bde550509bf0fd955cbe0c6efa6df9e Mon Sep 17 00:00:00 2001 From: Konstantin Isakov Date: Fri, 2 Jul 2010 15:19:02 +0400 Subject: [PATCH] Add support for zooming fonts in word list and translate line. --- config.cc | 10 +++++- config.hh | 1 + mainwindow.cc | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++ mainwindow.hh | 10 ++++++ mainwindow.ui | 8 ++++- 5 files changed, 111 insertions(+), 2 deletions(-) diff --git a/config.cc b/config.cc index 4b282b3f..b1055333 100644 --- a/config.cc +++ b/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 ); diff --git a/config.hh b/config.hh index b6b253de..fec41347 100644 --- a/config.hh +++ b/config.hh @@ -165,6 +165,7 @@ struct Preferences bool disallowContentFromOtherSites; qreal zoomFactor; + int wordsZoomLevel; Preferences(); }; diff --git a/mainwindow.cc b/mainwindow.cc index 1bef8ec3..af782641 100644 --- a/mainwindow.cc +++ b/mainwindow.cc @@ -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 ); +} diff --git a/mainwindow.hh b/mainwindow.hh index 2857a333..247d9dc2 100644 --- a/mainwindow.hh +++ b/mainwindow.hh @@ -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 ); diff --git a/mainwindow.ui b/mainwindow.ui index 9b3be9ab..90205231 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -58,7 +58,7 @@ 0 0 653 - 21 + 23 @@ -96,6 +96,12 @@ &View + + + &Zoom + + +