68
|
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 |
|
74
|
18 |
#include <qregexp.h>
|
68
|
19 |
#include <hbtextitem.h>
|
|
20 |
#include <hbiconitem.h>
|
|
21 |
#include <hbframeitem.h>
|
|
22 |
#include <hbframebackground.h>
|
|
23 |
#include <hbextendedlocale.h>
|
|
24 |
#include <hbcolorscheme.h>
|
|
25 |
#include <nmmessageenvelope.h>
|
|
26 |
#include <nmicons.h>
|
74
|
27 |
#include <hbstringutil.h>
|
68
|
28 |
#include "nmhswidgetlistviewitem.h"
|
|
29 |
|
|
30 |
/*!
|
|
31 |
\class NmHsWidgetListViewItem
|
|
32 |
\brief Mail widget list view item inherited from HbListViewItem
|
|
33 |
*/
|
|
34 |
|
|
35 |
/*!
|
|
36 |
Constructor
|
|
37 |
*/
|
|
38 |
NmHsWidgetListViewItem::NmHsWidgetListViewItem(QGraphicsItem *parent)
|
|
39 |
: HbListViewItem(parent),
|
|
40 |
mSeparator(NULL),
|
|
41 |
mSender(NULL),
|
|
42 |
mSubject(NULL),
|
|
43 |
mTime(NULL),
|
|
44 |
mNewMsgIcon(NULL),
|
|
45 |
mIcon1(NULL),
|
|
46 |
mIcon2(NULL)
|
|
47 |
{
|
|
48 |
NM_FUNCTION;
|
|
49 |
}
|
|
50 |
|
|
51 |
/*!
|
|
52 |
Destructor
|
|
53 |
*/
|
|
54 |
NmHsWidgetListViewItem::~NmHsWidgetListViewItem()
|
|
55 |
{
|
|
56 |
NM_FUNCTION;
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
Item creation
|
|
61 |
*/
|
|
62 |
HbAbstractViewItem* NmHsWidgetListViewItem::createItem()
|
|
63 |
{
|
|
64 |
NM_FUNCTION;
|
|
65 |
|
|
66 |
return new NmHsWidgetListViewItem(*this);
|
|
67 |
}
|
|
68 |
|
|
69 |
/*!
|
|
70 |
update child items
|
|
71 |
*/
|
|
72 |
void NmHsWidgetListViewItem::updateChildItems()
|
|
73 |
{
|
|
74 |
NM_FUNCTION;
|
|
75 |
|
|
76 |
NmMessageEnvelope *envelope =
|
|
77 |
modelIndex().data(Qt::DisplayRole).value<NmMessageEnvelope*>();
|
|
78 |
|
|
79 |
createMessageItemLayout();
|
|
80 |
setContentsToMessageItem(*envelope);
|
|
81 |
|
|
82 |
HbListViewItem::updateChildItems();
|
|
83 |
}
|
|
84 |
|
|
85 |
/*!
|
|
86 |
Set item layout.
|
|
87 |
Function does not take ownership of model or model item.
|
|
88 |
*/
|
|
89 |
void NmHsWidgetListViewItem::createMessageItemLayout()
|
|
90 |
{
|
|
91 |
NM_FUNCTION;
|
|
92 |
getFontSizes();
|
|
93 |
// Create separator icon and set name from widgetml.
|
|
94 |
if (!mSeparator) {
|
|
95 |
mSeparator = new HbIconItem(this);
|
|
96 |
HbStyle::setItemName(mSeparator, "separator");
|
|
97 |
mSeparator->setObjectName("ListViewItemMessageSeparator");
|
|
98 |
mSeparator->setIcon(HbIcon("qtg_graf_divider_h_thin"));
|
|
99 |
}
|
|
100 |
// Create sender label and set name from widgetml.
|
|
101 |
if (!mSender) {
|
|
102 |
mSender = new HbTextItem(this);
|
|
103 |
HbStyle::setItemName(mSender, "sender");
|
|
104 |
mSender->setObjectName("ListViewItemMessageSender");
|
|
105 |
}
|
|
106 |
// Create time label and set name from widgetml.
|
|
107 |
if (!mTime) {
|
|
108 |
mTime = new HbTextItem(this);
|
|
109 |
HbStyle::setItemName(mTime, "time");
|
|
110 |
mTime->setObjectName("ListViewItemMessageTime");
|
|
111 |
}
|
|
112 |
// Create subject label and set name from widgetml.
|
|
113 |
if (!mSubject) {
|
|
114 |
mSubject = new HbTextItem(this);
|
|
115 |
HbStyle::setItemName(mSubject, "subject");
|
|
116 |
mSubject->setObjectName("ListViewItemMessageSubject");
|
|
117 |
}
|
|
118 |
// Set new message icon.
|
|
119 |
if (!mNewMsgIcon) {
|
|
120 |
mNewMsgIcon = new HbFrameItem(this);
|
|
121 |
HbStyle::setItemName(mNewMsgIcon, "msgicon");
|
|
122 |
}
|
|
123 |
|
|
124 |
// Create priority icon and set name from widgetml.
|
|
125 |
if(!mIcon1){
|
|
126 |
mIcon1 = new HbIconItem(this);
|
|
127 |
HbStyle::setItemName(mIcon1, "icon1");
|
|
128 |
mStatusIcons.append(mIcon1);
|
|
129 |
}
|
|
130 |
|
|
131 |
// Create attachment icon and set name from widgetml.
|
|
132 |
if(!mIcon2){
|
|
133 |
mIcon2 = new HbIconItem(this);
|
|
134 |
HbStyle::setItemName(mIcon2, "icon2");
|
|
135 |
mStatusIcons.append(mIcon2);
|
|
136 |
}
|
|
137 |
|
|
138 |
//set empty frame as list item only shows background when selected
|
|
139 |
setDefaultFrame(HbFrameBackground("", HbFrameDrawer::OnePiece));
|
|
140 |
}
|
|
141 |
|
|
142 |
/*!
|
|
143 |
Set item text label contents, icons, etc.
|
|
144 |
Function does not take ownership of model or model item.
|
|
145 |
*/
|
|
146 |
void NmHsWidgetListViewItem::setContentsToMessageItem(const NmMessageEnvelope &envelope)
|
|
147 |
{
|
|
148 |
NM_FUNCTION;
|
|
149 |
// Member variables are created in previous function.
|
|
150 |
// Sender.
|
|
151 |
QString senderDisplayName = envelope.sender().displayName();
|
|
152 |
if (!senderDisplayName.isNull() && !senderDisplayName.isEmpty()) {
|
74
|
153 |
mSender->setText(cleanupDisplayName(senderDisplayName));
|
68
|
154 |
}
|
|
155 |
else {
|
|
156 |
mSender->setText(envelope.sender().address());
|
|
157 |
}
|
|
158 |
|
|
159 |
// Time.
|
|
160 |
HbExtendedLocale locale = HbExtendedLocale::system();
|
|
161 |
QDateTime localTime = envelope.sentTime().addSecs(locale.universalTimeOffset());
|
|
162 |
QDate sentLocalDate = localTime.date();
|
|
163 |
QDate currentdate = QDate::currentDate();
|
|
164 |
if (sentLocalDate == currentdate) {
|
|
165 |
QString shortTimeSpec = r_qtn_time_usual;
|
|
166 |
QTime time = localTime.time();
|
74
|
167 |
mTime->setText(HbStringUtil::convertDigits(locale.format(time, shortTimeSpec)));
|
68
|
168 |
} else {
|
|
169 |
QString shortDateSpec = r_qtn_date_without_year;
|
74
|
170 |
mTime->setText(HbStringUtil::convertDigits(locale.format(sentLocalDate, shortDateSpec)));
|
68
|
171 |
}
|
|
172 |
// Subject.
|
|
173 |
QString subjectText = envelope.subject();
|
|
174 |
if (subjectText.length()) {
|
|
175 |
mSubject->setText(subjectText);
|
|
176 |
} else {
|
|
177 |
mSubject->setText(hbTrId("txt_mailwdgt_dblist_val_no_subject"));
|
|
178 |
}
|
|
179 |
|
|
180 |
// Here we have list for priority and attachment icons. Later it is easy to add
|
|
181 |
// followup icon or something else if needed.
|
|
182 |
QList<HbIcon> iconList;
|
|
183 |
|
|
184 |
//make sure icons are not shown yet
|
|
185 |
for (int i = 0; i < mStatusIcons.count(); i++) {
|
|
186 |
mStatusIcons.at(i)->hide();
|
|
187 |
}
|
|
188 |
|
|
189 |
// Priority icon is added to list first thus it is always shown most right.
|
|
190 |
switch (envelope.priority()) {
|
|
191 |
case NmMessagePriorityLow:
|
|
192 |
iconList.append(NmIcons::getIcon(NmIcons::NmIconPriorityLow));
|
|
193 |
break;
|
|
194 |
case NmMessagePriorityHigh:
|
|
195 |
iconList.append(NmIcons::getIcon(NmIcons::NmIconPriorityHigh));
|
|
196 |
break;
|
|
197 |
default:
|
|
198 |
// Normal priority has no icon
|
|
199 |
break;
|
|
200 |
}
|
|
201 |
|
|
202 |
// Attachment icon is always shown on the left side of priority icon if it
|
|
203 |
// exists. Otherwise in the most right.
|
|
204 |
if (envelope.hasAttachments()) {
|
|
205 |
iconList.append(NmIcons::getIcon(NmIcons::NmIconAttachment));
|
|
206 |
}
|
|
207 |
|
|
208 |
// Here we show icons added to the iconList in the order they have been added.
|
|
209 |
for (int count = 0; count < iconList.count(); count++) {
|
|
210 |
mStatusIcons.at(count)->setIcon(iconList.at(count));
|
|
211 |
mStatusIcons.at(count)->show();
|
|
212 |
}
|
|
213 |
|
|
214 |
// Message read status.
|
|
215 |
bool msgReadStatus(envelope.isRead());
|
|
216 |
HbFrameDrawer *drawer(NULL);
|
|
217 |
HbStyle::setItemName(mNewMsgIcon, "msgicon");
|
|
218 |
if (!msgReadStatus) {
|
|
219 |
setFontsUnread();
|
|
220 |
mNewMsgIcon->setObjectName("ListViewItemMessageIconUnread");
|
|
221 |
drawer = new HbFrameDrawer("qtg_fr_list_new_item",
|
|
222 |
HbFrameDrawer::ThreePiecesVertical);
|
|
223 |
drawer->setFillWholeRect(false);
|
|
224 |
// Set drawer. Takes ownership of the drawer and deletes previous drawer.
|
|
225 |
mNewMsgIcon->setFrameDrawer(drawer);
|
|
226 |
mNewMsgIcon->show();
|
|
227 |
} else {
|
|
228 |
setFontsRead();
|
|
229 |
mNewMsgIcon->setObjectName("ListViewItemMessageIconRead");
|
|
230 |
drawer = new HbFrameDrawer(); // Create empty drawer.
|
|
231 |
drawer->setFillWholeRect(false);
|
|
232 |
// Set drawer. Takes ownership of the drawer and deletes previous drawer.
|
|
233 |
mNewMsgIcon->setFrameDrawer(drawer);
|
|
234 |
mNewMsgIcon->hide();
|
|
235 |
}
|
|
236 |
repolish();
|
|
237 |
}
|
|
238 |
|
|
239 |
/*!
|
|
240 |
Boolean value indicating model index availability. Always true since
|
|
241 |
this item prototype is used for both divider and message.
|
|
242 |
*/
|
|
243 |
bool NmHsWidgetListViewItem::canSetModelIndex(const QModelIndex &index) const
|
|
244 |
{
|
|
245 |
NM_FUNCTION;
|
|
246 |
Q_UNUSED(index);
|
|
247 |
// This item class can handle all items in message list.
|
|
248 |
return true;
|
|
249 |
}
|
|
250 |
|
|
251 |
/*!
|
|
252 |
Set fonts unread.
|
|
253 |
*/
|
|
254 |
void NmHsWidgetListViewItem::setFontsUnread()
|
|
255 |
{
|
|
256 |
NM_FUNCTION;
|
|
257 |
static QColor colorRole = HbColorScheme::color("qtc_list_item_title_normal");
|
|
258 |
HbFontSpec fontSpec(HbFontSpec::Primary);
|
|
259 |
setFonts(colorRole, fontSpec);
|
|
260 |
}
|
|
261 |
|
|
262 |
/*!
|
|
263 |
Set fonts read.
|
|
264 |
*/
|
|
265 |
void NmHsWidgetListViewItem::setFontsRead()
|
|
266 |
{
|
|
267 |
NM_FUNCTION;
|
|
268 |
static QColor colorRole = HbColorScheme::color("qtc_list_item_content_normal");
|
|
269 |
HbFontSpec fontSpec(HbFontSpec::Secondary);
|
|
270 |
setFonts(colorRole, fontSpec);
|
|
271 |
}
|
|
272 |
|
|
273 |
/*!
|
|
274 |
Get font sizes.
|
|
275 |
*/
|
|
276 |
void NmHsWidgetListViewItem::getFontSizes()
|
|
277 |
{
|
|
278 |
NM_FUNCTION;
|
|
279 |
// Get font sizes from style.
|
|
280 |
qreal currentSize;
|
|
281 |
bool found = style()->parameter(QString("hb-param-text-height-secondary"), currentSize );
|
|
282 |
if (found) {
|
|
283 |
mPrimarySize = currentSize;
|
|
284 |
}
|
|
285 |
found = style()->parameter(QString("hb-param-text-height-tiny"), currentSize );
|
|
286 |
if (found) {
|
|
287 |
mSecondarySize = currentSize;
|
|
288 |
}
|
|
289 |
}
|
|
290 |
|
|
291 |
/*!
|
|
292 |
Set fonts.
|
|
293 |
*/
|
|
294 |
void NmHsWidgetListViewItem::setFonts(const QColor &colorRole,
|
|
295 |
HbFontSpec &fontSpec)
|
|
296 |
{
|
|
297 |
NM_FUNCTION;
|
|
298 |
// Change sizes explicitly since css is overwritten in polish now.
|
|
299 |
if (mSender && mSubject && mTime) {
|
|
300 |
|
|
301 |
fontSpec.setTextHeight(mPrimarySize);
|
|
302 |
|
|
303 |
mSender->setFontSpec(fontSpec);
|
|
304 |
mSender->setTextColor(colorRole);
|
|
305 |
|
|
306 |
mSubject->setFontSpec(fontSpec);
|
|
307 |
mSubject->setTextColor(colorRole);
|
|
308 |
|
|
309 |
fontSpec.setTextHeight(mSecondarySize);
|
|
310 |
|
|
311 |
mTime->setFontSpec(fontSpec);
|
|
312 |
mTime->setTextColor(colorRole);
|
|
313 |
}
|
|
314 |
}
|
74
|
315 |
|
|
316 |
/*!
|
|
317 |
Cleans up display name by stripping extra characters from the beginning and end of the string.
|
|
318 |
*/
|
|
319 |
QString NmHsWidgetListViewItem::cleanupDisplayName( const QString &displayName )
|
|
320 |
{
|
|
321 |
NM_FUNCTION;
|
|
322 |
|
|
323 |
// find the first and last position that is NOT one of the characters below
|
|
324 |
QRegExp rx("[^\\s\"<>]");
|
|
325 |
int firstPos = std::max(rx.indexIn(displayName), 0);
|
|
326 |
int lastPos = rx.lastIndexIn(displayName);
|
|
327 |
|
|
328 |
if (lastPos < 0) {
|
|
329 |
lastPos = displayName.length() - 1;
|
|
330 |
}
|
|
331 |
|
|
332 |
return displayName.mid(firstPos, lastPos - firstPos + 1);
|
|
333 |
}
|