1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the demonstration applications of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
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