|
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 "cnteditviewheadingitem.h" |
|
19 |
|
20 #include <qtcontacts.h> |
|
21 |
|
22 #include <hbiconitem.h> |
|
23 #include <hbtextitem.h> |
|
24 #include <hbframedrawer.h> |
|
25 #include <hbframeitem.h> |
|
26 #include <hbtoucharea.h> |
|
27 #include <hbinstantfeedback.h> |
|
28 |
|
29 #include <QGraphicsSceneMouseEvent> |
|
30 |
|
31 CntEditViewHeadingItem::CntEditViewHeadingItem(QGraphicsItem *parent) : |
|
32 HbWidget(parent), |
|
33 mIcon(0), |
|
34 mLabel(0), |
|
35 mSecondLabel(0), |
|
36 mFrameItem(0), |
|
37 mIconTouchArea(0), |
|
38 mIconFocused(false), |
|
39 mTextFocused(false) |
|
40 { |
|
41 |
|
42 } |
|
43 |
|
44 CntEditViewHeadingItem::~CntEditViewHeadingItem() |
|
45 { |
|
46 |
|
47 } |
|
48 |
|
49 void CntEditViewHeadingItem::createPrimitives() |
|
50 { |
|
51 if (!icon.isNull()) |
|
52 { |
|
53 if (!mIcon) |
|
54 { |
|
55 mIcon = new HbIconItem(this); |
|
56 mIcon->setIcon(icon); |
|
57 style()->setItemName(mIcon, "icon"); |
|
58 } |
|
59 } |
|
60 else |
|
61 { |
|
62 if (mIcon) |
|
63 { |
|
64 delete mIcon; |
|
65 } |
|
66 mIcon = 0; |
|
67 } |
|
68 |
|
69 if (!text.isNull()) |
|
70 { |
|
71 if (!mLabel) |
|
72 { |
|
73 mLabel = new HbTextItem(this); |
|
74 mLabel->setText(text); |
|
75 mLabel->setMaximumLines(2); |
|
76 mLabel->setTextWrapping(Hb::TextWordWrap); |
|
77 style()->setItemName(mLabel, "text"); |
|
78 } |
|
79 } |
|
80 else |
|
81 { |
|
82 if (mLabel) |
|
83 { |
|
84 delete mLabel; |
|
85 } |
|
86 mLabel = 0; |
|
87 } |
|
88 |
|
89 if (!second_text.isNull()) |
|
90 { |
|
91 if (!mSecondLabel) |
|
92 { |
|
93 mSecondLabel = new HbTextItem(this); |
|
94 mSecondLabel->setText(second_text); |
|
95 style()->setItemName(mSecondLabel, "second_text"); |
|
96 } |
|
97 } |
|
98 else |
|
99 { |
|
100 if (mSecondLabel) |
|
101 { |
|
102 delete mSecondLabel; |
|
103 } |
|
104 mSecondLabel = 0; |
|
105 } |
|
106 |
|
107 if (!mFrameItem) |
|
108 { |
|
109 mFrameItem = new HbFrameItem(this); |
|
110 mFrameItem->frameDrawer().setFrameGraphicsName("qtg_fr_groupbox"); |
|
111 mFrameItem->frameDrawer().setFrameType(HbFrameDrawer::NinePieces); |
|
112 mFrameItem->setZValue(-2); |
|
113 style()->setItemName(mFrameItem, "background"); |
|
114 } |
|
115 |
|
116 if (!mIconTouchArea) |
|
117 { |
|
118 mIconTouchArea = new HbTouchArea(this); |
|
119 style()->setItemName(mIconTouchArea, "iconArea"); |
|
120 } |
|
121 } |
|
122 |
|
123 void CntEditViewHeadingItem::recreatePrimitives() |
|
124 { |
|
125 HbWidget::recreatePrimitives(); |
|
126 |
|
127 delete mIcon; |
|
128 mIcon = 0; |
|
129 |
|
130 delete mLabel; |
|
131 mLabel = 0; |
|
132 |
|
133 delete mSecondLabel; |
|
134 mSecondLabel = 0; |
|
135 |
|
136 delete mFrameItem; |
|
137 mFrameItem = 0; |
|
138 |
|
139 delete mIconTouchArea; |
|
140 mIconTouchArea = 0; |
|
141 |
|
142 createPrimitives(); |
|
143 } |
|
144 |
|
145 |
|
146 void CntEditViewHeadingItem::updatePrimitives() |
|
147 { |
|
148 HbWidget::updatePrimitives(); |
|
149 } |
|
150 |
|
151 void CntEditViewHeadingItem::setDetails(const QContact* contact) |
|
152 { |
|
153 text.clear(); |
|
154 second_text.clear(); |
|
155 icon.clear(); |
|
156 |
|
157 // icon label shows default icon first |
|
158 icon = HbIcon(":/icons/qtg_large_avatar.svg"); |
|
159 |
|
160 QContactName name = contact->detail<QContactName>(); |
|
161 |
|
162 QStringList nameList; |
|
163 if (!name.prefix().isEmpty()) |
|
164 { |
|
165 nameList << name.prefix(); |
|
166 } |
|
167 if (!name.first().isEmpty()) |
|
168 { |
|
169 nameList << name.first(); |
|
170 } |
|
171 if (!name.middle().isEmpty()) |
|
172 { |
|
173 nameList << name.middle(); |
|
174 } |
|
175 if (!name.last().isEmpty()) |
|
176 { |
|
177 nameList << name.last(); |
|
178 } |
|
179 if (!name.suffix().isEmpty()) |
|
180 { |
|
181 nameList << name.suffix(); |
|
182 } |
|
183 text = nameList.join(" "); |
|
184 |
|
185 if (!contact->detail<QContactNickname>().nickname().isEmpty()) |
|
186 { |
|
187 second_text = hbTrId("\"%1\"").arg(contact->detail<QContactNickname>().nickname()); |
|
188 } |
|
189 |
|
190 if (text.isEmpty() && second_text.isEmpty()) |
|
191 { |
|
192 text = hbTrId("txt_phob_list_enter_name"); |
|
193 } |
|
194 |
|
195 recreatePrimitives(); |
|
196 } |
|
197 |
|
198 void CntEditViewHeadingItem::setIcon(const HbIcon newIcon) |
|
199 { |
|
200 if (newIcon != icon) |
|
201 { |
|
202 icon = newIcon; |
|
203 createPrimitives(); |
|
204 mIcon->setIcon(icon); |
|
205 repolish(); |
|
206 } |
|
207 } |
|
208 |
|
209 void CntEditViewHeadingItem::mousePressEvent(QGraphicsSceneMouseEvent *event) |
|
210 { |
|
211 HbInstantFeedback::play(HbFeedback::Basic); |
|
212 if (mIconTouchArea->rect().contains(event->pos())) |
|
213 { |
|
214 mIconFocused = true; |
|
215 } |
|
216 else if (rect().contains(event->pos())) |
|
217 { |
|
218 mTextFocused = true; |
|
219 } |
|
220 |
|
221 event->accept(); |
|
222 } |
|
223 |
|
224 void CntEditViewHeadingItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event) |
|
225 { |
|
226 if (!mIconTouchArea->rect().contains(event->pos()) && mIconFocused) |
|
227 { |
|
228 mIconFocused = false; |
|
229 } |
|
230 else if ((!rect().contains(event->pos()) || mIconTouchArea->rect().contains(event->pos())) && mTextFocused) |
|
231 { |
|
232 mTextFocused = false; |
|
233 } |
|
234 event->accept(); |
|
235 } |
|
236 |
|
237 |
|
238 void CntEditViewHeadingItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
239 { |
|
240 if (mIconTouchArea->rect().contains(event->pos()) && mIconFocused) |
|
241 { |
|
242 mIconFocused = false; |
|
243 emit iconClicked(); |
|
244 } |
|
245 else if (rect().contains(event->pos()) && !mIconTouchArea->rect().contains(event->pos()) && mTextFocused) |
|
246 { |
|
247 mTextFocused = false; |
|
248 emit textClicked(); |
|
249 } |
|
250 event->accept(); |
|
251 } |