|
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 "cnteditviewdetailitem.h" |
|
19 |
|
20 #include <hbiconitem.h> |
|
21 #include <hbtextitem.h> |
|
22 #include <hbframedrawer.h> |
|
23 #include <hbframeitem.h> |
|
24 #include <hbeffect.h> |
|
25 #include <hbgesturefilter.h> |
|
26 #include <hbgesture.h> |
|
27 #include <hbinstantfeedback.h> |
|
28 |
|
29 #include <QGraphicsSceneMouseEvent> |
|
30 |
|
31 CntEditViewDetailItem::CntEditViewDetailItem(QGraphicsItem *parent): |
|
32 HbWidget(parent), |
|
33 mIcon(0), |
|
34 mLabel(0), |
|
35 mContent(0), |
|
36 mFrameItem(0), |
|
37 mFocusItem(0), |
|
38 mHasFocus(false), |
|
39 mGestureFilter(0), |
|
40 mGestureLongpressed(0) |
|
41 { |
|
42 HbEffect::add(QString("frameitem"), QString(":/xml/edit_button_pressed.fxml"), QString("pressed")); |
|
43 HbEffect::add(QString("frameitem"), QString(":/xml/edit_button_released.fxml"), QString("released")); |
|
44 |
|
45 setFlag(QGraphicsItem::ItemIsFocusable, true); |
|
46 setFocusPolicy(Qt::StrongFocus); |
|
47 initGesture(); |
|
48 } |
|
49 |
|
50 CntEditViewDetailItem::~CntEditViewDetailItem() |
|
51 { |
|
52 |
|
53 } |
|
54 |
|
55 void CntEditViewDetailItem::createPrimitives() |
|
56 { |
|
57 if (!icon.isNull()) |
|
58 { |
|
59 if (!mIcon) |
|
60 { |
|
61 mIcon = new HbIconItem(this); |
|
62 mIcon->setIcon(icon); |
|
63 style()->setItemName(mIcon, "icon"); |
|
64 } |
|
65 } |
|
66 else |
|
67 { |
|
68 if (mIcon) |
|
69 { |
|
70 delete mIcon; |
|
71 } |
|
72 mIcon = 0; |
|
73 } |
|
74 |
|
75 if (!text.isNull()) |
|
76 { |
|
77 if (!mLabel) |
|
78 { |
|
79 mLabel = new HbTextItem(this); |
|
80 mLabel->setText(text); |
|
81 style()->setItemName(mLabel, "text"); |
|
82 } |
|
83 } |
|
84 else |
|
85 { |
|
86 if (mLabel) |
|
87 { |
|
88 delete mLabel; |
|
89 } |
|
90 mLabel = 0; |
|
91 } |
|
92 |
|
93 if (!valueText.isNull()) |
|
94 { |
|
95 if (!mContent) |
|
96 { |
|
97 mContent = new HbTextItem(this); |
|
98 mContent->setText(valueText); |
|
99 mContent->setTextWrapping(Hb::TextNoWrap); |
|
100 style()->setItemName(mContent, "valueText"); |
|
101 |
|
102 // make sure phone number truncation characters are placed |
|
103 // on left side of the phone number. |
|
104 if ( mDetail.definitionName() == QContactPhoneNumber::DefinitionName ) |
|
105 { |
|
106 mContent->setElideMode( Qt::ElideLeft ); |
|
107 } |
|
108 } |
|
109 } |
|
110 else |
|
111 { |
|
112 if (mContent) |
|
113 { |
|
114 delete mContent; |
|
115 } |
|
116 mContent = 0; |
|
117 } |
|
118 |
|
119 if (!mFrameItem) |
|
120 { |
|
121 mFrameItem = new HbFrameItem(this); |
|
122 mFrameItem->frameDrawer().setFrameGraphicsName("qtg_fr_list_normal"); |
|
123 mFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
124 mFrameItem->setZValue(-2); |
|
125 style()->setItemName(mFrameItem, "background"); |
|
126 } |
|
127 |
|
128 if (!mFocusItem) |
|
129 { |
|
130 mFocusItem = new HbFrameItem(this); |
|
131 mFocusItem->frameDrawer().setFrameGraphicsName("qtg_fr_list_pressed"); |
|
132 mFocusItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
133 mFocusItem->setZValue(-1); |
|
134 mFocusItem->setVisible(false); |
|
135 style()->setItemName(mFocusItem, "highlight"); |
|
136 } |
|
137 } |
|
138 |
|
139 void CntEditViewDetailItem::recreatePrimitives() |
|
140 { |
|
141 HbWidget::recreatePrimitives(); |
|
142 |
|
143 delete mIcon; |
|
144 mIcon = 0; |
|
145 |
|
146 delete mLabel; |
|
147 mLabel = 0; |
|
148 |
|
149 delete mContent; |
|
150 mContent = 0; |
|
151 |
|
152 delete mFrameItem; |
|
153 mFrameItem = 0; |
|
154 |
|
155 delete mFocusItem; |
|
156 mFocusItem = 0; |
|
157 |
|
158 createPrimitives(); |
|
159 } |
|
160 |
|
161 void CntEditViewDetailItem::initGesture() |
|
162 { |
|
163 mGestureFilter = new HbGestureSceneFilter(Qt::LeftButton, this); |
|
164 mGestureLongpressed = new HbGesture(HbGesture::longpress, 5); |
|
165 mGestureFilter->addGesture(mGestureLongpressed); |
|
166 mGestureFilter->setLongpressAnimation(true); |
|
167 installSceneEventFilter(mGestureFilter); |
|
168 |
|
169 connect(mGestureLongpressed, SIGNAL(longPress(QPointF)), this, SLOT(onLongPress(QPointF))); |
|
170 } |
|
171 |
|
172 void CntEditViewDetailItem::onLongPress(const QPointF &point) |
|
173 { |
|
174 mHasFocus = false; |
|
175 updatePrimitives(); |
|
176 emit longPressed(point); |
|
177 } |
|
178 |
|
179 void CntEditViewDetailItem::setDetail(const QContactDetail &detail, const QString &type) |
|
180 { |
|
181 bool doPolish = false; |
|
182 if (!mDetail.isEmpty() && detail != mDetail) |
|
183 { |
|
184 text.clear(); |
|
185 valueText.clear(); |
|
186 icon.clear(); |
|
187 doPolish = true; |
|
188 } |
|
189 mDetail = detail; |
|
190 mType = type; |
|
191 |
|
192 QString context; |
|
193 if (mDetail.contexts().count()) |
|
194 { |
|
195 context = mStringMapper.getMappedDetail(detail.contexts().at(0)); |
|
196 } |
|
197 |
|
198 // phone number |
|
199 if (mDetail.definitionName() == QContactPhoneNumber::DefinitionName) |
|
200 { |
|
201 QContactPhoneNumber number = mDetail; |
|
202 if (number.isEmpty()) |
|
203 { |
|
204 text = hbTrId("txt_phob_list_add_phone_number"); |
|
205 icon = HbIcon(mStringMapper.getMappedIcon(number.definitionName())); |
|
206 } |
|
207 else |
|
208 { |
|
209 QStringList list; |
|
210 list << mStringMapper.getMappedDetail(number.subTypes().at(0)) << context; |
|
211 text = list.join(" "); |
|
212 valueText = number.number(); |
|
213 icon = HbIcon(mStringMapper.getMappedIcon(number.subTypes().at(0))); |
|
214 } |
|
215 } |
|
216 |
|
217 // email address |
|
218 if (mDetail.definitionName() == QContactEmailAddress::DefinitionName) |
|
219 { |
|
220 QContactEmailAddress email = mDetail; |
|
221 if (email.isEmpty()) |
|
222 { |
|
223 text = hbTrId("txt_phob_list_add_email_address"); |
|
224 icon = HbIcon(mStringMapper.getMappedIcon(email.definitionName())); |
|
225 } |
|
226 else |
|
227 { |
|
228 QStringList list; |
|
229 list << mStringMapper.getMappedDetail(email.definitionName()) << context; |
|
230 text = list.join(" "); |
|
231 valueText = email.emailAddress(); |
|
232 icon = HbIcon(mStringMapper.getMappedIcon(email.definitionName())); |
|
233 } |
|
234 } |
|
235 |
|
236 // postal address |
|
237 if (mDetail.definitionName() == QContactAddress::DefinitionName) |
|
238 { |
|
239 QContactAddress address = mDetail; |
|
240 if (address.isEmpty()) |
|
241 { |
|
242 text = qtTrId("Add postal address"); |
|
243 icon = HbIcon(mStringMapper.getMappedIcon(address.definitionName())); |
|
244 } |
|
245 else |
|
246 { |
|
247 QStringList nameList; |
|
248 nameList << mStringMapper.getMappedDetail(address.definitionName()) << context; |
|
249 text = nameList.join(" "); |
|
250 QStringList list; |
|
251 if (!address.street().isEmpty()) |
|
252 list << address.street(); |
|
253 if (!address.postcode().isEmpty()) |
|
254 list << address.postcode(); |
|
255 if (!address.postOfficeBox().isEmpty()) |
|
256 list << address.postOfficeBox(); |
|
257 if (!address.locality().isEmpty()) |
|
258 list << address.locality(); |
|
259 if (!address.region().isEmpty()) |
|
260 list << address.region(); |
|
261 if (!address.country().isEmpty()) |
|
262 list << address.country(); |
|
263 |
|
264 QString data = list.join(", "); |
|
265 valueText = data; |
|
266 } |
|
267 } |
|
268 |
|
269 // online account |
|
270 if (mDetail.definitionName() == QContactOnlineAccount::DefinitionName) |
|
271 { |
|
272 QContactOnlineAccount account = mDetail; |
|
273 if (account.isEmpty()) |
|
274 { |
|
275 text = hbTrId("Add IM address"); |
|
276 icon = HbIcon(mStringMapper.getMappedIcon(account.definitionName())); |
|
277 } |
|
278 else |
|
279 { |
|
280 QStringList list; |
|
281 list << mStringMapper.getMappedDetail(account.subTypes().at(0)) << context; |
|
282 text = list.join(" "); |
|
283 valueText = account.accountUri(); |
|
284 icon = HbIcon(mStringMapper.getMappedIcon(account.subTypes().at(0))); |
|
285 } |
|
286 } |
|
287 |
|
288 // url address |
|
289 if (mDetail.definitionName() == QContactUrl::DefinitionName) |
|
290 { |
|
291 QContactUrl url = mDetail; |
|
292 if (url.isEmpty()) |
|
293 { |
|
294 text = hbTrId("txt_phob_list_add_url_address"); |
|
295 icon = HbIcon(mStringMapper.getMappedIcon(url.definitionName())); |
|
296 } |
|
297 else |
|
298 { |
|
299 QStringList list; |
|
300 list << mStringMapper.getMappedDetail(url.definitionName()) << context; |
|
301 text = list.join(" "); |
|
302 valueText = url.url(); |
|
303 icon = HbIcon(mStringMapper.getMappedIcon(url.definitionName())); |
|
304 } |
|
305 } |
|
306 |
|
307 // company details |
|
308 if (mDetail.definitionName() == QContactOrganization::DefinitionName) |
|
309 { |
|
310 QContactOrganization org = mDetail; |
|
311 |
|
312 // general details |
|
313 if (mType == QContactOrganization::DefinitionName) |
|
314 { |
|
315 text = mStringMapper.getMappedDetail(org.definitionName()); |
|
316 QStringList list; |
|
317 if(!org.title().isEmpty()) |
|
318 list << org.title(); |
|
319 if(!org.name().isEmpty()) |
|
320 list << org.name(); |
|
321 if(!org.department().isEmpty()) |
|
322 list << org.department().join(" "); |
|
323 valueText = list.join(", "); |
|
324 |
|
325 } |
|
326 // assistant name |
|
327 else if (mType == QContactOrganization::FieldAssistantName) |
|
328 { |
|
329 text = mStringMapper.getMappedDetail(QContactOrganization::FieldAssistantName); |
|
330 valueText = org.assistantName(); |
|
331 } |
|
332 } |
|
333 |
|
334 // birthday |
|
335 if (mDetail.definitionName() == QContactBirthday::DefinitionName) |
|
336 { |
|
337 QContactBirthday bDay = mDetail; |
|
338 |
|
339 text = mStringMapper.getMappedDetail(bDay.definitionName()); |
|
340 valueText = bDay.date().toString("dd MMMM yyyy"); |
|
341 } |
|
342 |
|
343 // anniversary |
|
344 if (mDetail.definitionName() == QContactAnniversary::DefinitionName) |
|
345 { |
|
346 QContactAnniversary anniversary = mDetail; |
|
347 |
|
348 text = mStringMapper.getMappedDetail(anniversary.definitionName()); |
|
349 valueText = anniversary.originalDate().toString("dd MMMM yyyy"); |
|
350 } |
|
351 |
|
352 // ringing tone |
|
353 if (mDetail.definitionName() == QContactAvatar::DefinitionName) |
|
354 { |
|
355 QContactAvatar avatar = mDetail; |
|
356 |
|
357 text = mStringMapper.getMappedDetail(QContactAvatar::SubTypeAudioRingtone); |
|
358 valueText = avatar.avatar(); |
|
359 } |
|
360 |
|
361 // note |
|
362 if (mDetail.definitionName() == QContactNote::DefinitionName) |
|
363 { |
|
364 QContactNote note = mDetail; |
|
365 |
|
366 text = mStringMapper.getMappedDetail(note.definitionName()); |
|
367 valueText = note.note(); |
|
368 } |
|
369 |
|
370 // family details |
|
371 if (mDetail.definitionName() == QContactFamily::DefinitionName) |
|
372 { |
|
373 QContactFamily family = mDetail; |
|
374 |
|
375 // spouse |
|
376 if (mType == QContactFamily::FieldSpouse) |
|
377 { |
|
378 text = mStringMapper.getMappedDetail(QContactFamily::FieldSpouse); |
|
379 valueText = family.spouse(); |
|
380 |
|
381 } |
|
382 // children |
|
383 else if (mType == QContactFamily::FieldChildren) |
|
384 { |
|
385 text = mStringMapper.getMappedDetail(QContactFamily::FieldChildren); |
|
386 valueText = family.children().join(", "); |
|
387 } |
|
388 } |
|
389 |
|
390 recreatePrimitives(); |
|
391 if (doPolish) |
|
392 { |
|
393 repolish(); |
|
394 } |
|
395 } |
|
396 |
|
397 QContactDetail CntEditViewDetailItem::detail() |
|
398 { |
|
399 return mDetail; |
|
400 } |
|
401 |
|
402 QString CntEditViewDetailItem::fieldType() |
|
403 { |
|
404 return mType; |
|
405 } |
|
406 |
|
407 void CntEditViewDetailItem::updatePrimitives() |
|
408 { |
|
409 HbWidget::updatePrimitives(); |
|
410 if (mHasFocus) |
|
411 { |
|
412 mFocusItem->setVisible(true); |
|
413 HbEffect::start(mFocusItem, QString("frameitem"), QString("pressed")); |
|
414 } |
|
415 else |
|
416 { |
|
417 HbEffect::start(mFocusItem, QString("frameitem"), QString("released")); |
|
418 } |
|
419 } |
|
420 |
|
421 void CntEditViewDetailItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
422 { |
|
423 HbInstantFeedback::play(HbFeedback::Basic); |
|
424 event->accept(); |
|
425 mHasFocus = true; |
|
426 updatePrimitives(); |
|
427 } |
|
428 |
|
429 void CntEditViewDetailItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
430 { |
|
431 if (!rect().contains(event->pos()) && mHasFocus) |
|
432 { |
|
433 mHasFocus = false; |
|
434 updatePrimitives(); |
|
435 } |
|
436 event->accept(); |
|
437 } |
|
438 |
|
439 |
|
440 void CntEditViewDetailItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
441 { |
|
442 bool hadFocus = mHasFocus; |
|
443 mHasFocus = false; |
|
444 if (rect().contains(event->pos()) && hadFocus) |
|
445 { |
|
446 updatePrimitives(); |
|
447 emit clicked(); |
|
448 } |
|
449 event->accept(); |
|
450 } |