author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 20:15:53 +0300 | |
branch | RCL_3 |
changeset 13 | c0432d11811c |
parent 7 | 3f74d0d4af4c |
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 demos 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 "BrowserView.h" |
|
43 |
||
44 |
#include <QtGui> |
|
45 |
#include <QtNetwork> |
|
46 |
#include <QtWebKit> |
|
47 |
||
48 |
#include "ControlStrip.h" |
|
49 |
#include "TitleBar.h" |
|
50 |
#include "flickcharm.h" |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
51 |
#include "webview.h" |
0 | 52 |
#include "ZoomStrip.h" |
53 |
||
54 |
#if defined (Q_OS_SYMBIAN) |
|
55 |
#include "sym_iap_util.h" |
|
56 |
#endif |
|
57 |
||
58 |
BrowserView::BrowserView(QWidget *parent) |
|
59 |
: QWidget(parent) |
|
60 |
, m_titleBar(0) |
|
61 |
, m_webView(0) |
|
62 |
, m_progress(0) |
|
63 |
, m_currentZoom(100) |
|
64 |
{ |
|
65 |
m_titleBar = new TitleBar(this); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
66 |
m_webView = new WebView(this); |
0 | 67 |
m_zoomStrip = new ZoomStrip(this); |
68 |
m_controlStrip = new ControlStrip(this); |
|
69 |
||
70 |
m_zoomLevels << 30 << 50 << 67 << 80 << 90; |
|
71 |
m_zoomLevels << 100; |
|
72 |
m_zoomLevels << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; |
|
73 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
74 |
QTimer::singleShot(0, this, SLOT(initialize())); |
0 | 75 |
} |
76 |
||
77 |
void BrowserView::initialize() |
|
78 |
{ |
|
79 |
connect(m_zoomStrip, SIGNAL(zoomInClicked()), SLOT(zoomIn())); |
|
80 |
connect(m_zoomStrip, SIGNAL(zoomOutClicked()), SLOT(zoomOut())); |
|
81 |
||
82 |
connect(m_controlStrip, SIGNAL(menuClicked()), SIGNAL(menuButtonClicked())); |
|
83 |
connect(m_controlStrip, SIGNAL(backClicked()), m_webView, SLOT(back())); |
|
84 |
connect(m_controlStrip, SIGNAL(forwardClicked()), m_webView, SLOT(forward())); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
85 |
connect(m_controlStrip, SIGNAL(closeClicked()), qApp, SLOT(quit())); |
0 | 86 |
|
87 |
QPalette pal = m_webView->palette(); |
|
88 |
pal.setBrush(QPalette::Base, Qt::white); |
|
89 |
m_webView->setPalette(pal); |
|
90 |
||
91 |
FlickCharm *flickCharm = new FlickCharm(this); |
|
92 |
flickCharm->activateOn(m_webView); |
|
93 |
||
94 |
m_webView->setZoomFactor(static_cast<qreal>(m_currentZoom)/100.0); |
|
95 |
connect(m_webView, SIGNAL(loadStarted()), SLOT(start())); |
|
96 |
connect(m_webView, SIGNAL(loadProgress(int)), SLOT(setProgress(int))); |
|
97 |
connect(m_webView, SIGNAL(loadFinished(bool)), SLOT(finish(bool))); |
|
98 |
connect(m_webView, SIGNAL(urlChanged(QUrl)), SLOT(updateTitleBar())); |
|
99 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
m_webView->setHtml("about:blank"); |
0 | 101 |
m_webView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
102 |
m_webView->setFocus(); |
|
103 |
#ifdef Q_OS_SYMBIAN |
|
104 |
QTimer::singleShot(0, this, SLOT(setDefaultIap())); |
|
105 |
#endif |
|
106 |
} |
|
107 |
||
108 |
void BrowserView::start() |
|
109 |
{ |
|
110 |
m_progress = 0; |
|
111 |
updateTitleBar(); |
|
112 |
//m_titleBar->setText(m_webView->url().toString()); |
|
113 |
} |
|
114 |
||
115 |
void BrowserView::setProgress(int percent) |
|
116 |
{ |
|
117 |
m_progress = percent; |
|
118 |
updateTitleBar(); |
|
119 |
//m_titleBar->setText(QString("Loading %1%").arg(percent)); |
|
120 |
} |
|
121 |
||
122 |
void BrowserView::updateTitleBar() |
|
123 |
{ |
|
124 |
QUrl url = m_webView->url(); |
|
125 |
m_titleBar->setHost(url.host()); |
|
126 |
m_titleBar->setTitle(m_webView->title()); |
|
127 |
m_titleBar->setProgress(m_progress); |
|
128 |
} |
|
129 |
||
130 |
void BrowserView::finish(bool ok) |
|
131 |
{ |
|
132 |
m_progress = 0; |
|
133 |
updateTitleBar(); |
|
134 |
||
135 |
// TODO: handle error |
|
136 |
if (!ok) { |
|
137 |
//m_titleBar->setText("Loading failed."); |
|
138 |
} |
|
139 |
} |
|
140 |
||
141 |
void BrowserView::zoomIn() |
|
142 |
{ |
|
143 |
int i = m_zoomLevels.indexOf(m_currentZoom); |
|
144 |
Q_ASSERT(i >= 0); |
|
145 |
if (i < m_zoomLevels.count() - 1) |
|
146 |
m_currentZoom = m_zoomLevels[i + 1]; |
|
147 |
||
148 |
m_webView->setZoomFactor(static_cast<qreal>(m_currentZoom)/100.0); |
|
149 |
} |
|
150 |
||
151 |
void BrowserView::zoomOut() |
|
152 |
{ |
|
153 |
int i = m_zoomLevels.indexOf(m_currentZoom); |
|
154 |
Q_ASSERT(i >= 0); |
|
155 |
if (i > 0) |
|
156 |
m_currentZoom = m_zoomLevels[i - 1]; |
|
157 |
||
158 |
m_webView->setZoomFactor(static_cast<qreal>(m_currentZoom)/100.0); |
|
159 |
} |
|
160 |
||
161 |
void BrowserView::resizeEvent(QResizeEvent *event) |
|
162 |
{ |
|
163 |
QWidget::resizeEvent(event); |
|
164 |
||
165 |
int h1 = m_titleBar->sizeHint().height(); |
|
166 |
int h2 = m_controlStrip->sizeHint().height(); |
|
167 |
||
168 |
m_titleBar->setGeometry(0, 0, width(), h1); |
|
169 |
m_controlStrip->setGeometry(0, height() - h2, width(), h2); |
|
170 |
m_webView->setGeometry(0, h1, width(), height() - h1); |
|
171 |
||
172 |
int zw = m_zoomStrip->sizeHint().width(); |
|
173 |
int zh = m_zoomStrip->sizeHint().height(); |
|
174 |
m_zoomStrip->move(width() - zw, (height() - zh) / 2); |
|
175 |
} |
|
176 |
#ifdef Q_OS_SYMBIAN |
|
177 |
void BrowserView::setDefaultIap() |
|
178 |
{ |
|
179 |
qt_SetDefaultIap(); |
|
180 |
m_webView->load(QUrl("http://news.bbc.co.uk/text_only.stm")); |
|
181 |
} |
|
182 |
#endif |
|
183 |
||
184 |
void BrowserView::navigate(const QUrl &url) |
|
185 |
{ |
|
186 |
m_webView->load(url); |
|
187 |
} |