Update copyright headers
[qt:qt.git] / demos / browser / tabwidget.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the demonstration applications of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
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 http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef TABWIDGET_H
43 #define TABWIDGET_H
44
45 #include <QtGui/QTabBar>
46
47 #include <QtGui/QShortcut>
48 /*
49     Tab bar with a few more features such as a context menu and shortcuts
50  */
51 class TabBar : public QTabBar
52 {
53     Q_OBJECT
54
55 signals:
56     void newTab();
57     void cloneTab(int index);
58     void closeTab(int index);
59     void closeOtherTabs(int index);
60     void reloadTab(int index);
61     void reloadAllTabs();
62     void tabMoveRequested(int fromIndex, int toIndex);
63
64 public:
65     TabBar(QWidget *parent = 0);
66
67 protected:
68     void mousePressEvent(QMouseEvent* event);
69     void mouseMoveEvent(QMouseEvent* event);
70
71 private slots:
72     void selectTabAction();
73     void cloneTab();
74     void closeTab();
75     void closeOtherTabs();
76     void reloadTab();
77     void contextMenuRequested(const QPoint &position);
78
79 private:
80     QList<QShortcut*> m_tabShortcuts;
81     friend class TabWidget;
82
83     QPoint m_dragStartPos;
84     int m_dragCurrentIndex;
85 };
86
87 #include <QtWebKit/QWebPage>
88
89 QT_BEGIN_NAMESPACE
90 class QAction;
91 QT_END_NAMESPACE
92 class WebView;
93 /*!
94     A proxy object that connects a single browser action
95     to one child webpage action at a time.
96
97     Example usage: used to keep the main window stop action in sync with
98     the current tabs webview's stop action.
99  */
100 class WebActionMapper : public QObject
101 {
102     Q_OBJECT
103
104 public:
105     WebActionMapper(QAction *root, QWebPage::WebAction webAction, QObject *parent);
106     QWebPage::WebAction webAction() const;
107     void addChild(QAction *action);
108     void updateCurrent(QWebPage *currentParent);
109
110 private slots:
111     void rootTriggered();
112     void childChanged();
113     void rootDestroyed();
114     void currentDestroyed();
115
116 private:
117     QWebPage *m_currentParent;
118     QAction *m_root;
119     QWebPage::WebAction m_webAction;
120 };
121
122 #include <QtCore/QUrl>
123 #include <QtGui/QTabWidget>
124 QT_BEGIN_NAMESPACE
125 class QCompleter;
126 class QLineEdit;
127 class QMenu;
128 class QStackedWidget;
129 QT_END_NAMESPACE
130 /*!
131     TabWidget that contains WebViews and a stack widget of associated line edits.
132
133     Connects up the current tab's signals to this class's signal and uses WebActionMapper
134     to proxy the actions.
135  */
136 class TabWidget : public QTabWidget
137 {
138     Q_OBJECT
139
140 signals:
141     // tab widget signals
142     void loadPage(const QString &url);
143     void tabsChanged();
144     void lastTabClosed();
145
146     // current tab signals
147     void setCurrentTitle(const QString &url);
148     void showStatusBarMessage(const QString &message);
149     void linkHovered(const QString &link);
150     void loadProgress(int progress);
151     void geometryChangeRequested(const QRect &geometry);
152     void menuBarVisibilityChangeRequested(bool visible);
153     void statusBarVisibilityChangeRequested(bool visible);
154     void toolBarVisibilityChangeRequested(bool visible);
155     void printRequested(QWebFrame *frame);
156
157 public:
158     TabWidget(QWidget *parent = 0);
159     void clear();
160     void addWebAction(QAction *action, QWebPage::WebAction webAction);
161
162     QAction *newTabAction() const;
163     QAction *closeTabAction() const;
164     QAction *recentlyClosedTabsAction() const;
165     QAction *nextTabAction() const;
166     QAction *previousTabAction() const;
167
168     QWidget *lineEditStack() const;
169     QLineEdit *currentLineEdit() const;
170     WebView *currentWebView() const;
171     WebView *webView(int index) const;
172     QLineEdit *lineEdit(int index) const;
173     int webViewIndex(WebView *webView) const;
174
175     QByteArray saveState() const;
176     bool restoreState(const QByteArray &state);
177
178 protected:
179     void mouseDoubleClickEvent(QMouseEvent *event);
180     void contextMenuEvent(QContextMenuEvent *event);
181     void mouseReleaseEvent(QMouseEvent *event);
182
183 public slots:
184     void loadUrlInCurrentTab(const QUrl &url);
185     WebView *newTab(bool makeCurrent = true);
186     void cloneTab(int index = -1);
187     void closeTab(int index = -1);
188     void closeOtherTabs(int index);
189     void reloadTab(int index = -1);
190     void reloadAllTabs();
191     void nextTab();
192     void previousTab();
193
194 private slots:
195     void currentChanged(int index);
196     void aboutToShowRecentTabsMenu();
197     void aboutToShowRecentTriggeredAction(QAction *action);
198     void webViewLoadStarted();
199     void webViewIconChanged();
200     void webViewTitleChanged(const QString &title);
201     void webViewUrlChanged(const QUrl &url);
202     void lineEditReturnPressed();
203     void windowCloseRequested();
204     void moveTab(int fromIndex, int toIndex);
205
206 private:
207     QAction *m_recentlyClosedTabsAction;
208     QAction *m_newTabAction;
209     QAction *m_closeTabAction;
210     QAction *m_nextTabAction;
211     QAction *m_previousTabAction;
212
213     QMenu *m_recentlyClosedTabsMenu;
214     static const int m_recentlyClosedTabsSize = 10;
215     QList<QUrl> m_recentlyClosedTabs;
216     QList<WebActionMapper*> m_actions;
217
218     QCompleter *m_lineEditCompleter;
219     QStackedWidget *m_lineEdits;
220     TabBar *m_tabBar;
221 };
222
223 #endif // TABWIDGET_H
224