13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
17 |
17 |
|
18 #include <QGraphicsLayout> |
|
19 #include <QDebug> |
|
20 |
18 #include "cntcontactcarddetailitem.h" |
21 #include "cntcontactcarddetailitem.h" |
19 #include "cntcontactcarddataitem.h" |
22 #include "cntcontactcarddataitem.h" |
20 #include <hbiconitem.h> |
23 #include <hbiconitem.h> |
21 #include <hbtextitem.h> |
24 #include <hbtextitem.h> |
22 #include <hbrichtextitem.h> |
25 #include <hbrichtextitem.h> |
23 #include <hbframedrawer.h> |
26 #include <hbframedrawer.h> |
24 #include <hbframeitem.h> |
27 #include <hbframeitem.h> |
25 #include <hbeffect.h> |
28 #include <hbeffect.h> |
26 #include <hbgesturefilter.h> |
|
27 #include <hbgesture.h> |
|
28 #include <hbstyleloader.h> |
29 #include <hbstyleloader.h> |
29 #include <QGraphicsSceneMouseEvent> |
30 #include <QGraphicsSceneMouseEvent> |
30 #include <hbinstantfeedback.h> |
31 #include <hbinstantfeedback.h> |
|
32 #include <hbcolorscheme.h> |
|
33 #include <QGestureEvent> |
|
34 #include <QTapGesture> |
|
35 #include <hbtoucharea.h> |
|
36 |
31 |
37 |
32 CntContactCardDetailItem::CntContactCardDetailItem(int index, QGraphicsItem *parent, bool isFocusable) : |
38 CntContactCardDetailItem::CntContactCardDetailItem(int index, QGraphicsItem *parent, bool isFocusable) : |
33 HbWidget(parent), |
39 HbWidget(parent), |
34 mIcon(NULL), |
40 mIcon(NULL), |
|
41 mSecondaryIcon(NULL), |
35 mFirstLineText(NULL), |
42 mFirstLineText(NULL), |
36 mSecondLineText(NULL), |
43 mSecondLineText(NULL), |
37 mFrameItem(NULL), |
44 mFrameItem(NULL), |
38 mFocusItem(NULL), |
45 mFocusItem(NULL), |
39 mHasFocus(false), |
46 mHasFocus(false), |
40 mGestureFilter(NULL), |
|
41 mGestureLongpressed(NULL), |
|
42 mIndex(index), |
47 mIndex(index), |
43 mIsFocusable(isFocusable), |
48 mIsFocusable(isFocusable), |
44 mValueTextElideMode(Qt::ElideRight), |
49 mValueTextElideMode(Qt::ElideRight), |
45 mIsUnderline(false) |
50 mIsUnderline(false) |
46 { |
51 { |
62 if (!icon.isNull()) |
67 if (!icon.isNull()) |
63 { |
68 { |
64 if (!mIcon) |
69 if (!mIcon) |
65 { |
70 { |
66 mIcon = new HbIconItem(this); |
71 mIcon = new HbIconItem(this); |
67 mIcon->setIcon(icon); |
|
68 style()->setItemName(mIcon, "icon"); |
72 style()->setItemName(mIcon, "icon"); |
69 } |
73 } |
|
74 mIcon->setIcon(icon); |
70 } |
75 } |
71 else |
76 else |
72 { |
77 { |
73 if (mIcon) |
78 if (mIcon) |
74 { |
79 { |
75 delete mIcon; |
80 delete mIcon; |
76 } |
81 } |
77 mIcon = 0; |
82 mIcon = 0; |
78 } |
83 } |
79 |
84 |
|
85 if (!mSecondaryIcon) |
|
86 { |
|
87 mSecondaryIcon = new HbIconItem(this); |
|
88 mSecondaryIcon->setFlags(HbIcon::Colorized); |
|
89 style()->setItemName(mSecondaryIcon, "secondaryIcon"); |
|
90 } |
|
91 mSecondaryIcon->setIcon(secondaryIcon); |
|
92 mSecondaryIcon->setColor(HbColorScheme::color("foreground")); |
|
93 |
80 if (!text.isNull()) |
94 if (!text.isNull()) |
81 { |
95 { |
82 mFirstLineText = new HbTextItem(this); |
96 if (!mFirstLineText) |
|
97 { |
|
98 mFirstLineText = new HbTextItem(this); |
|
99 mFirstLineText->setTextWrapping(Hb::TextWordWrap); |
|
100 style()->setItemName(mFirstLineText, "text"); |
|
101 } |
83 mFirstLineText->setText(text); |
102 mFirstLineText->setText(text); |
84 mFirstLineText->setTextWrapping(Hb::TextWordWrap); |
|
85 style()->setItemName(mFirstLineText, "text"); |
|
86 } |
103 } |
87 else |
104 else |
88 { |
105 { |
89 if (mFirstLineText) |
106 if (mFirstLineText) |
90 { |
107 { |
91 delete mFirstLineText; |
108 delete mFirstLineText; |
92 } |
109 } |
93 mFirstLineText = 0; |
110 mFirstLineText = 0; |
94 } |
111 } |
95 |
112 |
96 if (!valueText.isNull()) |
113 if (!valueText.isNull()) |
97 { |
114 { |
98 if (!mSecondLineText) |
115 if (!mSecondLineText) |
99 { |
116 { |
100 mSecondLineText = new HbTextItem(this); |
117 mSecondLineText = new HbTextItem(this); |
101 mSecondLineText->setText(valueText); |
|
102 mSecondLineText->setElideMode(mValueTextElideMode); |
118 mSecondLineText->setElideMode(mValueTextElideMode); |
103 style()->setItemName(mSecondLineText, "valueText"); |
119 style()->setItemName(mSecondLineText, "valueText"); |
104 } |
120 } |
|
121 mSecondLineText->setText(valueText); |
105 } |
122 } |
106 else |
123 else |
107 { |
124 { |
108 if (mSecondLineText) |
125 if (mSecondLineText) |
109 { |
126 { |
128 mFocusItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
145 mFocusItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
129 mFocusItem->setZValue(-1); |
146 mFocusItem->setZValue(-1); |
130 mFocusItem->setVisible(false); |
147 mFocusItem->setVisible(false); |
131 style()->setItemName(mFocusItem, "highlight"); |
148 style()->setItemName(mFocusItem, "highlight"); |
132 } |
149 } |
|
150 |
|
151 updatePrimitives(); |
|
152 updateGeometry(); |
|
153 repolish(); |
133 } |
154 } |
134 |
155 |
135 void CntContactCardDetailItem::recreatePrimitives() |
156 void CntContactCardDetailItem::recreatePrimitives() |
136 { |
157 { |
137 HbWidget::recreatePrimitives(); |
158 HbWidget::recreatePrimitives(); |
138 |
159 |
139 delete mIcon; |
|
140 mIcon = 0; |
|
141 |
|
142 delete mFirstLineText; |
|
143 mFirstLineText = 0; |
|
144 |
|
145 delete mSecondLineText; |
|
146 mSecondLineText = 0; |
|
147 |
|
148 delete mFrameItem; |
|
149 mFrameItem = 0; |
|
150 |
|
151 delete mFocusItem; |
|
152 mFocusItem = 0; |
|
153 |
|
154 createPrimitives(); |
160 createPrimitives(); |
155 } |
161 } |
156 |
162 |
157 void CntContactCardDetailItem::initGesture() |
163 void CntContactCardDetailItem::initGesture() |
158 { |
164 { |
159 mGestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
165 grabGesture(Qt::TapAndHoldGesture, Qt::ReceivePartialGestures); |
160 mGestureLongpressed = new HbGesture(HbGesture::longpress, 5); |
166 grabGesture(Qt::TapGesture, Qt::ReceivePartialGestures); |
161 mGestureFilter->addGesture(mGestureLongpressed); |
167 } |
162 mGestureFilter->setLongpressAnimation(true); |
168 |
163 installSceneEventFilter(mGestureFilter); |
169 void CntContactCardDetailItem::gestureEvent(QGestureEvent* event) |
164 |
170 { |
165 connect(mGestureLongpressed, SIGNAL(longPress(QPointF)), this, SLOT(onLongPress(QPointF))); |
171 qDebug() << "CntContactCardDetailItem::gestureEvent - IN"; |
166 } |
172 event->accept( Qt::TapAndHoldGesture ); |
|
173 |
|
174 if (QGesture *tap = event->gesture(Qt::TapGesture)) |
|
175 { |
|
176 tapTriggered(static_cast<QTapGesture *>(tap)); |
|
177 event->accept( tap ); |
|
178 } |
|
179 |
|
180 if (QGesture *tapAndHold = event->gesture(Qt::TapAndHoldGesture)) |
|
181 { |
|
182 tapAndHoldTriggered(static_cast<QTapAndHoldGesture *>(tapAndHold)); |
|
183 event->accept( tapAndHold ); |
|
184 } |
|
185 qDebug() << "CntContactCardDetailItem::gestureEvent - OUT"; |
|
186 } |
|
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 |
167 |
230 |
168 void CntContactCardDetailItem::onLongPress(const QPointF &point) |
231 void CntContactCardDetailItem::onLongPress(const QPointF &point) |
169 { |
232 { |
170 mHasFocus = false; |
233 mHasFocus = false; |
171 updatePrimitives(); |
234 updatePrimitives(); |
184 { |
247 { |
185 HbEffect::start(mFocusItem, QString("frameitem"), QString("released")); |
248 HbEffect::start(mFocusItem, QString("frameitem"), QString("released")); |
186 } |
249 } |
187 } |
250 } |
188 |
251 |
|
252 /* |
189 void CntContactCardDetailItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
253 void CntContactCardDetailItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
190 { |
254 { |
191 if (mIsFocusable) |
255 if (mIsFocusable) |
192 { |
256 { |
193 HbInstantFeedback::play(HbFeedback::Basic); |
257 HbInstantFeedback::play(HbFeedback::Basic); |
194 } |
258 } |
195 event->accept(); |
259 event->accept(); |
196 mHasFocus = true; |
260 mHasFocus = true; |
197 updatePrimitives(); |
261 updatePrimitives(); |
198 } |
262 } |
199 |
263 */ |
|
264 /* |
200 void CntContactCardDetailItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
265 void CntContactCardDetailItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
201 { |
266 { |
202 if (!rect().contains(event->pos()) && mHasFocus) |
267 if (!rect().contains(event->pos()) && mHasFocus) |
203 { |
268 { |
204 mHasFocus = false; |
269 mHasFocus = false; |
217 updatePrimitives(); |
282 updatePrimitives(); |
218 emit clicked(); |
283 emit clicked(); |
219 } |
284 } |
220 event->accept(); |
285 event->accept(); |
221 } |
286 } |
|
287 */ |
222 |
288 |
223 void CntContactCardDetailItem::setDetails(CntContactCardDataItem* aDataItem) |
289 void CntContactCardDetailItem::setDetails(CntContactCardDataItem* aDataItem) |
224 { |
290 { |
225 text.clear(); |
|
226 valueText.clear(); |
|
227 icon.clear(); |
|
228 mValueTextElideMode = aDataItem->elideMode(); |
291 mValueTextElideMode = aDataItem->elideMode(); |
229 |
292 |
230 if (!aDataItem->icon().isNull()) |
293 if (aDataItem->icon() != icon) |
|
294 { |
|
295 icon.clear(); |
231 icon = aDataItem->icon(); |
296 icon = aDataItem->icon(); |
232 if (!aDataItem->titleText().isEmpty()) |
297 } |
|
298 if (aDataItem->secondaryIcon() != secondaryIcon) |
|
299 { |
|
300 secondaryIcon.clear(); |
|
301 secondaryIcon = aDataItem->secondaryIcon(); |
|
302 } |
|
303 if (aDataItem->titleText() != text) |
|
304 { |
|
305 text.clear(); |
233 text = aDataItem->titleText(); |
306 text = aDataItem->titleText(); |
234 if (!aDataItem->valueText().isEmpty()) |
307 } |
|
308 if (aDataItem->valueText() != valueText) |
|
309 { |
|
310 valueText.clear(); |
235 valueText = aDataItem->valueText(); |
311 valueText = aDataItem->valueText(); |
|
312 } |
236 |
313 |
237 recreatePrimitives(); |
314 recreatePrimitives(); |
238 } |
315 } |
239 |
316 |
240 int CntContactCardDetailItem::index() |
317 int CntContactCardDetailItem::index() |