diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp index 0b4881f762bda2fcfd371fa6f464bac8ca86c5bc..5c1b5acbe86a9a36852079107bc4505ca6b2e4b9 100644 --- a/src/plugins/help/centralwidget.cpp +++ b/src/plugins/help/centralwidget.cpp @@ -131,14 +131,18 @@ CentralWidget::~CentralWidget() if (!engine.setupData()) return; + QString zoomCount; QString currentPages; for (int i = 0; i < tabWidget->count(); ++i) { HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); - if (viewer && viewer->source().isValid()) + if (viewer && viewer->source().isValid()) { currentPages += (viewer->source().toString() + QLatin1Char('|')); + zoomCount += QString::number(viewer->zoom()) + QLatin1Char('|'); + } } engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage); engine.setCustomValue(QLatin1String("LastShownPages"), currentPages); + engine.setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount); } CentralWidget *CentralWidget::instance() @@ -250,9 +254,21 @@ void CentralWidget::setLastShownPages() return; } + value = helpEngine->customValue(QLatin1String("LastShownPagesZoom"), + QString()).toString(); + QVector<QString> zoomVector = value.split(QLatin1Char('|'), + QString::SkipEmptyParts).toVector(); + + const int zoomCount = zoomVector.count(); + zoomVector.insert(zoomCount, pageCount - zoomCount, QLatin1String("0")); + + QVector<QString>::const_iterator zIt = zoomVector.constBegin(); QStringList::const_iterator it = lastShownPageList.constBegin(); - for (; it != lastShownPageList.constEnd(); ++it) - setSourceInNewTab((*it)); + for (; it != lastShownPageList.constEnd(); ++it, ++zIt) + setSourceInNewTab((*it), (*zIt).toInt()); + + int tab = helpEngine->customValue(QLatin1String("LastTabPage"), 0).toInt(); + tabWidget->setCurrentIndex(tab); } bool CentralWidget::hasSelection() const @@ -404,12 +420,20 @@ void CentralWidget::setGlobalActions(const QList<QAction*> &actions) globalActionList = actions; } -void CentralWidget::setSourceInNewTab(const QUrl &url) +void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom) { HelpViewer* viewer = new HelpViewer(helpEngine, this); viewer->installEventFilter(this); + viewer->setZoom(zoom); viewer->setSource(url); viewer->setFocus(Qt::OtherFocusReason); + +#if defined(QT_NO_WEBKIT) + QFont font = viewer->font(); + font.setPointSize(font.pointSize() + int(zoom)); + viewer->setFont(font); +#endif + tabWidget->setCurrentIndex(tabWidget->addTab(viewer, quoteTabTitle(viewer->documentTitle()))); diff --git a/src/plugins/help/centralwidget.h b/src/plugins/help/centralwidget.h index eaa5d45aac460df70f2f3bddfe8e2673e5c2f8bd..1bb9bc696f70990a849486c0265eea248120a5f3 100644 --- a/src/plugins/help/centralwidget.h +++ b/src/plugins/help/centralwidget.h @@ -90,7 +90,7 @@ public slots: void pageSetup(); void printPreview(); void setSource(const QUrl &url); - void setSourceInNewTab(const QUrl &url); + void setSourceInNewTab(const QUrl &url, int zoom = 0); HelpViewer *newEmptyTab(); void home(); void forward(); diff --git a/src/plugins/help/helpplugin.cpp b/src/plugins/help/helpplugin.cpp index 0256309436fd41c03bb4d6100fb4bb60d9e81651..dda3959f3716a759fb4c3bf6084616669891d256 100644 --- a/src/plugins/help/helpplugin.cpp +++ b/src/plugins/help/helpplugin.cpp @@ -404,6 +404,13 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-"))); connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomOut())); advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); + + a = new QAction(tr("Reset Font Size"), this); + cmd = am->registerAction(a, QLatin1String("Help.ResetFontSize"), + modecontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+0"))); + connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(resetZoom())); + advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); } return true; diff --git a/src/shared/help/helpviewer.cpp b/src/shared/help/helpviewer.cpp index 0133d5fbb4fc63b16987fbf918303f8a3607aa2a..45caae8e53014395b87285b8963109d5d358f41f 100644 --- a/src/shared/help/helpviewer.cpp +++ b/src/shared/help/helpviewer.cpp @@ -277,14 +277,20 @@ void HelpViewer::resetZoom() setTextSizeMultiplier(1.0); } -void HelpViewer::zoomIn(qreal range) +void HelpViewer::zoomIn(int range) +{ + setTextSizeMultiplier(qMin(2.0, textSizeMultiplier() + range / 10.0)); +} + +void HelpViewer::zoomOut(int range) { - setTextSizeMultiplier(textSizeMultiplier() + range / 10.0); + setTextSizeMultiplier(qMax(0.5, textSizeMultiplier() - range / 10.0)); } -void HelpViewer::zoomOut(qreal range) +int HelpViewer::zoom() const { - setTextSizeMultiplier(qMax(0.0, textSizeMultiplier() - range / 10.0)); + qreal zoom = textSizeMultiplier() * 10.0; + return (zoom < 10.0 ? zoom * -1.0 : zoom - 10.0); } void HelpViewer::home() diff --git a/src/shared/help/helpviewer.h b/src/shared/help/helpviewer.h index 76bee7887d21f73d59d64661df23457cf203540b..cd6f699feb2c2b4ecca8cf35ae12766f0e4a122a 100644 --- a/src/shared/help/helpviewer.h +++ b/src/shared/help/helpviewer.h @@ -76,9 +76,12 @@ public: inline bool hasSelection() const { return !selectedText().isEmpty(); } // ### this is suboptimal + void zoomIn(int range = 1); + void zoomOut(int range = 1); + void resetZoom(); - void zoomIn(qreal range = 1); - void zoomOut(qreal range = 1); + int zoom() const; + void setZoom(int zoom) { zoomIn(zoom); } inline void copy() { return triggerPageAction(QWebPage::Copy); } @@ -124,9 +127,10 @@ public: HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *parent); void setSource(const QUrl &url); - void resetZoom(); void zoomIn(int range = 1); void zoomOut(int range = 1); + + void resetZoom(); int zoom() const { return zoomCount; } void setZoom(int zoom) { zoomCount = zoom; }