author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 29 Apr 2010 15:15:16 +0300 | |
branch | RCL_3 |
changeset 16 | 4b6ee5efea19 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the demonstration applications of the Qt Toolkit. |
|
8 |
** |
|
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 |
|
14 |
** this package. |
|
15 |
** |
|
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. |
|
23 |
** |
|
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. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
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 |