20 #include <HbStyleLoader> |
20 #include <HbStyleLoader> |
21 #include <HbFrameItem> |
21 #include <HbFrameItem> |
22 #include <HbFrameDrawer> |
22 #include <HbFrameDrawer> |
23 #include <HbIconItem> |
23 #include <HbIconItem> |
24 #include <HbTextItem> |
24 #include <HbTextItem> |
25 #include <HbTouchArea> |
|
26 #include <HbInstantFeedback> |
25 #include <HbInstantFeedback> |
|
26 #include <HbTapGesture> |
27 |
27 |
28 #include "hsshortcutwidget.h" |
28 #include "hsshortcutwidget.h" |
29 #include "hsshortcutservice.h" |
29 #include "hsshortcutservice.h" |
30 #include "hsapp_defs.h" |
30 #include "hsapp_defs.h" |
31 #include "caservice.h" |
31 #include "caservice.h" |
45 /*! |
45 /*! |
46 Constructor. |
46 Constructor. |
47 */ |
47 */ |
48 HsShortcutWidget::HsShortcutWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
48 HsShortcutWidget::HsShortcutWidget(QGraphicsItem *parent, Qt::WindowFlags flags) |
49 : HbWidget(parent, flags), |
49 : HbWidget(parent, flags), |
50 mBackground(0), mIcon(0), mText(0), mTouchArea(0), |
50 mBackground(0), mIcon(0), mText(0), |
51 mCaEntryId(-1), mCaEntryRole(ItemEntryRole) |
51 mCaEntryId(-1), mCaEntryRole(ItemEntryRole) |
52 { |
52 { |
|
53 grabGesture(Qt::TapGesture); |
|
54 |
53 HbStyleLoader::registerFilePath(":/hsshortcutwidget.widgetml"); |
55 HbStyleLoader::registerFilePath(":/hsshortcutwidget.widgetml"); |
54 HbStyleLoader::registerFilePath(":/hsshortcutwidget.css"); |
56 HbStyleLoader::registerFilePath(":/hsshortcutwidget.css"); |
55 |
57 |
56 createPrimitives(); |
58 createPrimitives(); |
57 } |
59 } |
115 void HsShortcutWidget::setText(const QString& textItem) |
117 void HsShortcutWidget::setText(const QString& textItem) |
116 { |
118 { |
117 if ( mText ) { |
119 if ( mText ) { |
118 mText->setText(textItem); |
120 mText->setText(textItem); |
119 } |
121 } |
120 } |
|
121 |
|
122 /*! |
|
123 Filters touch area events. |
|
124 */ |
|
125 bool HsShortcutWidget::eventFilter(QObject *watched, QEvent *event) |
|
126 { |
|
127 Q_UNUSED(watched) |
|
128 |
|
129 switch (event->type()) { |
|
130 case QEvent::GraphicsSceneMousePress: |
|
131 handleMousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
132 return true; |
|
133 case QEvent::GraphicsSceneMouseMove: |
|
134 handleMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
135 return true; |
|
136 case QEvent::GraphicsSceneMouseRelease: |
|
137 handleMouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event)); |
|
138 return true; |
|
139 case QEvent::UngrabMouse: |
|
140 setBackgroundToNormal(); |
|
141 return true; |
|
142 default: |
|
143 break; |
|
144 } |
|
145 |
|
146 return false; |
|
147 } |
122 } |
148 |
123 |
149 /*! |
124 /*! |
150 Initializes this widget. |
125 Initializes this widget. |
151 */ |
126 */ |
202 void HsShortcutWidget::onHide() |
177 void HsShortcutWidget::onHide() |
203 { |
178 { |
204 } |
179 } |
205 |
180 |
206 /*! |
181 /*! |
207 \internal |
182 \internal |
208 */ |
183 */ |
209 void HsShortcutWidget::handleMousePressEvent(QGraphicsSceneMouseEvent *event) |
184 #ifdef COVERAGE_MEASUREMENT |
210 { |
185 #pragma CTC SKIP |
211 Q_UNUSED(event) |
186 #endif //COVERAGE_MEASUREMENT |
212 setBackgroundToPressed(); |
187 void HsShortcutWidget::gestureEvent(QGestureEvent *event) |
213 } |
188 { |
214 |
189 HbTapGesture *gesture = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture)); |
215 /*! |
190 if (gesture) { |
216 \internal |
191 switch (gesture->state()) { |
217 */ |
192 case Qt::GestureStarted: |
218 void HsShortcutWidget::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) |
193 setBackgroundToPressed(); |
219 { |
194 break; |
220 if (contains(event->pos())) { |
195 case Qt::GestureCanceled: |
221 setBackgroundToPressed(); |
196 setBackgroundToNormal(); |
222 } else { |
197 break; |
223 setBackgroundToNormal(); |
198 case Qt::GestureFinished: |
224 } |
199 setBackgroundToNormal(); |
225 } |
200 if (gesture->tapStyleHint() == HbTapGesture::Tap) { |
226 |
201 launch(); |
227 /*! |
202 } |
228 \internal |
203 break; |
229 */ |
204 default: |
230 void HsShortcutWidget::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
205 break; |
231 { |
206 } |
232 setBackgroundToNormal(); |
207 } |
233 |
208 } |
234 if (!contains(event->pos())) { |
209 #ifdef COVERAGE_MEASUREMENT |
235 return; |
210 #pragma CTC ENDSKIP |
236 } |
211 #endif //COVERAGE_MEASUREMENT |
237 |
212 |
|
213 /*! |
|
214 \internal |
|
215 */ |
|
216 void HsShortcutWidget::launch() |
|
217 { |
238 HbInstantFeedback::play(HSCONFIGURATION_GET(shortcutWidgetTapFeedbackEffect)); |
218 HbInstantFeedback::play(HSCONFIGURATION_GET(shortcutWidgetTapFeedbackEffect)); |
239 |
219 |
240 if (mCaEntryRole == ItemEntryRole) { |
220 if (mCaEntryRole == ItemEntryRole) { |
241 CaService::instance()->executeCommand(mCaEntryId); |
221 CaService::instance()->executeCommand(mCaEntryId); |
242 } else { |
222 } else { |
265 |
245 |
266 // Text |
246 // Text |
267 if (HSCONFIGURATION_GET(isShortcutLabelVisible) && !mText ) { |
247 if (HSCONFIGURATION_GET(isShortcutLabelVisible) && !mText ) { |
268 mText = new HbTextItem(this); |
248 mText = new HbTextItem(this); |
269 HbStyle::setItemName(mText, QLatin1String("text")); |
249 HbStyle::setItemName(mText, QLatin1String("text")); |
270 } |
|
271 // Touch Area |
|
272 if (!mTouchArea) { |
|
273 mTouchArea = new HbTouchArea(this); |
|
274 mTouchArea->installEventFilter(this); |
|
275 HbStyle::setItemName(mTouchArea, QLatin1String("toucharea")); |
|
276 } |
250 } |
277 } |
251 } |
278 |
252 |
279 /*! |
253 /*! |
280 \internal |
254 \internal |