author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 19 Feb 2010 23:40:16 +0200 | |
branch | RCL_3 |
changeset 4 | 3b1da2848fc7 |
parent 3 | 41300fa6a67c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
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 examples 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 |
#include <QtGui> |
|
43 |
#include <QtWebKit> |
|
44 |
#include "mainwindow.h" |
|
45 |
||
46 |
//! [1] |
|
47 |
||
48 |
MainWindow::MainWindow() |
|
49 |
{ |
|
50 |
progress = 0; |
|
51 |
||
52 |
QFile file; |
|
53 |
file.setFileName(":/jquery.min.js"); |
|
54 |
file.open(QIODevice::ReadOnly); |
|
55 |
jQuery = file.readAll(); |
|
56 |
file.close(); |
|
57 |
//! [1] |
|
58 |
||
59 |
QNetworkProxyFactory::setUseSystemConfiguration(true); |
|
60 |
||
61 |
//! [2] |
|
62 |
view = new QWebView(this); |
|
63 |
view->load(QUrl("http://www.google.com/ncr")); |
|
64 |
connect(view, SIGNAL(loadFinished(bool)), SLOT(adjustLocation())); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
65 |
connect(view, SIGNAL(titleChanged(QString)), SLOT(adjustTitle())); |
0 | 66 |
connect(view, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); |
67 |
connect(view, SIGNAL(loadFinished(bool)), SLOT(finishLoading(bool))); |
|
68 |
||
69 |
locationEdit = new QLineEdit(this); |
|
70 |
locationEdit->setSizePolicy(QSizePolicy::Expanding, locationEdit->sizePolicy().verticalPolicy()); |
|
71 |
connect(locationEdit, SIGNAL(returnPressed()), SLOT(changeLocation())); |
|
72 |
||
73 |
QToolBar *toolBar = addToolBar(tr("Navigation")); |
|
74 |
toolBar->addAction(view->pageAction(QWebPage::Back)); |
|
75 |
toolBar->addAction(view->pageAction(QWebPage::Forward)); |
|
76 |
toolBar->addAction(view->pageAction(QWebPage::Reload)); |
|
77 |
toolBar->addAction(view->pageAction(QWebPage::Stop)); |
|
78 |
toolBar->addWidget(locationEdit); |
|
79 |
//! [2] |
|
80 |
||
81 |
//! [3] |
|
82 |
QMenu *effectMenu = menuBar()->addMenu(tr("&Effect")); |
|
83 |
effectMenu->addAction("Highlight all links", this, SLOT(highlightAllLinks())); |
|
84 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
85 |
rotateAction = new QAction(this); |
0 | 86 |
rotateAction->setIcon(style()->standardIcon(QStyle::SP_FileDialogDetailedView)); |
87 |
rotateAction->setCheckable(true); |
|
88 |
rotateAction->setText(tr("Turn images upside down")); |
|
89 |
connect(rotateAction, SIGNAL(toggled(bool)), this, SLOT(rotateImages(bool))); |
|
90 |
effectMenu->addAction(rotateAction); |
|
91 |
||
92 |
QMenu *toolsMenu = menuBar()->addMenu(tr("&Tools")); |
|
93 |
toolsMenu->addAction(tr("Remove GIF images"), this, SLOT(removeGifImages())); |
|
94 |
toolsMenu->addAction(tr("Remove all inline frames"), this, SLOT(removeInlineFrames())); |
|
95 |
toolsMenu->addAction(tr("Remove all object elements"), this, SLOT(removeObjectElements())); |
|
96 |
toolsMenu->addAction(tr("Remove all embedded elements"), this, SLOT(removeEmbeddedElements())); |
|
97 |
||
98 |
setCentralWidget(view); |
|
99 |
setUnifiedTitleAndToolBarOnMac(true); |
|
100 |
} |
|
101 |
//! [3] |
|
102 |
||
103 |
//! [4] |
|
104 |
void MainWindow::adjustLocation() |
|
105 |
{ |
|
106 |
locationEdit->setText(view->url().toString()); |
|
107 |
} |
|
108 |
||
109 |
void MainWindow::changeLocation() |
|
110 |
{ |
|
111 |
QUrl url = QUrl(locationEdit->text()); |
|
112 |
view->load(url); |
|
113 |
view->setFocus(); |
|
114 |
} |
|
115 |
//! [4] |
|
116 |
||
117 |
//! [5] |
|
118 |
void MainWindow::adjustTitle() |
|
119 |
{ |
|
120 |
if (progress <= 0 || progress >= 100) |
|
121 |
setWindowTitle(view->title()); |
|
122 |
else |
|
123 |
setWindowTitle(QString("%1 (%2%)").arg(view->title()).arg(progress)); |
|
124 |
} |
|
125 |
||
126 |
void MainWindow::setProgress(int p) |
|
127 |
{ |
|
128 |
progress = p; |
|
129 |
adjustTitle(); |
|
130 |
} |
|
131 |
//! [5] |
|
132 |
||
133 |
//! [6] |
|
134 |
void MainWindow::finishLoading(bool) |
|
135 |
{ |
|
136 |
progress = 100; |
|
137 |
adjustTitle(); |
|
138 |
view->page()->mainFrame()->evaluateJavaScript(jQuery); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
139 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
140 |
rotateImages(rotateAction->isChecked()); |
0 | 141 |
} |
142 |
//! [6] |
|
143 |
||
144 |
//! [7] |
|
145 |
void MainWindow::highlightAllLinks() |
|
146 |
{ |
|
147 |
QString code = "$('a').each( function () { $(this).css('background-color', 'yellow') } )"; |
|
148 |
view->page()->mainFrame()->evaluateJavaScript(code); |
|
149 |
} |
|
150 |
//! [7] |
|
151 |
||
152 |
//! [8] |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
153 |
void MainWindow::rotateImages(bool invert) |
0 | 154 |
{ |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
155 |
QString code; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
156 |
if (invert) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
157 |
code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s'); $(this).css('-webkit-transform', 'rotate(180deg)') } )"; |
0 | 158 |
else |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
code = "$('img').each( function () { $(this).css('-webkit-transition', '-webkit-transform 2s'); $(this).css('-webkit-transform', 'rotate(0deg)') } )"; |
0 | 160 |
view->page()->mainFrame()->evaluateJavaScript(code); |
161 |
} |
|
162 |
//! [8] |
|
163 |
||
164 |
//! [9] |
|
165 |
void MainWindow::removeGifImages() |
|
166 |
{ |
|
167 |
QString code = "$('[src*=gif]').remove()"; |
|
168 |
view->page()->mainFrame()->evaluateJavaScript(code); |
|
169 |
} |
|
170 |
||
171 |
void MainWindow::removeInlineFrames() |
|
172 |
{ |
|
173 |
QString code = "$('iframe').remove()"; |
|
174 |
view->page()->mainFrame()->evaluateJavaScript(code); |
|
175 |
} |
|
176 |
||
177 |
void MainWindow::removeObjectElements() |
|
178 |
{ |
|
179 |
QString code = "$('object').remove()"; |
|
180 |
view->page()->mainFrame()->evaluateJavaScript(code); |
|
181 |
} |
|
182 |
||
183 |
void MainWindow::removeEmbeddedElements() |
|
184 |
{ |
|
185 |
QString code = "$('embed').remove()"; |
|
186 |
view->page()->mainFrame()->evaluateJavaScript(code); |
|
187 |
} |
|
188 |
//! [9] |
|
189 |