29 #include <hbstyleloader.h> |
29 #include <hbstyleloader.h> |
30 #include <QGraphicsSceneMouseEvent> |
30 #include <QGraphicsSceneMouseEvent> |
31 #include <hbinstantfeedback.h> |
31 #include <hbinstantfeedback.h> |
32 #include <hbcolorscheme.h> |
32 #include <hbcolorscheme.h> |
33 #include <QGestureEvent> |
33 #include <QGestureEvent> |
34 #include <QTapGesture> |
34 #include <hbtapgesture.h> |
35 #include <hbtoucharea.h> |
|
36 |
35 |
37 |
36 |
38 CntContactCardDetailItem::CntContactCardDetailItem(int index, QGraphicsItem *parent, bool isFocusable) : |
37 CntContactCardDetailItem::CntContactCardDetailItem(int index, QGraphicsItem *parent, bool isFocusable) : |
39 HbWidget(parent), |
38 HbWidget(parent), |
40 mIcon(NULL), |
39 mIcon(NULL), |
160 createPrimitives(); |
160 createPrimitives(); |
161 } |
161 } |
162 |
162 |
163 void CntContactCardDetailItem::initGesture() |
163 void CntContactCardDetailItem::initGesture() |
164 { |
164 { |
165 grabGesture(Qt::TapAndHoldGesture, Qt::ReceivePartialGestures); |
165 grabGesture(Qt::TapGesture); |
166 grabGesture(Qt::TapGesture, Qt::ReceivePartialGestures); |
|
167 } |
166 } |
168 |
167 |
169 void CntContactCardDetailItem::gestureEvent(QGestureEvent* event) |
168 void CntContactCardDetailItem::gestureEvent(QGestureEvent* event) |
170 { |
169 { |
171 qDebug() << "CntContactCardDetailItem::gestureEvent - IN"; |
170 qDebug() << "CntContactCardDetailItem::gestureEvent - IN"; |
172 event->accept( Qt::TapAndHoldGesture ); |
171 if (HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) |
173 |
172 { |
174 if (QGesture *tap = event->gesture(Qt::TapGesture)) |
173 switch(tap->state()) |
175 { |
174 { |
176 tapTriggered(static_cast<QTapGesture *>(tap)); |
175 case Qt::GestureStarted: // |
177 event->accept( tap ); |
176 if (mIsFocusable) |
178 } |
177 { |
179 |
178 HbInstantFeedback::play(HbFeedback::Basic); |
180 if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture)) |
179 } |
181 { |
180 mHasFocus = true; |
182 tapAndHoldTriggered(static_cast<QTapAndHoldGesture *>(tapAndHold)); |
181 updatePrimitives(); |
183 event->accept( tapAndHold ); |
182 break; |
|
183 case Qt::GestureCanceled: // Reset state |
|
184 mHasFocus = false; |
|
185 updatePrimitives(); |
|
186 break; |
|
187 case Qt::GestureUpdated: |
|
188 if(tap->tapStyleHint() == HbTapGesture::TapAndHold) |
|
189 { |
|
190 emit onLongPress(event->mapToGraphicsScene(tap->position())); |
|
191 } |
|
192 break; |
|
193 case Qt::GestureFinished: // emit clicked |
|
194 mHasFocus = false; |
|
195 updatePrimitives(); |
|
196 if (tap->tapStyleHint() == HbTapGesture::Tap) |
|
197 { |
|
198 emit clicked(); |
|
199 } |
|
200 break; |
|
201 default: |
|
202 break; |
|
203 } |
|
204 event->accept(); |
|
205 } |
|
206 else |
|
207 { |
|
208 event->ignore(); |
184 } |
209 } |
185 qDebug() << "CntContactCardDetailItem::gestureEvent - OUT"; |
210 qDebug() << "CntContactCardDetailItem::gestureEvent - OUT"; |
186 } |
211 } |
187 |
|
188 void CntContactCardDetailItem::tapTriggered(QTapGesture *gesture) |
|
189 { |
|
190 qDebug() << "CntContactdDetailItem::tagTriggered - IN"; |
|
191 |
|
192 Qt::GestureState state = gesture->state(); |
|
193 qDebug() << "CntContactdDetailItem::tagTriggered, state: " << state; |
|
194 switch ( state ) |
|
195 { |
|
196 case Qt::GestureStarted: |
|
197 { |
|
198 if (mIsFocusable) |
|
199 { |
|
200 HbInstantFeedback::play(HbFeedback::Basic); |
|
201 } |
|
202 mHasFocus = true; |
|
203 updatePrimitives(); |
|
204 break; |
|
205 } |
|
206 case Qt::GestureFinished: |
|
207 case Qt::GestureCanceled: |
|
208 { |
|
209 mHasFocus = false; |
|
210 updatePrimitives(); |
|
211 emit clicked(); // also in GestureCancelled? |
|
212 break; |
|
213 } |
|
214 default: |
|
215 { |
|
216 break; |
|
217 } |
|
218 } |
|
219 qDebug() << "CntContactdDetailItem::tagTriggered - OUT"; |
|
220 } |
|
221 |
|
222 void CntContactCardDetailItem::tapAndHoldTriggered(QTapAndHoldGesture *gesture) |
|
223 { |
|
224 if (gesture->state() == Qt::GestureFinished) |
|
225 { |
|
226 onLongPress(gesture->position()); |
|
227 } |
|
228 } |
|
229 |
|
230 |
212 |
231 void CntContactCardDetailItem::onLongPress(const QPointF &point) |
213 void CntContactCardDetailItem::onLongPress(const QPointF &point) |
232 { |
214 { |
233 mHasFocus = false; |
215 mHasFocus = false; |
234 updatePrimitives(); |
216 updatePrimitives(); |
235 emit longPressed(point); |
217 emit longPressed(point); |
236 } |
218 } |
237 |
219 |
238 void CntContactCardDetailItem::updatePrimitives() |
220 void CntContactCardDetailItem::updatePrimitives() |
239 { |
221 { |
|
222 if (mHasFocus && mIsFocusable) |
|
223 { |
|
224 mFocusItem->setVisible(true); |
|
225 setProperty("state", "pressed"); |
|
226 HbEffect::start(mFocusItem, QString("frameitem"), QString("pressed")); |
|
227 } |
|
228 else |
|
229 { |
|
230 HbEffect::start(mFocusItem, QString("frameitem"), QString("released")); |
|
231 mFocusItem->setVisible(false); |
|
232 setProperty("state", "normal"); |
|
233 } |
240 HbWidget::updatePrimitives(); |
234 HbWidget::updatePrimitives(); |
241 if (mHasFocus && mIsFocusable) |
235 } |
242 { |
|
243 mFocusItem->setVisible(true); |
|
244 HbEffect::start(mFocusItem, QString("frameitem"), QString("pressed")); |
|
245 } |
|
246 else |
|
247 { |
|
248 HbEffect::start(mFocusItem, QString("frameitem"), QString("released")); |
|
249 } |
|
250 } |
|
251 |
|
252 /* |
|
253 void CntContactCardDetailItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
254 { |
|
255 if (mIsFocusable) |
|
256 { |
|
257 HbInstantFeedback::play(HbFeedback::Basic); |
|
258 } |
|
259 event->accept(); |
|
260 mHasFocus = true; |
|
261 updatePrimitives(); |
|
262 } |
|
263 */ |
|
264 /* |
|
265 void CntContactCardDetailItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
266 { |
|
267 if (!rect().contains(event->pos()) && mHasFocus) |
|
268 { |
|
269 mHasFocus = false; |
|
270 updatePrimitives(); |
|
271 } |
|
272 event->accept(); |
|
273 } |
|
274 |
|
275 |
|
276 void CntContactCardDetailItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
277 { |
|
278 bool hadFocus = mHasFocus; |
|
279 mHasFocus = false; |
|
280 if (rect().contains(event->pos()) && hadFocus) |
|
281 { |
|
282 updatePrimitives(); |
|
283 emit clicked(); |
|
284 } |
|
285 event->accept(); |
|
286 } |
|
287 */ |
|
288 |
236 |
289 void CntContactCardDetailItem::setDetails(CntContactCardDataItem* aDataItem) |
237 void CntContactCardDetailItem::setDetails(CntContactCardDataItem* aDataItem) |
290 { |
238 { |
291 mValueTextElideMode = aDataItem->elideMode(); |
239 mValueTextElideMode = aDataItem->elideMode(); |
292 |
240 |