1 /* |
1 /* |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
4 * |
9 * Initial Contributors: |
5 * This program is free software: you can redistribute it and/or modify |
10 * Nokia Corporation - initial contribution. |
6 * it under the terms of the GNU Lesser General Public License as published by |
|
7 * the Free Software Foundation, version 2.1 of the License. |
11 * |
8 * |
12 * Contributors: |
9 * This program is distributed in the hope that it will be useful, |
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 * GNU Lesser General Public License for more details. |
13 * |
13 * |
14 * Description: |
14 * You should have received a copy of the GNU Lesser General Public License |
|
15 * along with this program. If not, |
|
16 * see "http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html/". |
|
17 * |
|
18 * Description: |
15 * |
19 * |
16 */ |
20 */ |
17 |
|
18 |
21 |
19 #include <QtGui> |
22 #include <QtGui> |
20 #include <QWebPage> |
23 #include <QWebPage> |
21 |
24 |
22 #include "ChromeView.h" |
25 #include "ChromeView.h" |
23 #include "ChromeWidget.h" |
26 #include "ChromeWidget.h" //TODO: get rid of this, refer directly to layout |
|
27 #include "ChromeLayout.h" |
24 #ifndef NO_QSTM_GESTURE |
28 #ifndef NO_QSTM_GESTURE |
25 #include "qstmgestureevent.h" |
29 #include "qstmgestureevent.h" |
26 #endif |
30 #endif |
27 |
31 |
28 #ifdef Q_OS_SYMBIAN |
32 #ifdef Q_OS_SYMBIAN |
29 #ifdef SET_DEFAULT_IAP |
33 #ifdef SET_DEFAULT_IAP |
30 #include "sym_iap_util.h" |
34 #include "sym_iap_util.h" |
31 #endif //SET_DEFAULT_IAP |
35 #endif //SET_DEFAULT_IAP |
32 #endif //Q_OS_SYMBIAN |
36 #endif //Q_OS_SYMBIAN |
33 |
37 |
|
38 #ifdef ENABLE_PERF_TRACE |
|
39 #include "wrtperftracer.h" |
|
40 #endif |
|
41 |
34 namespace GVA { |
42 namespace GVA { |
35 |
43 |
36 ChromeView::ChromeView(ChromeWidget * chrome, QWidget * parent) |
44 ChromeView::ChromeView(QGraphicsScene *graphicsScene, ChromeWidget * chrome, QWidget * parent) |
37 : QGraphicsView(chrome->scene(), parent), |
45 #ifdef ORBIT_UI |
38 m_topWidget(chrome) |
46 : HbMainWindow(parent), |
|
47 #else |
|
48 : QGraphicsView(graphicsScene, parent), |
|
49 #endif // ORBIT_UI |
|
50 m_chrome(chrome), |
|
51 m_topWidget(chrome->layout()) |
39 { |
52 { |
|
53 #ifdef ORBIT_UI |
|
54 addView(chrome->layout()); |
|
55 #endif // ORRBIT_UI |
|
56 |
|
57 // Initialize the ChromeWidget with the scene created in the ChromeView |
|
58 chrome->layout()->setScene(scene()); |
|
59 |
40 //setGeometry(chrome->geometry().toRect()); |
60 //setGeometry(chrome->geometry().toRect()); |
41 setObjectName("ChromeView"); |
61 setObjectName("ChromeView"); |
42 //When content view is external widget, make the background transparent |
62 //When content view is external widget, make the background transparent |
43 //setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:transparent}"); |
63 //setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:transparent}"); |
44 setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:#fff}"); |
64 setStyleSheet("QGraphicsView#ChromeView {margin:0; border: 0; padding:0; background:#fff}"); |
45 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
65 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
46 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
66 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); |
|
67 |
|
68 #ifdef BEDROCK_TILED_BACKING_STORE |
|
69 setFrameShape(QFrame::NoFrame); |
|
70 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
71 scene()->setItemIndexMethod(QGraphicsScene::NoIndex); |
|
72 #endif |
|
73 |
47 //NB: maybe not needed? |
74 //NB: maybe not needed? |
48 setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); |
75 setViewportUpdateMode(QGraphicsView::MinimalViewportUpdate); |
49 //installEventFilter(this); |
76 //installEventFilter(this); |
50 //chrome->page()->setView(this); |
77 //chrome->page()->setView(this); |
51 #ifndef NO_QSTM_GESTURE |
78 #ifndef NO_QSTM_GESTURE |
61 QTimer::singleShot(0, this, SLOT(setDefaultIap())); |
88 QTimer::singleShot(0, this, SLOT(setDefaultIap())); |
62 //setDefaultIap(); |
89 //setDefaultIap(); |
63 #endif //SET_DEFAULT_IAP |
90 #endif //SET_DEFAULT_IAP |
64 #endif //Q_OS_SYMBIAN |
91 #endif //Q_OS_SYMBIAN |
65 } |
92 } |
66 |
93 |
67 ChromeView::~ChromeView() |
94 ChromeView::~ChromeView() |
68 { |
95 { |
69 |
|
70 } |
96 } |
71 |
97 |
72 void ChromeView::resizeEvent(QResizeEvent * ev) |
98 void ChromeView::resizeEvent(QResizeEvent * ev) |
73 { |
99 { |
74 //Resize the chrome to match the view and scene rectangle size |
100 //Resize the chrome to match the view and scene rectangle size |
|
101 if (m_topWidget) { |
75 |
102 |
76 if(m_topWidget) |
103 // On calling setGeometry on QGraphicsWidget, the layout resizes if |
77 m_topWidget->setGeometry(0,0, ev->size().width(), ev->size().height()); |
104 // first called before resize on children happens. In order to avoid painting |
78 QGraphicsView::resizeEvent(ev); |
105 // the children in their old positions, first let children change size |
|
106 // ChromeWidget * w = static_cast<ChromeWidget*>(m_topWidget); |
|
107 // w->sizeChange(ev->size()); |
|
108 //TODO: move sizeChange to ChromeLayout, remove m_chrome member !!!!! |
|
109 m_chrome->sizeChange(ev->size()); |
|
110 m_topWidget->setGeometry(0,0, ev->size().width(), ev->size().height()); |
|
111 } |
|
112 QGraphicsView::resizeEvent(ev); |
|
113 |
|
114 #ifdef BEDROCK_TILED_BACKING_STORE |
|
115 if (scene()) { |
|
116 QRectF rect(QPointF(0, 0), size()); |
|
117 scene()->setSceneRect(rect); |
|
118 } |
|
119 #endif |
79 } |
120 } |
80 |
121 |
81 //Never scroll the chrome |
122 //Never scroll the chrome |
82 //NB: this shouldn't be needed, but some events from |
123 //NB: this shouldn't be needed, but some events from |
83 //the chrome are causing scrolling. Need to track this |
124 //the chrome are causing scrolling. Need to track this |
84 //down further. |
125 //down further. |
85 |
126 |
86 void ChromeView::scrollContentsBy(int dx, int dy) |
127 void ChromeView::scrollContentsBy(int dx, int dy) |
87 { |
128 { |
|
129 Q_UNUSED(dx) |
|
130 Q_UNUSED(dy) |
88 // qDebug() << "View scroll"; |
131 // qDebug() << "View scroll"; |
89 // QGraphicsView::scrollContentsBy(dx, dy); |
132 // QGraphicsView::scrollContentsBy(dx, dy); |
90 } |
133 } |
91 |
134 |
92 //Eat key events not otherwise consumed. |
135 //Eat key events not otherwise consumed. |
93 /* bool ChromeView::eventFilter(QObject * obj, QEvent * ev) |
136 /* bool ChromeView::eventFilter(QObject * obj, QEvent * ev) |
94 { |
137 { |
95 if(ev->type() == QEvent::KeyPress){ |
138 if (ev->type() == QEvent::KeyPress){ |
96 int key = static_cast<QKeyEvent*>(ev)->key(); |
139 int key = static_cast<QKeyEvent*>(ev)->key(); |
97 if(key == Qt::Key_Down || key == Qt::Key_Up || key ==Qt::Key_Left){ |
140 if (key == Qt::Key_Down || key == Qt::Key_Up || key ==Qt::Key_Left){ |
98 return true; |
141 return true; |
99 } |
142 } |
100 } |
143 } |
101 return QObject::eventFilter(obj,ev); |
144 return QObject::eventFilter(obj,ev); |
102 |
145 |
103 }*/ |
146 }*/ |
104 |
147 |
105 bool ChromeView::event(QEvent* event) |
148 bool ChromeView::event(QEvent* event) |
106 { |
149 { |
107 #ifndef NO_QSTM_GESTURE |
150 #ifndef NO_QSTM_GESTURE |
108 if (event->type() == QEvent::Gesture) { |
151 if (event->type() == QEvent::Gesture) { |
109 QStm_Gesture* gesture = getQStmGesture(event); |
152 QStm_Gesture* gesture = getQStmGesture(event); |
110 if (gesture) { |
153 if (gesture) { |
111 QPoint pos = mapFromGlobal(gesture->position()); |
154 QPoint pos = mapFromGlobal(gesture->position()); |
112 QGraphicsScene* gs = scene(); |
155 QGraphicsScene* gs = scene(); |
113 QGraphicsItem* gi = gs->itemAt(QPointF(pos)); |
156 QGraphicsItem* gi = gs->itemAt(QPointF(pos)); |
114 |
157 |
115 if (gi) { |
158 if (gi) { |
116 gs->sendEvent(gi, event); |
159 gs->sendEvent(gi, event); |
117 } |
160 } |
118 return true; |
161 return true; |
119 } |
162 } |
120 } |
163 } |
121 #endif |
164 #endif |
122 return QGraphicsView::event(event); |
165 return QGraphicsView::event(event); |
123 } |
166 } |
124 |
167 |
125 #ifdef Q_OS_SYMBIAN |
168 #ifdef Q_OS_SYMBIAN |
126 #ifdef SET_DEFAULT_IAP |
169 #ifdef SET_DEFAULT_IAP |
127 void ChromeView::setDefaultIap() |
170 void ChromeView::setDefaultIap() |