forked from qt-creator/qt-creator
Store and restore font size for help viewers. Add font reset shortcut.
Task-number: 253365 Reviewed-by: kh
This commit is contained in:
@@ -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())));
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -277,14 +277,20 @@ void HelpViewer::resetZoom()
|
||||
setTextSizeMultiplier(1.0);
|
||||
}
|
||||
|
||||
void HelpViewer::zoomIn(qreal range)
|
||||
void HelpViewer::zoomIn(int range)
|
||||
{
|
||||
setTextSizeMultiplier(textSizeMultiplier() + range / 10.0);
|
||||
setTextSizeMultiplier(qMin(2.0, textSizeMultiplier() + range / 10.0));
|
||||
}
|
||||
|
||||
void HelpViewer::zoomOut(qreal range)
|
||||
void HelpViewer::zoomOut(int range)
|
||||
{
|
||||
setTextSizeMultiplier(qMax(0.0, textSizeMultiplier() - range / 10.0));
|
||||
setTextSizeMultiplier(qMax(0.5, textSizeMultiplier() - range / 10.0));
|
||||
}
|
||||
|
||||
int HelpViewer::zoom() const
|
||||
{
|
||||
qreal zoom = textSizeMultiplier() * 10.0;
|
||||
return (zoom < 10.0 ? zoom * -1.0 : zoom - 10.0);
|
||||
}
|
||||
|
||||
void HelpViewer::home()
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user