Commit ee635941 authored by Eike Ziller's avatar Eike Ziller
Browse files

Help: Do not pass zoom factor to constructor



Introduce HelpViewer::setScale instead

Change-Id: I9d50483bc1fa4de89de53db40eda348379bd0ae9
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 6cafc424
......@@ -359,23 +359,26 @@ HelpViewer *HelpPlugin::createHelpViewer(qreal zoom)
const QString backend = QLatin1String(qgetenv("QTC_HELPVIEWER_BACKEND"));
if (backend.compare(QLatin1String("native"), Qt::CaseInsensitive) == 0) {
#ifdef QTC_MAC_NATIVE_HELPVIEWER
viewer = new MacWebKitHelpViewer(zoom);
viewer = new MacWebKitHelpViewer();
#else
qWarning() << "native help viewer is requested, but was not enabled during compilation";
#endif
} else if (backend.compare(QLatin1String("textbrowser"), Qt::CaseInsensitive) != 0) {
#ifndef QT_NO_WEBKIT
viewer = new QtWebKitHelpViewer(zoom);
viewer = new QtWebKitHelpViewer();
#endif
}
if (!viewer)
viewer = new TextBrowserHelpViewer(zoom);
viewer = new TextBrowserHelpViewer();
// initialize font
QVariant fontSetting = LocalHelpManager::engineFontSettings();
if (fontSetting.isValid())
viewer->setViewerFont(fontSetting.value<QFont>());
// initialize zoom
viewer->setScale(zoom);
// add find support
Aggregation::Aggregate *agg = new Aggregation::Aggregate();
agg->add(viewer);
......
......@@ -55,6 +55,7 @@ public:
virtual void setViewerFont(const QFont &font) = 0;
virtual qreal scale() const = 0;
virtual void setScale(qreal scale) = 0;
virtual QString title() const = 0;
......
......@@ -82,13 +82,14 @@ class MacWebKitHelpViewer : public HelpViewer
Q_OBJECT
public:
explicit MacWebKitHelpViewer(qreal zoom, QWidget *parent = 0);
explicit MacWebKitHelpViewer(QWidget *parent = 0);
~MacWebKitHelpViewer();
QFont viewerFont() const;
void setViewerFont(const QFont &font);
qreal scale() const;
void setScale(qreal scale);
QString title() const;
......
......@@ -454,7 +454,7 @@ void MacWebKitHelpWidget::showEvent(QShowEvent *)
// #pragma mark -- MacWebKitHelpViewer
MacWebKitHelpViewer::MacWebKitHelpViewer(qreal zoom, QWidget *parent)
MacWebKitHelpViewer::MacWebKitHelpViewer(QWidget *parent)
: HelpViewer(parent),
m_widget(new MacWebKitHelpWidget(this))
{
......@@ -469,7 +469,6 @@ MacWebKitHelpViewer::MacWebKitHelpViewer(qreal zoom, QWidget *parent)
setLayout(layout);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_widget, 10);
m_widget->webView().textSizeMultiplier = (zoom == 0.0 ? 1.0 : zoom);
}
MacWebKitHelpViewer::~MacWebKitHelpViewer()
......@@ -515,7 +514,12 @@ void MacWebKitHelpViewer::resetScale()
qreal MacWebKitHelpViewer::scale() const
{
AutoreleasePool pool; Q_UNUSED(pool)
return m_widget->webView().textSizeMultiplier;
return m_widget->webView().textSizeMultiplier;
}
void MacWebKitHelpViewer::setScale(qreal scale)
{
m_widget->webView().textSizeMultiplier = (scale <= 0.0 ? 1.0 : scale);
}
QString MacWebKitHelpViewer::title() const
......
......@@ -250,7 +250,7 @@ void HelpPage::onHandleUnsupportedContent(QNetworkReply *reply)
// -- HelpViewer
QtWebKitHelpWidget::QtWebKitHelpWidget(qreal zoom, QtWebKitHelpViewer *parent)
QtWebKitHelpWidget::QtWebKitHelpWidget(QtWebKitHelpViewer *parent)
: QWebView(parent),
m_parent(parent)
{
......@@ -278,8 +278,6 @@ QtWebKitHelpWidget::QtWebKitHelpWidget(qreal zoom, QtWebKitHelpViewer *parent)
SLOT(actionChanged()));
connect(pageAction(QWebPage::Forward), SIGNAL(changed()), this,
SLOT(actionChanged()));
setZoomFactor(zoom == 0.0 ? 1.0 : zoom);
}
QtWebKitHelpWidget::~QtWebKitHelpWidget()
......@@ -393,9 +391,9 @@ bool QtWebKitHelpWidget::eventFilter(QObject *obj, QEvent *event)
return QWebView::eventFilter(obj, event);
}
QtWebKitHelpViewer::QtWebKitHelpViewer(qreal zoom, QWidget *parent)
QtWebKitHelpViewer::QtWebKitHelpViewer(QWidget *parent)
: HelpViewer(parent),
m_webView(new QtWebKitHelpWidget(zoom, this))
m_webView(new QtWebKitHelpWidget(this))
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
......@@ -449,6 +447,11 @@ qreal QtWebKitHelpViewer::scale() const
return m_webView->zoomFactor();
}
void QtWebKitHelpViewer::setScale(qreal scale)
{
m_webView->setZoomFactor(scale <= 0.0 ? 1.0 : scale);
}
QString QtWebKitHelpViewer::title() const
{
return m_webView->title();
......
......@@ -48,13 +48,14 @@ class QtWebKitHelpViewer : public HelpViewer
{
Q_OBJECT
public:
explicit QtWebKitHelpViewer(qreal zoom, QWidget *parent = 0);
explicit QtWebKitHelpViewer(QWidget *parent = 0);
~QtWebKitHelpViewer() { }
QFont viewerFont() const;
void setViewerFont(const QFont &font);
qreal scale() const;
void setScale(qreal scale);
QString title() const;
......@@ -103,7 +104,7 @@ class QtWebKitHelpWidget : public QWebView
Q_OBJECT
public:
explicit QtWebKitHelpWidget(qreal zoom, QtWebKitHelpViewer *parent = 0);
explicit QtWebKitHelpWidget(QtWebKitHelpViewer *parent = 0);
~QtWebKitHelpWidget();
void scaleUp();
......
......@@ -50,9 +50,9 @@ using namespace Help::Internal;
// -- HelpViewer
TextBrowserHelpViewer::TextBrowserHelpViewer(qreal zoom, QWidget *parent)
TextBrowserHelpViewer::TextBrowserHelpViewer(QWidget *parent)
: HelpViewer(parent)
, m_textBrowser(new TextBrowserHelpWidget(zoom, this))
, m_textBrowser(new TextBrowserHelpWidget(this))
{
QVBoxLayout *layout = new QVBoxLayout;
setLayout(layout);
......@@ -112,6 +112,22 @@ qreal TextBrowserHelpViewer::scale() const
return m_textBrowser->zoomCount;
}
void TextBrowserHelpViewer::setScale(qreal scale)
{
m_textBrowser->forceFont = true;
if (scale > 10)
scale = 10;
else if (scale < -5)
scale = -5;
int diff = (int)scale - m_textBrowser->zoomCount;
if (diff > 0)
m_textBrowser->zoomIn(diff);
else if (diff < 0)
m_textBrowser->zoomOut(-diff);
m_textBrowser->zoomCount = (int)scale;
m_textBrowser->forceFont = false;
}
QString TextBrowserHelpViewer::title() const
{
return m_textBrowser->documentTitle();
......@@ -284,9 +300,9 @@ void TextBrowserHelpViewer::goToHistoryItem()
// -- private
TextBrowserHelpWidget::TextBrowserHelpWidget(int zoom, TextBrowserHelpViewer *parent)
TextBrowserHelpWidget::TextBrowserHelpWidget(TextBrowserHelpViewer *parent)
: QTextBrowser(parent)
, zoomCount(zoom)
, zoomCount(0)
, forceFont(false)
, m_openInNewPageActionVisible(true)
, m_parent(parent)
......
......@@ -47,13 +47,14 @@ class TextBrowserHelpViewer : public HelpViewer
Q_OBJECT
public:
explicit TextBrowserHelpViewer(qreal zoom, QWidget *parent = 0);
explicit TextBrowserHelpViewer(QWidget *parent = 0);
~TextBrowserHelpViewer();
QFont viewerFont() const;
void setViewerFont(const QFont &font);
qreal scale() const;
void setScale(qreal scale);
QString title() const;
......@@ -97,7 +98,7 @@ class TextBrowserHelpWidget : public QTextBrowser
Q_OBJECT
public:
TextBrowserHelpWidget(int zoom, TextBrowserHelpViewer *parent);
TextBrowserHelpWidget(TextBrowserHelpViewer *parent);
QVariant loadResource(int type, const QUrl &name);
......
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