|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
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 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "WebChromeContainerSnippet.h" |
|
20 #include "WebChromeItem.h" |
|
21 #include "ChromeWidget.h" |
|
22 #include "ChromeRenderer.h" |
|
23 #include "ChromeSnippet.h" |
|
24 |
|
25 #include <QDebug> |
|
26 |
|
27 namespace GVA { |
|
28 |
|
29 WebChromeContainerSnippet::WebChromeContainerSnippet(const QString & elementId, ChromeWidget * chrome, const QRectF& ownerArea, const QWebElement & element, QGraphicsWidget* gwidget) |
|
30 : ChromeSnippet(elementId, chrome, gwidget, element), |
|
31 m_ownerArea(ownerArea), |
|
32 m_layoutHeight(0) |
|
33 { |
|
34 QGraphicsWidget * item = static_cast<QGraphicsWidget*> (widget()); |
|
35 //NB: maybe size should be fixed only in one direction? |
|
36 item->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
37 //NB: add a method for setting owner area |
|
38 //item->setPreferredSize(m_ownerArea.width(), m_ownerArea.height()); |
|
39 //Also resize in case item is not part of anchor layout |
|
40 //item->resize(item->preferredSize()); |
|
41 |
|
42 //NB: Linear layout efaults to horizontal: handle vertical layouts too. |
|
43 m_layout = new QGraphicsLinearLayout(); |
|
44 m_layout->setContentsMargins(0,0,0,0); |
|
45 m_layout->setSpacing(0); |
|
46 |
|
47 //Add a stretch element at the beginning. |
|
48 m_layout->addStretch(); |
|
49 item->setLayout(m_layout); |
|
50 //When chrome is resized owner areas for snippets may change |
|
51 QObject::connect(m_chrome->renderer(), SIGNAL(chromeResized()), this, SLOT(updateOwnerArea())); |
|
52 } |
|
53 |
|
54 WebChromeContainerSnippet::~WebChromeContainerSnippet() |
|
55 { |
|
56 // delete m_layout; |
|
57 } |
|
58 |
|
59 void WebChromeContainerSnippet::positionChildren() |
|
60 { |
|
61 ; //Do nothing since the layout positions children automatically. |
|
62 } |
|
63 |
|
64 void WebChromeContainerSnippet::addChild(ChromeSnippet * child) |
|
65 { |
|
66 //Prevent layout from stretching the child widgets. NB: Revisit this to make configurable from chrome? |
|
67 child->widget()->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed)); |
|
68 //child->widget()->setParentItem(this->widget()); // Shouldn't be needed, right? |
|
69 m_layout->addItem(child->widget()); |
|
70 //Add a stretch after each element so the layout looks like this: |stretch|item|stretch|item . . . . stretch|item| |
|
71 m_layout->addStretch(); |
|
72 |
|
73 // If child is not a container itself, connect to its mouseEvent |
|
74 WebChromeContainerSnippet * s = qobject_cast <WebChromeContainerSnippet * >(child); |
|
75 if (!s ) { |
|
76 //qDebug() << __PRETTY_FUNCTION__ << s << child->elementId(); |
|
77 // Connect to mouse events of snippets |
|
78 WebChromeItem * item = static_cast<WebChromeItem*> (child->widget()); |
|
79 connect(item, SIGNAL(mouseEvent(QEvent::Type)), this, SIGNAL(snippetMouseEvent(QEvent::Type))); |
|
80 } |
|
81 qreal childHeight = child->widget()->size().height(); |
|
82 if(childHeight > m_layoutHeight){ |
|
83 m_layoutHeight = childHeight; |
|
84 updateOwnerArea(); |
|
85 } |
|
86 } |
|
87 |
|
88 void WebChromeContainerSnippet:: updateOwnerArea() |
|
89 { |
|
90 QGraphicsWidget * item = static_cast<QGraphicsWidget*> (widget()); |
|
91 //Resize the item |
|
92 m_ownerArea = m_chrome->getSnippetRect(m_elementId); |
|
93 item->setPreferredSize(m_ownerArea.width(), m_layoutHeight); |
|
94 //Also resize in case item is not part of anchor layout |
|
95 item->resize(item->preferredSize()); |
|
96 } |
|
97 |
|
98 void WebChromeContainerSnippet::setLayoutHeight(int height){ |
|
99 if(m_layoutHeight != height){ |
|
100 m_layoutHeight = height; |
|
101 updateOwnerArea(); |
|
102 } |
|
103 } |
|
104 |
|
105 } // endof namespace GVA |