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 CENTRALWIDGET_H |
5 | #define CENTRALWIDGET_H |
6 | |
7 | #include <QtCore/QUrl> |
8 | #include <QtCore/QHash> |
9 | |
10 | #include <QtWidgets/QTabBar> |
11 | #include <QtWidgets/QWidget> |
12 | |
13 | QT_BEGIN_NAMESPACE |
14 | |
15 | class FindWidget; |
16 | class HelpViewer; |
17 | class QStackedWidget; |
18 | class QPrinter; |
19 | |
20 | class TabBar : public QTabBar |
21 | { |
22 | Q_OBJECT |
23 | friend class CentralWidget; |
24 | |
25 | public: |
26 | ~TabBar(); |
27 | |
28 | int addNewTab(const QString &title); |
29 | void setCurrent(HelpViewer *viewer); |
30 | void removeTabAt(HelpViewer *viewer); |
31 | |
32 | public slots: |
33 | void titleChanged(); |
34 | |
35 | signals: |
36 | void currentTabChanged(HelpViewer *viewer); |
37 | void addBookmark(const QString &title, const QString &url); |
38 | |
39 | private: |
40 | TabBar(QWidget *parent = nullptr); |
41 | |
42 | private slots: |
43 | void slotCurrentChanged(int index); |
44 | void slotTabCloseRequested(int index); |
45 | void (const QPoint &pos); |
46 | }; |
47 | |
48 | class CentralWidget : public QWidget |
49 | { |
50 | Q_OBJECT |
51 | friend class OpenPagesManager; |
52 | |
53 | public: |
54 | CentralWidget(QWidget *parent = nullptr); |
55 | ~CentralWidget() override; |
56 | |
57 | static CentralWidget *instance(); |
58 | |
59 | QUrl currentSource() const; |
60 | QString currentTitle() const; |
61 | |
62 | bool hasSelection() const; |
63 | bool isForwardAvailable() const; |
64 | bool isBackwardAvailable() const; |
65 | |
66 | HelpViewer *viewerAt(int index) const; |
67 | HelpViewer *currentHelpViewer() const; |
68 | int currentIndex() const; |
69 | |
70 | void connectTabBar(); |
71 | |
72 | public slots: |
73 | #if QT_CONFIG(clipboard) |
74 | void copy(); |
75 | #endif |
76 | void home(); |
77 | |
78 | void zoomIn(); |
79 | void zoomOut(); |
80 | void resetZoom(); |
81 | |
82 | void forward(); |
83 | void nextPage(); |
84 | |
85 | void backward(); |
86 | void previousPage(); |
87 | |
88 | void print(); |
89 | void pageSetup(); |
90 | void printPreview(); |
91 | |
92 | void setSource(const QUrl &url); |
93 | void setSourceFromSearch(const QUrl &url); |
94 | |
95 | void findNext(); |
96 | void findPrevious(); |
97 | void find(const QString &text, bool forward, bool incremental); |
98 | |
99 | void activateTab(); |
100 | void showTextSearch(); |
101 | void updateBrowserFont(); |
102 | void updateUserInterface(); |
103 | |
104 | signals: |
105 | void currentViewerChanged(); |
106 | #if QT_CONFIG(clipboard) |
107 | void copyAvailable(bool yes); |
108 | #endif |
109 | void sourceChanged(const QUrl &url); |
110 | void highlighted(const QUrl &link); |
111 | void forwardAvailable(bool available); |
112 | void backwardAvailable(bool available); |
113 | void addBookmark(const QString &title, const QString &url); |
114 | |
115 | protected: |
116 | void keyPressEvent(QKeyEvent *) override; |
117 | void focusInEvent(QFocusEvent *event) override; |
118 | |
119 | private slots: |
120 | void highlightSearchTerms(); |
121 | void printPreviewToPrinter(QPrinter *printer); |
122 | void handleSourceChanged(const QUrl &url); |
123 | void slotHighlighted(const QUrl& link); |
124 | |
125 | private: |
126 | void initPrinter(); |
127 | void connectSignals(HelpViewer *page); |
128 | bool eventFilter(QObject *object, QEvent *e) override; |
129 | |
130 | void removePage(int index); |
131 | void setCurrentPage(HelpViewer *page); |
132 | void addPage(HelpViewer *page, bool fromSearch = false); |
133 | |
134 | private: |
135 | #ifndef QT_NO_PRINTER |
136 | QPrinter *m_printer; |
137 | #endif |
138 | FindWidget *m_findWidget; |
139 | QStackedWidget *m_stackedWidget; |
140 | TabBar *m_tabBar; |
141 | QHash<QUrl, QUrl> m_resolvedLinks; |
142 | }; |
143 | |
144 | QT_END_NAMESPACE |
145 | |
146 | #endif // CENTRALWIDGET_H |
147 | |