1 /****************************************************************************
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
6 ** This file is part of the demonstration applications of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
45 #include <QtGui/QTabBar>
47 #include <QtGui/QShortcut>
49 Tab bar with a few more features such as a context menu and shortcuts
51 class TabBar : public QTabBar
57 void cloneTab(int index);
58 void closeTab(int index);
59 void closeOtherTabs(int index);
60 void reloadTab(int index);
62 void tabMoveRequested(int fromIndex, int toIndex);
65 TabBar(QWidget *parent = 0);
68 void mousePressEvent(QMouseEvent* event);
69 void mouseMoveEvent(QMouseEvent* event);
72 void selectTabAction();
75 void closeOtherTabs();
77 void contextMenuRequested(const QPoint &position);
80 QList<QShortcut*> m_tabShortcuts;
81 friend class TabWidget;
83 QPoint m_dragStartPos;
84 int m_dragCurrentIndex;
87 #include <QtWebKit/QWebPage>
94 A proxy object that connects a single browser action
95 to one child webpage action at a time.
97 Example usage: used to keep the main window stop action in sync with
98 the current tabs webview's stop action.
100 class WebActionMapper : public QObject
105 WebActionMapper(QAction *root, QWebPage::WebAction webAction, QObject *parent);
106 QWebPage::WebAction webAction() const;
107 void addChild(QAction *action);
108 void updateCurrent(QWebPage *currentParent);
111 void rootTriggered();
113 void rootDestroyed();
114 void currentDestroyed();
117 QWebPage *m_currentParent;
119 QWebPage::WebAction m_webAction;
122 #include <QtCore/QUrl>
123 #include <QtGui/QTabWidget>
128 class QStackedWidget;
131 TabWidget that contains WebViews and a stack widget of associated line edits.
133 Connects up the current tab's signals to this class's signal and uses WebActionMapper
134 to proxy the actions.
136 class TabWidget : public QTabWidget
141 // tab widget signals
142 void loadPage(const QString &url);
144 void lastTabClosed();
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);
158 TabWidget(QWidget *parent = 0);
160 void addWebAction(QAction *action, QWebPage::WebAction webAction);
162 QAction *newTabAction() const;
163 QAction *closeTabAction() const;
164 QAction *recentlyClosedTabsAction() const;
165 QAction *nextTabAction() const;
166 QAction *previousTabAction() const;
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;
175 QByteArray saveState() const;
176 bool restoreState(const QByteArray &state);
179 void mouseDoubleClickEvent(QMouseEvent *event);
180 void contextMenuEvent(QContextMenuEvent *event);
181 void mouseReleaseEvent(QMouseEvent *event);
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();
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);
207 QAction *m_recentlyClosedTabsAction;
208 QAction *m_newTabAction;
209 QAction *m_closeTabAction;
210 QAction *m_nextTabAction;
211 QAction *m_previousTabAction;
213 QMenu *m_recentlyClosedTabsMenu;
214 static const int m_recentlyClosedTabsSize = 10;
215 QList<QUrl> m_recentlyClosedTabs;
216 QList<WebActionMapper*> m_actions;
218 QCompleter *m_lineEditCompleter;
219 QStackedWidget *m_lineEdits;
223 #endif // TABWIDGET_H