1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4#ifndef HELPVIEWERIMPLPRIVATE_H
5#define HELPVIEWERIMPLPRIVATE_H
6
7#include "centralwidget.h"
8#include "helpviewer.h"
9#include "openpagesmanager.h"
10
11#include <QtCore/QObject>
12#if defined(BROWSER_QTEXTBROWSER)
13# include <QtWidgets/QTextBrowser>
14#elif defined(BROWSER_QTWEBKIT)
15# include <QtGui/QGuiApplication>
16# include <QtGui/QScreen>
17#endif // BROWSER_QTWEBKIT
18
19QT_BEGIN_NAMESPACE
20
21class HelpViewerImpl::HelpViewerImplPrivate : public QObject
22{
23 Q_OBJECT
24
25public:
26#if defined(BROWSER_QTEXTBROWSER)
27 HelpViewerImplPrivate(int zoom)
28 : zoomCount(zoom)
29 { }
30#elif defined(BROWSER_QTWEBKIT)
31 HelpViewerImplPrivate()
32 {
33 // The web uses 96dpi by default on the web to preserve the font size across platforms, but
34 // since we control the content for the documentation, we want the system DPI to be used.
35 // - OS X reports 72dpi but doesn't allow changing the DPI, ignore anything below a 1.0 ratio to handle this.
36 // - On Windows and Linux don't zoom the default web 96dpi below a 1.25 ratio to avoid
37 // filtered images in the doc unless the font readability difference is considerable.
38 webDpiRatio = QGuiApplication::primaryScreen()->logicalDotsPerInch() / 96.;
39 if (webDpiRatio < 1.25)
40 webDpiRatio = 1.0;
41 }
42#endif // BROWSER_QTWEBKIT
43
44#if defined(BROWSER_QTEXTBROWSER)
45 bool hasAnchorAt(QTextBrowser *browser, const QPoint& pos)
46 {
47 lastAnchor = browser->anchorAt(pos);
48 if (lastAnchor.isEmpty())
49 return false;
50
51 lastAnchor = browser->source().resolved(relative: lastAnchor).toString();
52 if (lastAnchor.at(i: 0) == QLatin1Char('#')) {
53 QString src = browser->source().toString();
54 int hsh = src.indexOf(c: QLatin1Char('#'));
55 lastAnchor = (hsh >= 0 ? src.left(n: hsh) : src) + lastAnchor;
56 }
57 return true;
58 }
59
60public slots:
61 void openLink()
62 {
63 doOpenLink(newPage: false);
64 }
65
66 void openLinkInNewPage()
67 {
68 doOpenLink(newPage: true);
69 }
70
71public:
72 QString lastAnchor;
73 int zoomCount;
74 bool forceFont = false;
75
76private:
77
78 void doOpenLink(bool newPage)
79 {
80 if (lastAnchor.isEmpty())
81 return;
82 if (newPage)
83 OpenPagesManager::instance()->createPage(url: lastAnchor);
84 else
85 CentralWidget::instance()->setSource(lastAnchor);
86 lastAnchor.clear();
87 }
88
89#elif defined(BROWSER_QTWEBKIT)
90 qreal webDpiRatio;
91#endif // BROWSER_QTWEBKIT
92};
93
94QT_END_NAMESPACE
95
96#endif // HELPVIEWERIMPLPRIVATE_H
97

source code of qttools/src/assistant/assistant/helpviewerimpl_p.h