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 HELPVIEWERIMPL_H |
5 | #define HELPVIEWERIMPL_H |
6 | |
7 | #include <QtCore/qglobal.h> |
8 | #include <QtCore/QUrl> |
9 | #include <QtCore/QVariant> |
10 | |
11 | #include <QtGui/QFont> |
12 | |
13 | #if defined(BROWSER_QTWEBKIT) |
14 | # include <QWebView> |
15 | #elif defined(BROWSER_QTEXTBROWSER) |
16 | # include <QtWidgets/QTextBrowser> |
17 | #endif |
18 | |
19 | #include "helpviewer.h" |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | #if defined(BROWSER_QTWEBKIT) |
24 | #define TEXTBROWSER_OVERRIDE |
25 | class HelpViewerImpl : public QWebView |
26 | #elif defined(BROWSER_QTEXTBROWSER) |
27 | #define TEXTBROWSER_OVERRIDE override |
28 | class HelpViewerImpl : public QTextBrowser |
29 | #endif |
30 | { |
31 | Q_OBJECT |
32 | class HelpViewerImplPrivate; |
33 | |
34 | public: |
35 | HelpViewerImpl(qreal zoom, QWidget *parent = nullptr); |
36 | ~HelpViewerImpl() override; |
37 | |
38 | QFont viewerFont() const; |
39 | void setViewerFont(const QFont &font); |
40 | |
41 | void scaleUp(); |
42 | void scaleDown(); |
43 | |
44 | void resetScale(); |
45 | qreal scale() const; |
46 | |
47 | QString title() const; |
48 | |
49 | QUrl source() const; |
50 | void doSetSource(const QUrl &url, QTextDocument::ResourceType type) TEXTBROWSER_OVERRIDE; |
51 | |
52 | QString selectedText() const; |
53 | bool isForwardAvailable() const; |
54 | bool isBackwardAvailable() const; |
55 | |
56 | bool findText(const QString &text, HelpViewer::FindFlags flags, bool incremental, |
57 | bool fromSearch); |
58 | |
59 | static const QString AboutBlank; |
60 | static const QString LocalHelpFile; |
61 | static const QString PageNotFoundMessage; |
62 | |
63 | public slots: |
64 | #if QT_CONFIG(clipboard) |
65 | void copy(); |
66 | #endif |
67 | void home() TEXTBROWSER_OVERRIDE; |
68 | |
69 | void forward() TEXTBROWSER_OVERRIDE; |
70 | void backward() TEXTBROWSER_OVERRIDE; |
71 | |
72 | signals: |
73 | void titleChanged(); |
74 | #if !defined(BROWSER_QTEXTBROWSER) |
75 | // Provide signals present in QTextBrowser, QTextEdit for browsers that do not inherit QTextBrowser |
76 | void copyAvailable(bool yes); |
77 | void sourceChanged(const QUrl &url); |
78 | void forwardAvailable(bool enabled); |
79 | void backwardAvailable(bool enabled); |
80 | void highlighted(const QUrl &link); |
81 | void printRequested(); |
82 | #elif !defined(BROWSER_QTWEBKIT) |
83 | // Provide signals present in QWebView for browsers that do not inherit QWebView |
84 | void loadFinished(bool finished); |
85 | #endif |
86 | |
87 | protected: |
88 | void keyPressEvent(QKeyEvent *e) override; |
89 | void wheelEvent(QWheelEvent *event) override; |
90 | void mousePressEvent(QMouseEvent *event) override; |
91 | void mouseReleaseEvent(QMouseEvent *event) override; |
92 | void resizeEvent(QResizeEvent *e) override; |
93 | |
94 | private slots: |
95 | void actionChanged(); |
96 | void setLoadFinished(); |
97 | |
98 | private: |
99 | bool eventFilter(QObject *obj, QEvent *event) override; |
100 | void (QContextMenuEvent *event) override; |
101 | QVariant loadResource(int type, const QUrl &name) TEXTBROWSER_OVERRIDE; |
102 | bool handleForwardBackwardMouseButtons(QMouseEvent *e); |
103 | void scrollToTextPosition(int position); |
104 | |
105 | private: |
106 | HelpViewerImplPrivate *d; |
107 | }; |
108 | |
109 | QT_END_NAMESPACE |
110 | |
111 | #endif // HELPVIEWERIMPL_H |
112 | |