summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkh <qtc-committer@nokia.com>2009-06-25 16:03:02 +0200
committerkh <qtc-committer@nokia.com>2009-06-25 16:03:02 +0200
commitbfc04b98f0700b7af486185dcd4b7f0f1d1e30d9 (patch)
treeb451c36859901e35b5c1f3161e932572f890e5dd
parentc798f54fd3b8e1a05bf8f6957e7db6cb0588bb6b (diff)
downloadqt-creator-bfc04b98f0700b7af486185dcd4b7f0f1d1e30d9.tar.gz
Store and restore font size for help viewers. Add font reset shortcut.
Task-number: 253365 Reviewed-by: kh
-rw-r--r--src/plugins/help/centralwidget.cpp32
-rw-r--r--src/plugins/help/centralwidget.h2
-rw-r--r--src/plugins/help/helpplugin.cpp7
-rw-r--r--src/shared/help/helpviewer.cpp14
-rw-r--r--src/shared/help/helpviewer.h10
5 files changed, 53 insertions, 12 deletions
diff --git a/src/plugins/help/centralwidget.cpp b/src/plugins/help/centralwidget.cpp
index 0b4881f762..5c1b5acbe8 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 eaa5d45aac..1bb9bc696f 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 0256309436..dda3959f37 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 0133d5fbb4..45caae8e53 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 76bee7887d..cd6f699feb 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; }