1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QTEXTBROWSER_H |
5 | #define QTEXTBROWSER_H |
6 | |
7 | #include <QtWidgets/qtwidgetsglobal.h> |
8 | #include <QtWidgets/qtextedit.h> |
9 | #include <QtCore/qurl.h> |
10 | |
11 | QT_REQUIRE_CONFIG(textbrowser); |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class QTextBrowserPrivate; |
16 | |
17 | class Q_WIDGETS_EXPORT QTextBrowser : public QTextEdit |
18 | { |
19 | Q_OBJECT |
20 | |
21 | Q_PROPERTY(QUrl source READ source WRITE setSource) |
22 | Q_PROPERTY(QTextDocument::ResourceType sourceType READ sourceType) |
23 | Q_OVERRIDE(bool modified SCRIPTABLE false) |
24 | Q_OVERRIDE(bool readOnly DESIGNABLE false SCRIPTABLE false) |
25 | Q_OVERRIDE(bool undoRedoEnabled DESIGNABLE false SCRIPTABLE false) |
26 | Q_PROPERTY(QStringList searchPaths READ searchPaths WRITE setSearchPaths) |
27 | Q_PROPERTY(bool openExternalLinks READ openExternalLinks WRITE setOpenExternalLinks) |
28 | Q_PROPERTY(bool openLinks READ openLinks WRITE setOpenLinks) |
29 | |
30 | public: |
31 | explicit QTextBrowser(QWidget* parent = nullptr); |
32 | virtual ~QTextBrowser(); |
33 | |
34 | QUrl source() const; |
35 | QTextDocument::ResourceType sourceType() const; |
36 | |
37 | QStringList searchPaths() const; |
38 | void setSearchPaths(const QStringList &paths); |
39 | |
40 | virtual QVariant loadResource(int type, const QUrl &name) override; |
41 | |
42 | bool isBackwardAvailable() const; |
43 | bool isForwardAvailable() const; |
44 | void clearHistory(); |
45 | QString historyTitle(int) const; |
46 | QUrl historyUrl(int) const; |
47 | int backwardHistoryCount() const; |
48 | int forwardHistoryCount() const; |
49 | |
50 | bool openExternalLinks() const; |
51 | void setOpenExternalLinks(bool open); |
52 | |
53 | bool openLinks() const; |
54 | void setOpenLinks(bool open); |
55 | |
56 | public Q_SLOTS: |
57 | void setSource(const QUrl &name, QTextDocument::ResourceType type = QTextDocument::UnknownResource); |
58 | virtual void backward(); |
59 | virtual void forward(); |
60 | virtual void home(); |
61 | virtual void reload(); |
62 | |
63 | Q_SIGNALS: |
64 | void backwardAvailable(bool); |
65 | void forwardAvailable(bool); |
66 | void historyChanged(); |
67 | void sourceChanged(const QUrl &); |
68 | void highlighted(const QUrl &); |
69 | void anchorClicked(const QUrl &); |
70 | |
71 | protected: |
72 | bool event(QEvent *e) override; |
73 | virtual void keyPressEvent(QKeyEvent *ev) override; |
74 | virtual void mouseMoveEvent(QMouseEvent *ev) override; |
75 | virtual void mousePressEvent(QMouseEvent *ev) override; |
76 | virtual void mouseReleaseEvent(QMouseEvent *ev) override; |
77 | virtual void focusOutEvent(QFocusEvent *ev) override; |
78 | virtual bool focusNextPrevChild(bool next) override; |
79 | virtual void paintEvent(QPaintEvent *e) override; |
80 | virtual void doSetSource(const QUrl &name, QTextDocument::ResourceType type = QTextDocument::UnknownResource); |
81 | |
82 | private: |
83 | Q_DISABLE_COPY(QTextBrowser) |
84 | Q_DECLARE_PRIVATE(QTextBrowser) |
85 | Q_PRIVATE_SLOT(d_func(), void _q_documentModified()) |
86 | Q_PRIVATE_SLOT(d_func(), void _q_activateAnchor(const QString &)) |
87 | Q_PRIVATE_SLOT(d_func(), void _q_highlightLink(const QString &)) |
88 | }; |
89 | |
90 | QT_END_NAMESPACE |
91 | |
92 | #endif // QTEXTBROWSER_H |
93 | |