Commit bfc04b98 authored by kh's avatar kh
Browse files

Store and restore font size for help viewers. Add font reset shortcut.

Task-number: 253365
Reviewed-by: kh
parent c798f54f
...@@ -131,14 +131,18 @@ CentralWidget::~CentralWidget() ...@@ -131,14 +131,18 @@ CentralWidget::~CentralWidget()
if (!engine.setupData()) if (!engine.setupData())
return; return;
QString zoomCount;
QString currentPages; QString currentPages;
for (int i = 0; i < tabWidget->count(); ++i) { for (int i = 0; i < tabWidget->count(); ++i) {
HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i)); HelpViewer *viewer = qobject_cast<HelpViewer*>(tabWidget->widget(i));
if (viewer && viewer->source().isValid()) if (viewer && viewer->source().isValid()) {
currentPages += (viewer->source().toString() + QLatin1Char('|')); currentPages += (viewer->source().toString() + QLatin1Char('|'));
zoomCount += QString::number(viewer->zoom()) + QLatin1Char('|');
}
} }
engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage); engine.setCustomValue(QLatin1String("LastTabPage"), lastTabPage);
engine.setCustomValue(QLatin1String("LastShownPages"), currentPages); engine.setCustomValue(QLatin1String("LastShownPages"), currentPages);
engine.setCustomValue(QLatin1String("LastShownPagesZoom"), zoomCount);
} }
CentralWidget *CentralWidget::instance() CentralWidget *CentralWidget::instance()
...@@ -250,9 +254,21 @@ void CentralWidget::setLastShownPages() ...@@ -250,9 +254,21 @@ void CentralWidget::setLastShownPages()
return; 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(); QStringList::const_iterator it = lastShownPageList.constBegin();
for (; it != lastShownPageList.constEnd(); ++it) for (; it != lastShownPageList.constEnd(); ++it, ++zIt)
setSourceInNewTab((*it)); setSourceInNewTab((*it), (*zIt).toInt());
int tab = helpEngine->customValue(QLatin1String("LastTabPage"), 0).toInt();
tabWidget->setCurrentIndex(tab);
} }
bool CentralWidget::hasSelection() const bool CentralWidget::hasSelection() const
...@@ -404,12 +420,20 @@ void CentralWidget::setGlobalActions(const QList<QAction*> &actions) ...@@ -404,12 +420,20 @@ void CentralWidget::setGlobalActions(const QList<QAction*> &actions)
globalActionList = actions; globalActionList = actions;
} }
void CentralWidget::setSourceInNewTab(const QUrl &url) void CentralWidget::setSourceInNewTab(const QUrl &url, int zoom)
{ {
HelpViewer* viewer = new HelpViewer(helpEngine, this); HelpViewer* viewer = new HelpViewer(helpEngine, this);
viewer->installEventFilter(this); viewer->installEventFilter(this);
viewer->setZoom(zoom);
viewer->setSource(url); viewer->setSource(url);
viewer->setFocus(Qt::OtherFocusReason); 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, tabWidget->setCurrentIndex(tabWidget->addTab(viewer,
quoteTabTitle(viewer->documentTitle()))); quoteTabTitle(viewer->documentTitle())));
......
...@@ -90,7 +90,7 @@ public slots: ...@@ -90,7 +90,7 @@ public slots:
void pageSetup(); void pageSetup();
void printPreview(); void printPreview();
void setSource(const QUrl &url); void setSource(const QUrl &url);
void setSourceInNewTab(const QUrl &url); void setSourceInNewTab(const QUrl &url, int zoom = 0);
HelpViewer *newEmptyTab(); HelpViewer *newEmptyTab();
void home(); void home();
void forward(); void forward();
......
...@@ -404,6 +404,13 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error) ...@@ -404,6 +404,13 @@ bool HelpPlugin::initialize(const QStringList &arguments, QString *error)
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-"))); cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+-")));
connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomOut())); connect(a, SIGNAL(triggered()), m_centralWidget, SLOT(zoomOut()));
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_FONT); 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; return true;
......
...@@ -277,14 +277,20 @@ void HelpViewer::resetZoom() ...@@ -277,14 +277,20 @@ void HelpViewer::resetZoom()
setTextSizeMultiplier(1.0); 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() void HelpViewer::home()
......
...@@ -76,9 +76,12 @@ public: ...@@ -76,9 +76,12 @@ public:
inline bool hasSelection() const inline bool hasSelection() const
{ return !selectedText().isEmpty(); } // ### this is suboptimal { return !selectedText().isEmpty(); } // ### this is suboptimal
void zoomIn(int range = 1);
void zoomOut(int range = 1);
void resetZoom(); void resetZoom();
void zoomIn(qreal range = 1); int zoom() const;
void zoomOut(qreal range = 1); void setZoom(int zoom) { zoomIn(zoom); }
inline void copy() inline void copy()
{ return triggerPageAction(QWebPage::Copy); } { return triggerPageAction(QWebPage::Copy); }
...@@ -124,9 +127,10 @@ public: ...@@ -124,9 +127,10 @@ public:
HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *parent); HelpViewer(QHelpEngine *helpEngine, Help::Internal::CentralWidget *parent);
void setSource(const QUrl &url); void setSource(const QUrl &url);
void resetZoom();
void zoomIn(int range = 1); void zoomIn(int range = 1);
void zoomOut(int range = 1); void zoomOut(int range = 1);
void resetZoom();
int zoom() const { return zoomCount; } int zoom() const { return zoomCount; }
void setZoom(int zoom) { zoomCount = zoom; } void setZoom(int zoom) { zoomCount = zoom; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment