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