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 <QWebElement> |
22 #include <QWebElement> |
20 #include <QWebPage> |
23 #include <QWebPage> |
21 #include <QWebFrame> |
24 #include <QWebFrame> |
22 #include <QList> |
25 #include <QList> |
23 #include <QKeyEvent> |
26 #include <QKeyEvent> |
24 #include <QDebug> |
27 #include <QDebug> |
|
28 #include <QDesktopServices> |
25 #include <QGraphicsSceneContextMenuEvent> |
29 #include <QGraphicsSceneContextMenuEvent> |
26 |
30 |
|
31 #include "bedrockprovisioning.h" |
27 #include "ChromeWidgetJSObject.h" |
32 #include "ChromeWidgetJSObject.h" |
28 #include "ChromeRenderer.h" |
33 #include "ChromeRenderer.h" |
29 #include "ChromeDOM.h" |
34 #include "ChromeDOM.h" |
30 #include "Snippets.h" |
35 #include "Snippets.h" |
|
36 #include "ChromeEffect.h" |
31 #include "ChromeSnippet.h" |
37 #include "ChromeSnippet.h" |
32 #include "ChromeWidget.h" |
38 #include "ChromeWidget.h" |
33 #include "WebChromeContainerSnippet.h" |
39 #include "WebChromeContainerSnippet.h" |
34 #include "Application.h" |
40 #include "Application.h" |
35 #include "AppContentView.h" |
|
36 #include "BlueChromeSnippet.h" |
|
37 #include "GreenChromeSnippet.h" |
|
38 #include "ViewController.h" |
41 #include "ViewController.h" |
39 #include "ViewStack.h" |
42 #include "ViewStack.h" |
40 //#include "CollapsingWidget.h" |
43 //#include "CollapsingWidget.h" |
41 #include "SlidingWidget.h" |
44 #include "SlidingWidget.h" |
42 #include "ProgressSnippet.h" |
|
43 #include "GWebPage.h" |
45 #include "GWebPage.h" |
44 #include "webpagecontroller.h" |
46 #include "webpagecontroller.h" |
45 //#include "ViewStack.h" |
47 //#include "ViewStack.h" |
46 #include "BookmarksManager.h" |
48 #include "BookmarksManager.h" |
47 #include "ScriptObjects.h" |
49 #include "ScriptObjects.h" |
48 #include "LocaleDelegate.h" |
50 #include "LocaleDelegate.h" |
49 #include "DeviceDelegate.h" |
51 #include "DeviceDelegate.h" |
50 |
52 #include "NetworkDelegate.h" |
51 #ifdef USE_DOWNLOAD_MANAGER |
53 #include "ObjectCharm.h" |
|
54 #include "bedrockprovisioning.h" |
|
55 #include "Utilities.h" |
|
56 #include "PopupWebChromeItem.h" |
|
57 #ifdef QT_MOBILITY_SYSINFO |
|
58 #include "SystemDeviceImpl.h" |
|
59 #include "SystemNetworkImpl.h" |
|
60 #endif |
|
61 |
52 #include "Downloads.h" |
62 #include "Downloads.h" |
53 #endif |
|
54 |
63 |
55 #include "wrtbrowsercontainer.h" |
64 #include "wrtbrowsercontainer.h" |
56 #include "webpagecontroller.h" |
65 #include "webpagecontroller.h" |
57 |
66 |
|
67 #include "GAlternateFileChooser.h" |
|
68 |
58 namespace GVA { |
69 namespace GVA { |
59 |
70 |
60 // ----------------------------- |
71 // ----------------------------- |
61 |
72 |
62 ChromeWidget::ChromeWidget(QGraphicsItem * parent, Qt::WindowFlags wFlags) |
73 ChromeWidget::ChromeWidget(QGraphicsItem * parent, Qt::WindowFlags wFlags) |
63 : QGraphicsWidget(parent, wFlags), |
74 : QGraphicsWidget(parent, wFlags), |
64 m_renderer(0), |
75 m_renderer(0), |
65 m_dom(0), |
76 m_dom(0), |
66 m_viewController(new ViewController()), |
77 m_viewController(new ViewController()), |
67 m_topBar(0), |
78 m_topBar(0), |
107 // Pass some signals from this object to the Javascript object. |
124 // Pass some signals from this object to the Javascript object. |
108 QObject::connect(this, SIGNAL(chromeComplete()), m_jsObject, SIGNAL(chromeComplete())); |
125 QObject::connect(this, SIGNAL(chromeComplete()), m_jsObject, SIGNAL(chromeComplete())); |
109 QObject::connect(this, SIGNAL(aspectChanged(int)), m_jsObject, SIGNAL(aspectChanged(int))); |
126 QObject::connect(this, SIGNAL(aspectChanged(int)), m_jsObject, SIGNAL(aspectChanged(int))); |
110 QObject::connect(this, SIGNAL(prepareForGeometryChange()), m_jsObject, SIGNAL(prepareForGeometryChange())); |
127 QObject::connect(this, SIGNAL(prepareForGeometryChange()), m_jsObject, SIGNAL(prepareForGeometryChange())); |
111 QObject::connect(this, SIGNAL(symbianCarriageReturn()), m_jsObject, SIGNAL(symbianCarriageReturn())); |
128 QObject::connect(this, SIGNAL(symbianCarriageReturn()), m_jsObject, SIGNAL(symbianCarriageReturn())); |
|
129 QObject::connect(this, SIGNAL(popupShown(const QString &)), m_jsObject, SIGNAL(popupShown(const QString &))); |
|
130 QObject::connect(this, SIGNAL(popupHidden(const QString &)), m_jsObject, SIGNAL(popupHidden(const QString &))); |
112 |
131 |
113 //addJSObjectToEngine(this); |
132 //addJSObjectToEngine(this); |
114 m_app = new GinebraApplication(); |
133 m_app = new GinebraApplication(); |
115 //addJSObjectToEngine(m_app); |
134 //addJSObjectToEngine(m_app); |
116 |
135 |
117 #ifdef USE_DOWNLOAD_MANAGER |
|
118 m_downloads = new Downloads(); |
|
119 QObject::connect( |
136 QObject::connect( |
120 WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)), |
137 WebPageController::getSingleton(), SIGNAL(pageCreated(WRT::WrtBrowserContainer*)), |
121 this, SLOT(pageCreated(WRT::WrtBrowserContainer*))); |
138 this, SLOT(pageCreated(WRT::WrtBrowserContainer*))); |
122 #endif |
139 |
123 |
|
124 QObject::connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); |
140 QObject::connect(m_page, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished(bool))); |
125 QObject::connect(m_page, SIGNAL(loadStarted()), this, SLOT(loadStarted())); |
141 QObject::connect(m_page, SIGNAL(loadStarted()), this, SLOT(loadStarted())); |
126 QObject::connect(m_page->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(exportJSObjects())); |
142 QObject::connect(m_page->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(exportJSObjects())); |
127 |
143 |
128 #endif |
144 #endif |
129 |
145 |
130 ViewStack::getSingleton()->setViewController(m_viewController); |
146 ViewStack * vs = ViewStack::getSingleton(); |
|
147 vs->setViewController(m_viewController); |
|
148 vs->setChromeWidget(this); |
|
149 |
131 // TO DO: need a better home for this. |
150 // TO DO: need a better home for this. |
132 qMetaTypeId<QObjectList>(); |
151 qMetaTypeId<QObjectList>(); |
133 qRegisterMetaType<QObjectList>("QObjectList"); |
152 qRegisterMetaType<QObjectList>("QObjectList"); |
134 } |
153 } |
135 |
154 |
142 } |
161 } |
143 } |
162 } |
144 |
163 |
145 void ChromeWidget::pageCreated(WRT::WrtBrowserContainer * page) |
164 void ChromeWidget::pageCreated(WRT::WrtBrowserContainer * page) |
146 { |
165 { |
147 #ifdef USE_DOWNLOAD_MANAGER |
166 #ifdef Q_OS_SYMBIAN |
148 if (m_downloads) { |
167 QString path = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation); |
149 m_downloads->handlePage(page); |
168 GAlternateFileChooser * chooser = new GAlternateFileChooser(path); |
150 } |
169 page->setFileChooser(chooser); // chooser is now owned by page |
151 #else |
170 #endif |
152 Q_UNUSED(page) |
171 m_downloads->handlePage(page); |
153 #endif |
|
154 } |
172 } |
155 |
173 |
156 ChromeWidget::~ChromeWidget() |
174 ChromeWidget::~ChromeWidget() |
157 { |
175 { |
158 // clearChrome(); // crashes on exit |
176 // clearChrome(); // Crashes on exit |
159 delete m_viewController; |
177 delete m_viewController; |
|
178 delete m_jsObject; |
160 delete m_bottomBar; |
179 delete m_bottomBar; |
161 delete m_topBar; |
180 delete m_topBar; |
162 delete m_leftBar; |
181 delete m_leftBar; |
163 delete m_rightBar; |
182 delete m_rightBar; |
164 delete m_viewPort; |
183 delete m_viewPort; |
165 // delete m_viewLayout; // crashes on exit |
184 // delete m_viewLayout; // Crashes on exit |
166 delete m_renderer; |
185 delete m_renderer; |
167 delete m_dom; |
186 delete m_dom; |
168 delete m_page; |
187 delete m_page; |
169 // delete m_scene; // crashes on exit |
188 // delete m_scene; // Crashes on exit |
170 delete m_snippets; |
189 delete m_snippets; |
171 // delete m_layout; // crashes on exit |
190 // delete m_layout; // Crashes on exit |
172 delete m_localeDelegate; |
191 delete m_localeDelegate; |
173 delete m_deviceDelegate; |
192 delete m_deviceDelegate; |
174 #ifdef USE_DOWNLOAD_MANAGER |
193 delete m_networkDelegate; |
|
194 delete m_app; |
175 delete m_downloads; |
195 delete m_downloads; |
176 #endif |
196 } |
177 } |
197 |
178 |
|
179 |
198 |
180 //Eat key events not otherwise consumed. |
199 //Eat key events not otherwise consumed. |
181 /*bool ChromeWidget::eventFilter(QObject * obj, QEvent * ev) |
200 /*bool ChromeWidget::eventFilter(QObject * obj, QEvent * ev) |
182 { |
201 { |
183 if(ev->type() == QEvent::KeyPress){ |
202 if (ev->type() == QEvent::KeyPress){ |
184 return true; |
203 return true; |
185 } |
204 } |
186 return QObject::eventFilter(obj,ev); |
205 return QObject::eventFilter(obj,ev); |
187 |
206 |
188 }*/ |
207 }*/ |
189 |
208 |
190 void ChromeWidget::resizeEvent(QGraphicsSceneResizeEvent *ev) |
209 void ChromeWidget::resizeEvent(QGraphicsSceneResizeEvent *ev) |
191 { |
210 { |
192 #ifndef __gva_no_chrome__ |
211 #ifndef __gva_no_chrome__ |
193 if(m_dom && m_renderer) { |
212 if (m_dom && m_renderer) { |
194 emit prepareForGeometryChange(); |
213 emit prepareForGeometryChange(); |
195 m_renderer->setGeometry(QRectF(-1200,-1200, ev->newSize().width(), m_dom->height())); |
214 // m_renderer->setGeometry(QRectF(-1200,-1200, ev->newSize().width(), m_dom->height())); |
|
215 m_renderer->resize(QSizeF(ev->newSize().width(), m_dom->height())); |
196 } |
216 } |
197 int aspect = m_aspect; |
217 int aspect = m_aspect; |
198 m_aspect = (ev->newSize().width() > ev->newSize().height())?landscape:portrait; |
218 m_aspect = (ev->newSize().width() > ev->newSize().height())?landscape:portrait; |
199 if(m_aspect != aspect) { |
219 if (m_aspect != aspect) { |
200 QString mode = (m_aspect == landscape ? "Landscape" : "Portrait"); |
220 QString mode = (m_aspect == landscape ? "Landscape" : "Portrait"); |
201 ControllableViewBase* cview = m_viewController->currentView(); |
221 ControllableViewBase* cview = m_viewController->currentView(); |
202 if (cview) |
222 if (cview) |
203 cview->displayModeChanged(mode); |
223 cview->displayModeChanged(mode); |
204 emit aspectChanged(m_aspect); |
224 emit aspectChanged(m_aspect); |
205 } |
225 } |
206 #endif |
226 #endif |
207 QGraphicsWidget::resizeEvent(ev); |
227 QGraphicsWidget::resizeEvent(ev); |
208 |
228 } |
|
229 |
|
230 void ChromeWidget::updateChromeLayout() { |
|
231 qDebug() << "ChromeWidget::updateChromeLayout"; |
|
232 m_renderer->updateChromeLayout(); |
209 } |
233 } |
210 |
234 |
211 /* |
235 /* |
212 //For layout debugging |
236 //For layout debugging |
213 void ChromeWidget::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget* widget){ |
237 void ChromeWidget::paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget* widget){ |
268 { |
293 { |
269 Q_UNUSED(where) |
294 Q_UNUSED(where) |
270 //m_viewBar->addItem(snippet); |
295 //m_viewBar->addItem(snippet); |
271 m_viewPort->attachItem(snippet->widget()); |
296 m_viewPort->attachItem(snippet->widget()); |
272 } |
297 } |
273 |
298 |
274 void ChromeWidget::detachFromView(ChromeSnippet* snippet, const QString& where) |
299 void ChromeWidget::detachFromView(ChromeSnippet* snippet, const QString& where) |
275 { |
300 { |
276 Q_UNUSED(where) |
301 Q_UNUSED(where) |
277 // m_viewBar->removeItem(snippet); |
302 // m_viewBar->removeItem(snippet); |
278 m_viewPort->detachItem(snippet->widget()); |
303 m_viewPort->detachItem(snippet->widget()); |
279 } |
304 } |
280 |
305 |
281 void ChromeWidget::anchorTogether(ChromeSnippet* first, const QString& secondId, qreal x, qreal y) |
306 void ChromeWidget::anchorTogether(ChromeSnippet* first, const QString& secondId, qreal x, qreal y) |
282 { |
307 { |
283 ChromeSnippet* second = getSnippet(secondId); |
308 ChromeSnippet* second = getSnippet(secondId); |
284 if (second){ |
309 if (second){ |
285 //qDebug() << "Anchoring: " << first->objectName() << " to: " << second->objectName(); |
310 //qDebug() << "Anchoring: " << first->objectName() << " to: " << second->objectName(); |
286 first->widget()->setParentItem(second->widget()); |
311 first->widget()->setParentItem(second->widget()); |
287 first->widget()->setPos(x,y); |
312 first->widget()->setPos(x,y); |
288 } |
313 } |
|
314 else { |
|
315 qDebug() << "ChromeWidget::anchorTogether: error, not found: " << secondId; |
|
316 } |
289 } |
317 } |
290 |
318 |
291 void ChromeWidget::unAnchor(ChromeSnippet* snippet) |
319 void ChromeWidget::unAnchor(ChromeSnippet* snippet) |
292 { |
320 { |
293 snippet->widget()->setParentItem(0); |
321 snippet->widget()->setParentItem(0); |
294 snippet->widget()->setParentItem(this); |
322 snippet->widget()->setParentItem(this); |
295 } |
323 } |
296 |
324 |
|
325 qreal ChromeWidget::shrinkView(qreal delta) |
|
326 { |
|
327 m_viewPort->setShrinkMax(bottomBarHeight()); |
|
328 return m_viewPort->shrink(delta); |
|
329 } |
|
330 |
297 qreal ChromeWidget::slideView(qreal delta) |
331 qreal ChromeWidget::slideView(qreal delta) |
298 { |
332 { |
299 //return m_viewBar->collapse(delta); |
333 //return m_viewBar->collapse(delta); |
300 return m_viewPort->slide(delta); |
334 return m_viewPort->slide(delta); |
301 } |
335 } |
302 |
336 |
303 ControllableViewBase * ChromeWidget::getView(const QString& view) |
337 ControllableViewBase * ChromeWidget::getView(const QString& view) |
304 { |
338 { |
305 return m_viewController->view(view); |
339 return m_viewController->view(view); |
306 } |
340 } |
307 |
341 |
308 void ChromeWidget::showView(const QString &name) { |
342 void ChromeWidget::showView(const QString &name) { |
309 qDebug() << "ChromeWidget::showView: " << name; |
343 qDebug() << "ChromeWidget::showView: " << name; |
310 m_viewController->showView(name); |
344 m_viewController->showView(name); |
311 } |
345 } |
326 clearChrome(); |
360 clearChrome(); |
327 } |
361 } |
328 |
362 |
329 void ChromeWidget::loadFinished(bool ok) // slot |
363 void ChromeWidget::loadFinished(bool ok) // slot |
330 { |
364 { |
331 //qDebug() << "ChromeWidget::loadFinished"; |
365 qDebug() << "ChromeWidget::loadFinished: " << ok; |
332 if(!ok) |
366 if (!ok) { |
333 { |
|
334 qDebug() << "ChromeWidget::loadFinished: error"; |
367 qDebug() << "ChromeWidget::loadFinished: error"; |
335 return; |
368 return; |
336 } |
369 } |
337 //NB: do we really need to instantiate a new renderer? |
370 //NB: do we really need to instantiate a new renderer? |
338 if(m_renderer) |
371 if (m_renderer) |
339 delete m_renderer; |
372 delete m_renderer; |
340 // qDebug() << "Instantiate renderer"; |
373 // qDebug() << "Instantiate renderer"; |
341 m_renderer = new ChromeRenderer(m_page, this); |
374 m_renderer = new ChromeRenderer(m_page, this); |
342 // qDebug() << "Resize the renderer 1"; |
375 // qDebug() << "Resize the renderer 1"; |
343 m_renderer->resize(size()); |
376 m_renderer->resize(size()); |
344 m_renderer->setPos(-1200, -1200); |
377 // m_renderer->setPos(-1200, -1200); |
345 m_renderer->setZValue(-3); |
378 // m_renderer->setZValue(-3); |
346 #ifdef Q_OS_SYMBIAN |
379 #ifdef Q_OS_SYMBIAN |
347 connect(m_renderer, SIGNAL(symbianCarriageReturn()), this, SIGNAL(symbianCarriageReturn())); |
380 //connect(m_renderer, SIGNAL(symbianCarriageReturn()), this, SIGNAL(symbianCarriageReturn())); |
348 #endif |
381 #endif |
349 if(m_dom) |
382 if (m_dom) |
350 delete m_dom; // NB: This may need some further investigation |
383 delete m_dom; // NB: This may need some further investigation |
351 m_dom = new ChromeDOM(m_page, this); |
384 m_dom = new ChromeDOM(m_page, this); |
352 getInitialSnippets(); |
385 getInitialSnippets(); |
353 //Set the final renderer size to match the chrome |
386 //Set the final renderer size to match the chrome |
354 m_renderer->resize(size().width(), m_dom->height()); |
387 //m_renderer->resize(size().width(), m_dom->height()); |
|
388 m_renderer->resize(QSizeF(size().width(), m_dom->height())); |
355 //qDebug() << m_dom->getCacheableScript(); |
389 //qDebug() << m_dom->getCacheableScript(); |
356 |
390 |
357 // Let internal objects know that the chrome is complete. |
391 // Let internal objects know that the chrome is complete. |
358 emit internalChromeComplete(); |
392 emit internalChromeComplete(); |
359 // Now let the javascript world know that it is complete. |
393 // Now let the javascript world know that it is complete. |
360 emit chromeComplete(); |
394 emit chromeComplete(); |
|
395 |
|
396 // connect ViewStack to creatingPage signal |
|
397 connect( WebPageController::getSingleton(), SIGNAL(creatingPage(WRT::WrtBrowserContainer*)), |
|
398 ViewStack::getSingleton(), SLOT(creatingPage(WRT::WrtBrowserContainer*))); |
|
399 qDebug() << "ChromeWidget::loadFinished: done"; |
361 } |
400 } |
362 |
401 |
363 void ChromeWidget::chromeInitialized() |
402 void ChromeWidget::chromeInitialized() |
364 { |
403 { |
365 //NB: Don't want to implement this, but just in case |
404 //NB: Don't want to implement this, but just in case |
378 addJSObjectToPage(WebPageController::getSingleton(), page); |
417 addJSObjectToPage(WebPageController::getSingleton(), page); |
379 addJSObjectToPage(WRT::BookmarksManager::getSingleton(), page); |
418 addJSObjectToPage(WRT::BookmarksManager::getSingleton(), page); |
380 addJSObjectToPage(ViewStack::getSingleton(), page); |
419 addJSObjectToPage(ViewStack::getSingleton(), page); |
381 addJSObjectToPage(m_localeDelegate, page); |
420 addJSObjectToPage(m_localeDelegate, page); |
382 addJSObjectToPage(m_deviceDelegate, page); |
421 addJSObjectToPage(m_deviceDelegate, page); |
|
422 addJSObjectToPage(m_networkDelegate, page); |
383 // Dynamically added objects |
423 // Dynamically added objects |
384 foreach(QObject * jsObj, m_jsObjects) { |
424 //foreach(QObject * jsObj, m_jsObjects) { |
385 addJSObjectToPage(jsObj, page); |
425 // addJSObjectToPage(jsObj, page); |
386 } |
426 // } |
387 #ifdef USE_DOWNLOAD_MANAGER |
427 addJSObjectToPage(m_downloads, page); |
388 if (m_downloads != 0) { |
|
389 addJSObjectToPage(m_downloads, page); |
|
390 } |
|
391 #endif |
|
392 } |
428 } |
393 |
429 |
394 void ChromeWidget::getInitialSnippets() |
430 void ChromeWidget::getInitialSnippets() |
395 { |
431 { |
396 //TODO: get the list of containers form m_dom (via new method to be added). |
432 //TODO: get the list of containers form m_dom (via new method to be added). |
397 QList <QWebElement> initialSnippets = m_dom->getInitialElements(); |
433 QList <QWebElement> initialSnippets = m_dom->getInitialElements(); |
398 foreach(QWebElement element, initialSnippets) { |
434 foreach(QWebElement element, initialSnippets) { |
399 ChromeSnippet * s = getSnippet(element.attribute("id")); |
435 ChromeSnippet * s = getSnippet(element.attribute("id")); |
400 if(s->initiallyVisible()) |
436 if (s->initiallyVisible()) |
401 s->setVisible(true); |
437 s->setVisible(true); |
402 } |
438 } |
403 } |
439 } |
404 |
440 |
405 void ChromeWidget::addAnchors(){ |
441 void ChromeWidget::addAnchors(){ |
406 if(!m_bottomBar){ |
442 if (!m_bottomBar){ |
407 m_bottomBar = new QGraphicsWidget(this); |
443 m_bottomBar = new QGraphicsWidget(this); |
408 m_bottomBar->setPreferredHeight(0); |
444 m_bottomBar->setPreferredHeight(0); |
409 m_bottomBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); |
445 m_bottomBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); |
410 m_layout->addAnchor(m_bottomBar, Qt::AnchorBottom, m_layout, Qt::AnchorBottom); |
446 m_layout->addAnchor(m_bottomBar, Qt::AnchorBottom, m_layout, Qt::AnchorBottom); |
411 m_layout->addAnchors(m_bottomBar, m_layout, Qt::Horizontal); |
447 m_layout->addAnchors(m_bottomBar, m_layout, Qt::Horizontal); |
412 } |
448 } |
413 if(!m_topBar){ |
449 if (!m_topBar){ |
414 m_topBar = new QGraphicsWidget(this); |
450 m_topBar = new QGraphicsWidget(this); |
415 m_topBar->setPreferredHeight(0); |
451 m_topBar->setPreferredHeight(0); |
416 m_topBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); |
452 m_topBar->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed)); |
417 m_layout->addAnchor(m_topBar, Qt::AnchorTop, m_layout, Qt::AnchorTop); |
453 m_layout->addAnchor(m_topBar, Qt::AnchorTop, m_layout, Qt::AnchorTop); |
418 m_layout->addAnchors(m_topBar, m_layout, Qt::Horizontal); |
454 m_layout->addAnchors(m_topBar, m_layout, Qt::Horizontal); |
419 } |
455 } |
420 if(!m_leftBar){ |
456 if (!m_leftBar){ |
421 m_leftBar = new QGraphicsWidget(this); |
457 m_leftBar = new QGraphicsWidget(this); |
422 m_leftBar->setPreferredWidth(0); |
458 m_leftBar->setPreferredWidth(0); |
423 m_leftBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); |
459 m_leftBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); |
424 m_layout->addAnchor(m_leftBar, Qt::AnchorLeft, m_layout, Qt::AnchorLeft); |
460 m_layout->addAnchor(m_leftBar, Qt::AnchorLeft, m_layout, Qt::AnchorLeft); |
425 m_layout->addAnchors(m_leftBar, m_layout, Qt::Vertical); |
461 m_layout->addAnchors(m_leftBar, m_layout, Qt::Vertical); |
426 } |
462 } |
427 if(!m_rightBar){ |
463 if (!m_rightBar){ |
428 m_rightBar = new QGraphicsWidget(this); |
464 m_rightBar = new QGraphicsWidget(this); |
429 m_rightBar->setPreferredWidth(0); |
465 m_rightBar->setPreferredWidth(0); |
430 m_rightBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); |
466 m_rightBar->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); |
431 m_layout->addAnchor(m_rightBar, Qt::AnchorRight, m_layout, Qt::AnchorRight); |
467 m_layout->addAnchor(m_rightBar, Qt::AnchorRight, m_layout, Qt::AnchorRight); |
432 m_layout->addAnchors(m_rightBar, m_layout, Qt::Vertical); |
468 m_layout->addAnchors(m_rightBar, m_layout, Qt::Vertical); |
433 } |
469 } |
434 } |
470 } |
435 |
471 |
436 //Check to see if snippet has an anchor and lay it out accordingly. |
472 //Check to see if snippet has an anchor and lay it out accordingly. |
437 //Otherwise snippets determine their own positions from html |
473 //Otherwise snippets determine their own positions from html |
438 |
474 |
439 void ChromeWidget::anchorSnippet(ChromeSnippet * snippet) |
475 void ChromeWidget::anchorSnippet(ChromeSnippet * snippet) |
440 { |
476 { |
441 if(snippet->anchor() == anchorBottom){ |
477 if (snippet->anchor() == anchorBottom){ |
442 if(snippet->hidesContent()){ |
478 if (snippet->hidesContent()){ |
443 m_layout->addAnchor(snippet->widget(), Qt::AnchorBottom, m_bottomBar, Qt::AnchorTop); |
479 m_layout->addAnchor(snippet->widget(), Qt::AnchorBottom, m_bottomBar, Qt::AnchorTop); |
444 m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_bottomBar, Qt::AnchorHorizontalCenter); |
480 m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_bottomBar, Qt::AnchorHorizontalCenter); |
445 } else { |
481 } else { |
446 snippet->widget()->setParentItem(m_bottomBar); |
482 snippet->widget()->setParentItem(m_bottomBar); |
447 snippet->widget()->setY(-snippet->anchorOffset()); |
483 snippet->widget()->setY(-snippet->anchorOffset()); |
448 } |
484 } |
449 } |
485 } |
450 else if (snippet->anchor() == anchorTop){ |
486 else if (snippet->anchor() == anchorTop){ |
451 if(snippet->hidesContent()){ |
487 if (snippet->hidesContent()){ |
452 m_layout->addAnchor(snippet->widget(),Qt::AnchorTop, m_topBar, Qt::AnchorBottom); |
488 m_layout->addAnchor(snippet->widget(),Qt::AnchorTop, m_topBar, Qt::AnchorBottom); |
453 m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_topBar, Qt::AnchorHorizontalCenter); |
489 m_layout->addAnchor(snippet->widget(), Qt::AnchorHorizontalCenter, m_topBar, Qt::AnchorHorizontalCenter); |
454 } |
490 } |
455 else { |
491 else { |
456 snippet->widget()->setParentItem(m_topBar); |
492 snippet->widget()->setParentItem(m_topBar); |
457 snippet->widget()->setY(snippet->anchorOffset()); |
493 snippet->widget()->setY(snippet->anchorOffset()); |
458 } |
494 } |
459 } |
495 } |
460 else if (snippet->anchor() == anchorLeft){ |
496 else if (snippet->anchor() == anchorLeft){ |
461 if(snippet->hidesContent()) |
497 if (snippet->hidesContent()) |
462 m_layout->addAnchor(snippet->widget(),Qt::AnchorLeft, m_leftBar, Qt::AnchorRight); |
498 m_layout->addAnchor(snippet->widget(),Qt::AnchorLeft, m_leftBar, Qt::AnchorRight); |
463 else { |
499 else { |
464 snippet->widget()->setParentItem(m_leftBar); |
500 snippet->widget()->setParentItem(m_leftBar); |
465 snippet->widget()->setX(snippet->anchorOffset()); |
501 snippet->widget()->setX(snippet->anchorOffset()); |
466 } |
502 } |
467 } |
503 } |
468 else if (snippet->anchor() == anchorRight){ |
504 else if (snippet->anchor() == anchorRight){ |
469 if(snippet->hidesContent()) |
505 if (snippet->hidesContent()) |
470 m_layout->addAnchor(snippet->widget(),Qt::AnchorRight, m_rightBar, Qt::AnchorLeft); |
506 m_layout->addAnchor(snippet->widget(),Qt::AnchorRight, m_rightBar, Qt::AnchorLeft); |
471 else { |
507 else { |
472 snippet->widget()->setParentItem(m_rightBar); |
508 snippet->widget()->setParentItem(m_rightBar); |
473 snippet->widget()->setX(-snippet->anchorOffset()); |
509 snippet->widget()->setX(-snippet->anchorOffset()); |
474 } |
510 } |
475 } |
511 } |
476 else if (snippet->anchor() == anchorCenter) { |
512 else if (snippet->anchor() == anchorCenter) { |
477 snippet->widget()->setParentItem(m_viewPort); |
513 snippet->widget()->setParentItem(m_viewPort); |
478 snippet->widget()->setZValue(0.0); |
514 snippet->widget()->setZValue(0.0); |
494 |
530 |
495 void ChromeWidget:: addSnippet(ChromeSnippet * snippet, const QString & docElementId ) |
531 void ChromeWidget:: addSnippet(ChromeSnippet * snippet, const QString & docElementId ) |
496 { |
532 { |
497 m_snippets->addSnippet(snippet, docElementId); |
533 m_snippets->addSnippet(snippet, docElementId); |
498 snippet->widget()->setParentItem(this); |
534 snippet->widget()->setParentItem(this); |
499 |
535 |
500 if(!snippet->parentId().isNull()){ |
536 if (!snippet->parentId().isNull()){ |
501 ChromeSnippet * container = getSnippet(snippet->parentId()); |
537 ChromeSnippet * container = getSnippet(snippet->parentId()); |
502 if(container) |
538 if (container) |
503 container->addChild(snippet); |
539 container->addChild(snippet); |
504 } |
540 } |
505 |
541 |
506 anchorSnippet(snippet); |
542 anchorSnippet(snippet); |
507 } |
543 } |
508 |
544 |
509 //NB: This really shouldn't be necessary: anchor bars should be implemented as an expanding |
545 //NB: This really shouldn't be necessary: anchor bars should be implemented as an expanding |
510 //widget class !!!!!! |
546 //widget class !!!!!! |
511 |
547 |
512 void ChromeWidget::adjustAnchorOffset(ChromeSnippet * snippet, qreal delta) |
548 void ChromeWidget::adjustAnchorOffset(ChromeSnippet * snippet, qreal delta) |
513 { |
549 { |
514 if(snippet->anchor() == anchorBottom) |
550 if (snippet->anchor() == anchorBottom) |
515 m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() + delta); |
551 m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() + delta); |
516 else if(snippet->anchor() == anchorTop) |
552 else if (snippet->anchor() == anchorTop) |
517 m_topBar->setPreferredHeight(m_topBar->preferredHeight() + delta); |
553 m_topBar->setPreferredHeight(m_topBar->preferredHeight() + delta); |
518 else if(snippet->anchor() == anchorLeft){ |
554 else if (snippet->anchor() == anchorLeft){ |
519 m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() + delta); |
555 m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() + delta); |
520 } |
556 } |
521 else if(snippet->anchor() == anchorRight){ |
557 else if (snippet->anchor() == anchorRight){ |
522 m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() + delta); |
558 m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() + delta); |
523 } |
559 } |
524 } |
560 } |
525 |
561 |
526 // Call after a snippet changes to visible state |
562 // Call after a snippet changes to visible state |
551 // At a minimum should assert that the anchor "bars" |
599 // At a minimum should assert that the anchor "bars" |
552 // are not null.) |
600 // are not null.) |
553 |
601 |
554 void ChromeWidget::snippetHiding(ChromeSnippet * snippet) |
602 void ChromeWidget::snippetHiding(ChromeSnippet * snippet) |
555 { |
603 { |
556 if(snippet->hidesContent()) |
604 if (snippet->hidesContent()) |
557 return; |
605 return; |
558 if(snippet->anchor() == anchorBottom) |
606 if (snippet->anchor() == anchorBottom) |
559 m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() - snippet->widget()->preferredHeight()); |
607 m_bottomBar->setPreferredHeight(m_bottomBar->preferredHeight() - snippet->widget()->preferredHeight()); |
560 else if(snippet->anchor() == anchorTop) |
608 else if (snippet->anchor() == anchorTop) |
561 m_topBar->setPreferredHeight(m_topBar->preferredHeight() - snippet->widget()->preferredHeight()); |
609 m_topBar->setPreferredHeight(m_topBar->preferredHeight() - snippet->widget()->preferredHeight()); |
562 else if(snippet->anchor() == anchorLeft){ |
610 else if (snippet->anchor() == anchorLeft){ |
563 m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() - snippet->widget()->preferredWidth()); |
611 m_leftBar->setPreferredWidth(m_leftBar->preferredWidth() - snippet->widget()->preferredWidth()); |
564 } |
612 } |
565 else if(snippet->anchor() == anchorRight){ |
613 else if (snippet->anchor() == anchorRight){ |
566 m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() - snippet->widget()->preferredWidth()); |
614 m_rightBar->setPreferredWidth(m_rightBar->preferredWidth() - snippet->widget()->preferredWidth()); |
567 } |
615 } |
568 } |
616 } |
569 |
617 |
570 ChromeSnippet *ChromeWidget::getSnippet(const QString & docElementId, QGraphicsItem * parent) { |
618 ChromeSnippet *ChromeWidget::getSnippet(const QString & docElementId, QGraphicsItem * parent) { |
571 |
|
572 ChromeSnippet *result = m_snippets->getSnippet(docElementId); |
619 ChromeSnippet *result = m_snippets->getSnippet(docElementId); |
573 if(!result){ |
620 if (!result){ |
574 result = m_dom->getSnippet(docElementId, parent); |
621 result = m_dom->getSnippet(docElementId, parent); |
575 if(result) { |
622 if (result) { |
576 result->setParent(m_snippets); // Exports to "Snippets" JS object |
623 result->setParent(m_snippets); // Exports to "Snippets" JS object |
577 addSnippet(result, docElementId); |
624 addSnippet(result, docElementId); |
578 } |
625 } |
579 else{ |
626 else{ |
580 qDebug() << "Snippet not found: " << docElementId; |
627 qDebug() << "Snippet not found: " << docElementId; |
581 return 0; |
628 return 0; |
582 } |
629 } |
583 }else{ |
630 }else{ |
584 //qDebug() << "Found existing snippet: " << docElementId; |
631 //qDebug() << "Found existing snippet: " << docElementId; |
585 } |
632 } |
586 |
633 |
587 return result; |
634 return result; |
588 } |
635 } |
589 |
636 |
590 QRect ChromeWidget::getSnippetRect(const QString &docElementId) |
637 QRect ChromeWidget::getSnippetRect(const QString &docElementId) |
591 { |
638 { |
592 return m_dom->getElementRect(docElementId); |
639 return m_dom->getElementRect(docElementId); |
593 } |
640 } |
594 |
641 |
595 void ChromeWidget::addJSObjectToWindow(QObject *object) |
642 void ChromeWidget::addJSObjectToWindow(QObject *object) |
596 { |
643 { |
597 m_page->mainFrame()->addToJavaScriptWindowObject(object->objectName(), object); |
644 m_page->mainFrame()->addToJavaScriptWindowObject(object->objectName(), object); |
598 } |
645 } |
599 |
646 |
600 void ChromeWidget::addJSObjectToPage(QObject *object, QWebPage *page) |
647 void ChromeWidget::addJSObjectToPage(QObject *object, QWebPage *page) |