20 #include <hbiconitem.h> |
20 #include <hbiconitem.h> |
21 #include <hbframeitem.h> |
21 #include <hbframeitem.h> |
22 #include <hbframebackground.h> |
22 #include <hbframebackground.h> |
23 #include <hbextendedlocale.h> |
23 #include <hbextendedlocale.h> |
24 #include <hbcolorscheme.h> |
24 #include <hbcolorscheme.h> |
|
25 #include <hbevent.h> |
25 #include <nmmessageenvelope.h> |
26 #include <nmmessageenvelope.h> |
26 #include <nmicons.h> |
27 #include <nmicons.h> |
27 #include <hbstringutil.h> |
28 #include <hbstringutil.h> |
28 #include "nmhswidgetlistviewitem.h" |
29 #include "nmhswidgetlistviewitem.h" |
29 |
30 |
159 // Time. |
160 // Time. |
160 HbExtendedLocale locale = HbExtendedLocale::system(); |
161 HbExtendedLocale locale = HbExtendedLocale::system(); |
161 QDateTime localTime = envelope.sentTime().addSecs(locale.universalTimeOffset()); |
162 QDateTime localTime = envelope.sentTime().addSecs(locale.universalTimeOffset()); |
162 QDate sentLocalDate = localTime.date(); |
163 QDate sentLocalDate = localTime.date(); |
163 QDate currentdate = QDate::currentDate(); |
164 QDate currentdate = QDate::currentDate(); |
|
165 QString timeString; |
164 if (sentLocalDate == currentdate) { |
166 if (sentLocalDate == currentdate) { |
165 QString shortTimeSpec = r_qtn_time_usual; |
167 QString shortTimeSpec = r_qtn_time_usual; |
166 QTime time = localTime.time(); |
168 QTime time = localTime.time(); |
167 mTime->setText(HbStringUtil::convertDigits(locale.format(time, shortTimeSpec))); |
169 timeString = HbStringUtil::convertDigits(locale.format(time, shortTimeSpec)); |
168 } else { |
170 } else { |
169 QString shortDateSpec = r_qtn_date_without_year; |
171 QString shortDateSpec = r_qtn_date_without_year; |
170 mTime->setText(HbStringUtil::convertDigits(locale.format(sentLocalDate, shortDateSpec))); |
172 timeString = HbStringUtil::convertDigits(locale.format(sentLocalDate, shortDateSpec)); |
171 } |
173 } |
|
174 //shrink/expand the date field, so that sender field is as large as possible |
|
175 QFontMetrics fm(mTime->font()); |
|
176 qreal textWidth = fm.width(timeString); |
|
177 mTime->setMaximumWidth(textWidth); |
|
178 mTime->setText(timeString); |
|
179 |
172 // Subject. |
180 // Subject. |
173 QString subjectText = envelope.subject(); |
181 QString subjectText = envelope.subject(); |
174 if (subjectText.length()) { |
182 if (subjectText.length()) { |
175 mSubject->setText(subjectText); |
183 mSubject->setText(subjectText); |
176 } else { |
184 } else { |
182 QList<HbIcon> iconList; |
190 QList<HbIcon> iconList; |
183 |
191 |
184 //make sure icons are not shown yet |
192 //make sure icons are not shown yet |
185 for (int i = 0; i < mStatusIcons.count(); i++) { |
193 for (int i = 0; i < mStatusIcons.count(); i++) { |
186 mStatusIcons.at(i)->hide(); |
194 mStatusIcons.at(i)->hide(); |
|
195 mStatusIcons.at(i)->setPreferredWidth(0); //Do not consume space! |
187 } |
196 } |
188 |
197 |
189 // Priority icon is added to list first thus it is always shown most right. |
198 // Priority icon is added to list first thus it is always shown most right. |
190 switch (envelope.priority()) { |
199 switch (envelope.priority()) { |
191 case NmMessagePriorityLow: |
200 case NmMessagePriorityLow: |
207 |
216 |
208 // Here we show icons added to the iconList in the order they have been added. |
217 // Here we show icons added to the iconList in the order they have been added. |
209 for (int count = 0; count < iconList.count(); count++) { |
218 for (int count = 0; count < iconList.count(); count++) { |
210 mStatusIcons.at(count)->setIcon(iconList.at(count)); |
219 mStatusIcons.at(count)->setIcon(iconList.at(count)); |
211 mStatusIcons.at(count)->show(); |
220 mStatusIcons.at(count)->show(); |
|
221 mStatusIcons.at(count)->setMinimumWidth(mStatusIcons.at(count)->maximumWidth()); |
212 } |
222 } |
213 |
223 |
214 // Message read status. |
224 // Message read status. |
215 bool msgReadStatus(envelope.isRead()); |
225 bool msgReadStatus(envelope.isRead()); |
216 HbFrameDrawer *drawer(NULL); |
226 HbFrameDrawer *drawer(NULL); |
252 Set fonts unread. |
262 Set fonts unread. |
253 */ |
263 */ |
254 void NmHsWidgetListViewItem::setFontsUnread() |
264 void NmHsWidgetListViewItem::setFontsUnread() |
255 { |
265 { |
256 NM_FUNCTION; |
266 NM_FUNCTION; |
257 static QColor colorRole = HbColorScheme::color("qtc_list_item_title_normal"); |
267 QColor colorRole = HbColorScheme::color("qtc_hs_list_item_title_normal"); |
258 HbFontSpec fontSpec(HbFontSpec::Primary); |
268 HbFontSpec fontSpec(HbFontSpec::Primary); |
259 setFonts(colorRole, fontSpec); |
269 setFonts(colorRole, fontSpec); |
260 } |
270 } |
261 |
271 |
262 /*! |
272 /*! |
263 Set fonts read. |
273 Set fonts read. |
264 */ |
274 */ |
265 void NmHsWidgetListViewItem::setFontsRead() |
275 void NmHsWidgetListViewItem::setFontsRead() |
266 { |
276 { |
267 NM_FUNCTION; |
277 NM_FUNCTION; |
268 static QColor colorRole = HbColorScheme::color("qtc_list_item_content_normal"); |
278 QColor colorRole = HbColorScheme::color("qtc_hs_list_item_content_normal"); |
269 HbFontSpec fontSpec(HbFontSpec::Secondary); |
279 HbFontSpec fontSpec(HbFontSpec::Secondary); |
270 setFonts(colorRole, fontSpec); |
280 setFonts(colorRole, fontSpec); |
271 } |
281 } |
272 |
282 |
273 /*! |
283 /*! |
300 |
310 |
301 fontSpec.setTextHeight(mPrimarySize); |
311 fontSpec.setTextHeight(mPrimarySize); |
302 |
312 |
303 mSender->setFontSpec(fontSpec); |
313 mSender->setFontSpec(fontSpec); |
304 mSender->setTextColor(colorRole); |
314 mSender->setTextColor(colorRole); |
|
315 |
|
316 fontSpec.setTextHeight(mSecondarySize); |
305 |
317 |
306 mSubject->setFontSpec(fontSpec); |
318 mSubject->setFontSpec(fontSpec); |
307 mSubject->setTextColor(colorRole); |
319 mSubject->setTextColor(colorRole); |
308 |
320 |
309 fontSpec.setTextHeight(mSecondarySize); |
|
310 |
|
311 mTime->setFontSpec(fontSpec); |
321 mTime->setFontSpec(fontSpec); |
312 mTime->setTextColor(colorRole); |
322 mTime->setTextColor(colorRole); |
313 } |
323 } |
314 } |
324 } |
315 |
325 |
329 lastPos = displayName.length() - 1; |
339 lastPos = displayName.length() - 1; |
330 } |
340 } |
331 |
341 |
332 return displayName.mid(firstPos, lastPos - firstPos + 1); |
342 return displayName.mid(firstPos, lastPos - firstPos + 1); |
333 } |
343 } |
|
344 |
|
345 |
|
346 /*! |
|
347 Handle font color changes in the case of theme change |
|
348 */ |
|
349 bool NmHsWidgetListViewItem::event(QEvent *event) |
|
350 { |
|
351 NM_FUNCTION; |
|
352 |
|
353 bool ret = HbListViewItem::event(event); |
|
354 if (event && event->type() == HbEvent::ThemeChanged) { |
|
355 NmMessageEnvelope *envelope = |
|
356 modelIndex().data(Qt::DisplayRole).value<NmMessageEnvelope*>(); |
|
357 if (envelope && !envelope->isRead()) { |
|
358 setFontsUnread(); |
|
359 } |
|
360 else if (envelope) { |
|
361 setFontsRead(); |
|
362 } |
|
363 } |
|
364 return ret; |
|
365 } |