1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Assistant of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef HELPVIEWERPRIVATE_H |
30 | #define HELPVIEWERPRIVATE_H |
31 | |
32 | #include "centralwidget.h" |
33 | #include "helpviewer.h" |
34 | #include "openpagesmanager.h" |
35 | |
36 | #include <QtCore/QObject> |
37 | #if defined(BROWSER_QTEXTBROWSER) |
38 | # include <QtWidgets/QTextBrowser> |
39 | #elif defined(BROWSER_QTWEBKIT) |
40 | # include <QtGui/QGuiApplication> |
41 | # include <QtGui/QScreen> |
42 | #endif // BROWSER_QTWEBKIT |
43 | |
44 | QT_BEGIN_NAMESPACE |
45 | |
46 | class HelpViewer::HelpViewerPrivate : public QObject |
47 | { |
48 | Q_OBJECT |
49 | |
50 | public: |
51 | #if defined(BROWSER_QTEXTBROWSER) |
52 | HelpViewerPrivate(int zoom) |
53 | : zoomCount(zoom) |
54 | { } |
55 | #elif defined(BROWSER_QTWEBKIT) |
56 | HelpViewerPrivate() |
57 | : m_loadFinished(false) |
58 | { |
59 | // The web uses 96dpi by default on the web to preserve the font size across platforms, but |
60 | // since we control the content for the documentation, we want the system DPI to be used. |
61 | // - OS X reports 72dpi but doesn't allow changing the DPI, ignore anything below a 1.0 ratio to handle this. |
62 | // - On Windows and Linux don't zoom the default web 96dpi below a 1.25 ratio to avoid |
63 | // filtered images in the doc unless the font readability difference is considerable. |
64 | webDpiRatio = QGuiApplication::primaryScreen()->logicalDotsPerInch() / 96.; |
65 | if (webDpiRatio < 1.25) |
66 | webDpiRatio = 1.0; |
67 | } |
68 | #endif // BROWSER_QTWEBKIT |
69 | |
70 | #if defined(BROWSER_QTEXTBROWSER) |
71 | bool hasAnchorAt(QTextBrowser *browser, const QPoint& pos) |
72 | { |
73 | lastAnchor = browser->anchorAt(pos); |
74 | if (lastAnchor.isEmpty()) |
75 | return false; |
76 | |
77 | lastAnchor = browser->source().resolved(relative: lastAnchor).toString(); |
78 | if (lastAnchor.at(i: 0) == QLatin1Char('#')) { |
79 | QString src = browser->source().toString(); |
80 | int hsh = src.indexOf(c: QLatin1Char('#')); |
81 | lastAnchor = (hsh >= 0 ? src.left(n: hsh) : src) + lastAnchor; |
82 | } |
83 | return true; |
84 | } |
85 | |
86 | public slots: |
87 | void openLink() |
88 | { |
89 | doOpenLink(newPage: false); |
90 | } |
91 | |
92 | void openLinkInNewPage() |
93 | { |
94 | doOpenLink(newPage: true); |
95 | } |
96 | |
97 | public: |
98 | QString lastAnchor; |
99 | int zoomCount; |
100 | bool forceFont = false; |
101 | |
102 | private: |
103 | |
104 | void doOpenLink(bool newPage) |
105 | { |
106 | if (lastAnchor.isEmpty()) |
107 | return; |
108 | if (newPage) |
109 | OpenPagesManager::instance()->createPage(url: lastAnchor); |
110 | else |
111 | CentralWidget::instance()->setSource(lastAnchor); |
112 | lastAnchor.clear(); |
113 | } |
114 | |
115 | #elif defined(BROWSER_QTWEBKIT) |
116 | qreal webDpiRatio; |
117 | #endif // BROWSER_QTWEBKIT |
118 | |
119 | public: |
120 | bool m_loadFinished = false; |
121 | |
122 | }; |
123 | |
124 | QT_END_NAMESPACE |
125 | |
126 | #endif // HELPVIEWERPRIVATE_H |
127 | |