|
1 /* |
|
2 * Copyright (c) 2009 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 #include <QGraphicsLinearLayout> |
|
19 #include <QParallelAnimationGroup> |
|
20 #include <QPropertyAnimation> |
|
21 #include <QGraphicsDropShadowEffect> |
|
22 #include <QGraphicsSceneResizeEvent> |
|
23 #include <QGesture> |
|
24 #include <QGraphicsScene> |
|
25 |
|
26 #include "hswidgethostvisual.h" |
|
27 #include "hswidgethost.h" |
|
28 #include "hsscene.h" |
|
29 #include "hsconfiguration.h" |
|
30 #include "hswidgettoucharea.h" |
|
31 |
|
32 |
|
33 /*! |
|
34 \class HsWidgetHostVisual |
|
35 \ingroup group_hsdomainmodel |
|
36 \brief Each widget is controlled by the home screen framework through a widget host. |
|
37 */ |
|
38 |
|
39 /*! |
|
40 Constructs a new widget host with given \a databaseId and |
|
41 \a parent item. |
|
42 */ |
|
43 HsWidgetHostVisual::HsWidgetHostVisual(QGraphicsItem *parent) |
|
44 : HbWidget(parent),mWidget(0) |
|
45 |
|
46 { |
|
47 setFlag(QGraphicsItem::ItemClipsChildrenToShape); |
|
48 setFlag(QGraphicsItem::ItemHasNoContents); |
|
49 |
|
50 grabGesture(Qt::TapGesture); |
|
51 grabGesture(Qt::TapAndHoldGesture); |
|
52 grabGesture(Qt::PanGesture); |
|
53 grabGesture(Qt::PinchGesture); |
|
54 grabGesture(Qt::SwipeGesture); |
|
55 grabGesture(Qt::CustomGesture); |
|
56 |
|
57 setupTouchArea(); |
|
58 setupEffects(); |
|
59 |
|
60 setMinimumSize(HSCONFIGURATION_GET(minimumWidgetSizeInPixels)); |
|
61 setMaximumSize(HSCONFIGURATION_GET(maximumWidgetSizeInPixels)); |
|
62 |
|
63 } |
|
64 |
|
65 /*! |
|
66 Destructor. |
|
67 */ |
|
68 HsWidgetHostVisual::~HsWidgetHostVisual() |
|
69 { |
|
70 } |
|
71 |
|
72 |
|
73 /*! |
|
74 Reimplemented from QGraphicsItem. Returns the shape of the |
|
75 this widget host. The shape is computed based on the contained |
|
76 widget. |
|
77 */ |
|
78 QPainterPath HsWidgetHostVisual::shape() const |
|
79 { |
|
80 QPainterPath path; |
|
81 |
|
82 if (mWidget) { |
|
83 QRectF currRect = rect(); |
|
84 path = mWidget->shape(); |
|
85 |
|
86 QRectF pathRect(path.boundingRect()); |
|
87 |
|
88 if (pathRect.width() > currRect.width() |
|
89 || pathRect.height() > currRect.height()) { |
|
90 QPainterPath newPath(currRect.topLeft()); |
|
91 newPath.addRect(currRect); |
|
92 path = path.intersected(newPath); |
|
93 } |
|
94 } |
|
95 return path; |
|
96 } |
|
97 void HsWidgetHostVisual::setWidget(QObject *widget) |
|
98 { |
|
99 mWidget = qobject_cast<QGraphicsWidget *>(widget); |
|
100 if (mWidget) { |
|
101 mWidget->installEventFilter(this); |
|
102 mWidget->setParentItem(this); |
|
103 setNewSize(mWidget->size()); |
|
104 } |
|
105 } |
|
106 |
|
107 void HsWidgetHostVisual::setVisualModel(HsWidgetHost *model) |
|
108 { |
|
109 mVisualModel = model; |
|
110 } |
|
111 HsWidgetHost *HsWidgetHostVisual::visualModel() const |
|
112 { |
|
113 return mVisualModel; |
|
114 } |
|
115 /*! |
|
116 Starts the drag effect. |
|
117 */ |
|
118 void HsWidgetHostVisual::startDragEffect() |
|
119 { |
|
120 } |
|
121 |
|
122 /*! |
|
123 Starts the drop effect. |
|
124 */ |
|
125 void HsWidgetHostVisual::startDropEffect() |
|
126 { |
|
127 } |
|
128 /*! |
|
129 \fn HsWidgetHost::resized() |
|
130 Notifies the home screen framework that this widget |
|
131 host has resized itself. |
|
132 */ |
|
133 |
|
134 /*! |
|
135 Reimplemented from QObject for monitoring changes in |
|
136 contained widget's size. |
|
137 */ |
|
138 bool HsWidgetHostVisual::eventFilter(QObject *watched, QEvent *event) |
|
139 { |
|
140 return HbWidget::eventFilter(watched, event); |
|
141 } |
|
142 |
|
143 /*! |
|
144 Reimplemented from HbWidget for pan gesture handling. |
|
145 */ |
|
146 void HsWidgetHostVisual::gestureEvent(QGestureEvent *event) |
|
147 { |
|
148 } |
|
149 |
|
150 /*! |
|
151 \fn HsWidgetHostVisual::mousePressEvent(QGraphicsSceneMouseEvent *) |
|
152 Reimplemented from QGraphicsItem for eating all mouse presses. |
|
153 */ |
|
154 |
|
155 /*! |
|
156 Configures the touch are for this widget host. |
|
157 */ |
|
158 void HsWidgetHostVisual::setupTouchArea() |
|
159 { |
|
160 } |
|
161 |
|
162 /*! |
|
163 Configures the effects for this widget host. |
|
164 */ |
|
165 void HsWidgetHostVisual::setupEffects() |
|
166 { |
|
167 } |
|
168 |
|
169 |
|
170 /*! |
|
171 Resizes this widget host to the given \a size. |
|
172 */ |
|
173 void HsWidgetHostVisual::setNewSize(const QSizeF &size) |
|
174 { |
|
175 } |
|
176 |