1 /* |
1 /* |
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies). |
3 * All rights reserved. |
3 * All rights reserved. |
4 * This component and the accompanying materials are made available |
4 * This component and the accompanying materials are made available |
5 * under the terms of "Eclipse Public License v1.0" |
5 * under the terms of "Eclipse Public License v1.0" |
6 * which accompanies this distribution, and is available |
6 * which accompanies this distribution, and is available |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
8 * |
8 * |
9 * Initial Contributors: |
9 * Initial Contributors: |
10 * Nokia Corporation - initial contribution. |
10 * Nokia Corporation - initial contribution. |
11 * |
11 * |
12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * |
14 * Description: |
15 */ |
15 * |
|
16 */ |
16 |
17 |
17 #include "nmuiheaders.h" |
18 #include "nmuiheaders.h" |
18 |
19 |
19 /*! |
20 /*! |
20 \class NmMessageListViewItem |
21 \class NmMessageListViewItem |
21 \brief list view item for message list view |
22 \brief List view item for message list view. |
22 */ |
23 */ |
23 |
24 |
24 static const int NmFolderTypeRole = Qt::UserRole+1; |
25 static const int NmFolderTypeRole = Qt::UserRole+1; |
25 |
26 |
26 /*! |
27 /*! |
27 Constructor |
28 Constructor. |
28 */ |
29 */ |
29 NmMessageListViewItem::NmMessageListViewItem(QGraphicsItem *parent): |
30 NmMessageListViewItem::NmMessageListViewItem(QGraphicsItem *parent) |
30 HbTreeViewItem(parent), |
31 : HbTreeViewItem(parent), |
31 mSender(NULL), |
32 mSender(NULL), |
32 mSubject(NULL), |
33 mSubject(NULL), |
33 mTime(NULL), |
34 mTime(NULL), |
34 mDividerTitle(NULL), |
35 mDividerTitle(NULL), |
35 mNewMsgIcon(NULL), |
36 mNewMsgIcon(NULL), |
36 mIcon1(NULL), |
37 mIcon1(NULL), |
37 mIcon2(NULL), |
38 mIcon2(NULL), |
38 mPrimarySize(0), |
39 mPrimarySize(0), |
39 mSecondarySize(0) |
40 mSecondarySize(0) |
40 { |
41 { |
41 NM_FUNCTION; |
42 } |
42 } |
43 |
43 |
44 /*! |
44 /*! |
45 Destructor. |
45 Destruction. |
46 */ |
46 */ |
|
47 NmMessageListViewItem::~NmMessageListViewItem() |
47 NmMessageListViewItem::~NmMessageListViewItem() |
48 { |
48 { |
49 NM_FUNCTION; |
49 } |
50 } |
50 |
51 |
51 /*! |
52 /*! |
52 Create item. |
53 */ |
53 */ |
54 HbTreeViewItem *NmMessageListViewItem::createItem() |
54 HbTreeViewItem *NmMessageListViewItem::createItem() |
55 { |
55 { |
56 NM_FUNCTION; |
|
57 |
|
58 return new NmMessageListViewItem(*this); |
56 return new NmMessageListViewItem(*this); |
59 } |
57 } |
60 |
58 |
61 /*! |
59 /*! |
62 boolean value indicating model index availability. Always true since |
60 Boolean value indicating model index availability. Always true since |
63 this item prototype is used for both divider and message |
61 this item prototype is used for both divider and message. |
64 */ |
62 */ |
65 bool NmMessageListViewItem::canSetModelIndex(const QModelIndex &index) const |
63 bool NmMessageListViewItem::canSetModelIndex(const QModelIndex &index) const |
66 { |
64 { |
67 NM_FUNCTION; |
|
68 |
|
69 Q_UNUSED(index); |
65 Q_UNUSED(index); |
70 // This item class can handle all items in message list |
66 // This item class can handle all items in message list. |
71 return true; |
67 return true; |
72 } |
68 } |
73 |
69 |
74 /*! |
70 /*! |
75 update child items. List calls this function whenever item is needed |
71 Update child items. List calls this function whenever item is needed |
76 to be updated. |
72 to be updated. |
77 */ |
73 */ |
78 void NmMessageListViewItem::updateChildItems() |
74 void NmMessageListViewItem::updateChildItems() |
79 { |
75 { |
80 NM_FUNCTION; |
|
81 |
|
82 // Get model pointer |
76 // Get model pointer |
83 NmMessageListModelItem *msgModelItem = modelIndex().data( |
77 NmMessageListModelItem *msgModelItem = modelIndex().data( |
84 Qt::DisplayRole).value<NmMessageListModelItem*>(); |
78 Qt::DisplayRole).value<NmMessageListModelItem*>(); |
85 // Check whether item is message item or title divider |
79 // Check whether item is message item or title divider |
86 // and set the layout accordingly, dividers not currently used |
80 // and set the layout accordingly. Dividers are not currently used. |
87 if (msgModelItem && msgModelItem->itemType() == |
81 if (msgModelItem && msgModelItem->itemType() == |
88 NmMessageListModelItem::NmMessageItemMessage){ |
82 NmMessageListModelItem::NmMessageItemMessage){ |
89 NmMessageListModel *model = static_cast<NmMessageListModel*>(msgModelItem->model()); |
83 NmMessageListModel *model = static_cast<NmMessageListModel*>(msgModelItem->model()); |
90 if (model){ |
84 if (model){ |
91 // First set item layout |
85 // First set item layout. |
92 createMessageItemLayout(); |
86 createMessageItemLayout(); |
93 // Set content data to item after layout is created |
87 // Set content data to item after layout is created. |
94 setContentsToMessageItem(msgModelItem->envelope(), model->dividersActive()); |
88 setContentsToMessageItem(msgModelItem->envelope(), model->dividersActive()); |
95 } |
89 } |
96 } |
90 } |
97 HbTreeViewItem::updateChildItems(); |
91 HbTreeViewItem::updateChildItems(); |
98 } |
92 } |
99 |
93 |
100 /*! |
94 /*! |
101 Set item layout. |
95 Set item layout. |
102 Function does not take ownership of model or model item |
96 Function does not take ownership of model or model item. |
103 */ |
97 */ |
104 void NmMessageListViewItem::createMessageItemLayout() |
98 void NmMessageListViewItem::createMessageItemLayout() |
105 { |
99 { |
106 NM_FUNCTION; |
|
107 |
|
108 getFontSizes(); |
100 getFontSizes(); |
109 // Create sender label and set name from widgetml |
101 // Create sender label and set name from widgetml. |
110 if (!mSender){ |
102 if (!mSender) { |
111 mSender = new HbTextItem(this); |
103 mSender = new HbTextItem(this); |
112 HbStyle::setItemName(mSender, "sender"); |
104 HbStyle::setItemName(mSender, "sender"); |
113 mSender->setObjectName("ListViewItemMessageSender"); |
105 mSender->setObjectName("ListViewItemMessageSender"); |
114 mSender->setTextWrapping(Hb::TextNoWrap); |
106 } |
115 } |
107 // Create time label and set name from widgetml. |
116 // Create time label and set name from widgetml |
108 if (!mTime) { |
117 if (!mTime){ |
|
118 mTime = new HbTextItem(this); |
109 mTime = new HbTextItem(this); |
119 HbStyle::setItemName(mTime, "time"); |
110 HbStyle::setItemName(mTime, "time"); |
120 mTime->setObjectName("ListViewItemMessageTime"); |
111 mTime->setObjectName("ListViewItemMessageTime"); |
121 } |
112 } |
122 // Create subject label and set name from widgetml |
113 // Create subject label and set name from widgetml. |
123 if (!mSubject){ |
114 if (!mSubject) { |
124 mSubject = new HbTextItem(this); |
115 mSubject = new HbTextItem(this); |
125 HbStyle::setItemName(mSubject, "subject"); |
116 HbStyle::setItemName(mSubject, "subject"); |
126 mSubject->setObjectName("ListViewItemMessageSubject"); |
117 mSubject->setObjectName("ListViewItemMessageSubject"); |
127 mSubject->setTextWrapping(Hb::TextNoWrap); |
118 } |
128 } |
119 // Set new message icon. |
129 // Set new message icon |
|
130 if (!mNewMsgIcon) { |
120 if (!mNewMsgIcon) { |
131 mNewMsgIcon = new HbFrameItem(this); |
121 mNewMsgIcon = new HbFrameItem(this); |
132 } |
122 } |
133 // Create priority icon and set name from widgetml |
123 // Create priority icon and set name from widgetml. |
134 if (!mIcon1){ |
124 if (!mIcon1) { |
135 mIcon1 = new HbIconItem(this); |
125 mIcon1 = new HbIconItem(this); |
136 HbStyle::setItemName(mIcon1, "icon1"); |
126 HbStyle::setItemName(mIcon1, "icon1"); |
137 // According to layout guide, icon alignment is always right |
127 } |
138 mIcon1->setAlignment(Qt::AlignRight); |
128 // Create attachment icon and set name from widgetml. |
139 } |
129 if (!mIcon2) { |
140 // Create attachment icon and set name from widgetml |
|
141 if (!mIcon2){ |
|
142 mIcon2 = new HbIconItem(this); |
130 mIcon2 = new HbIconItem(this); |
143 HbStyle::setItemName(mIcon2, "icon2"); |
131 HbStyle::setItemName(mIcon2, "icon2"); |
144 // According to layout guide, icon alignment is always right |
|
145 mIcon2->setAlignment(Qt::AlignRight); |
|
146 } |
132 } |
147 setObjectName("ListViewItemMessage"); |
133 setObjectName("ListViewItemMessage"); |
148 } |
134 } |
149 |
135 |
150 /*! |
136 /*! |
151 set item text label contents, icons, etc. |
137 Set item text label contents, icons, etc. |
152 Function does not take ownership of model or model item |
138 Function does not take ownership of model or model item. |
153 */ |
139 */ |
154 void NmMessageListViewItem::setContentsToMessageItem(const NmMessageEnvelope &envelope, |
140 void NmMessageListViewItem::setContentsToMessageItem(const NmMessageEnvelope &envelope, |
155 bool dividersActive) |
141 bool dividersActive) |
156 { |
142 { |
157 NM_FUNCTION; |
143 // Member variables are created in previous function. |
158 |
144 // Sender. |
159 // member variables are created in previous function |
|
160 // sender |
|
161 mSender->setText(senderFieldText(envelope)); |
145 mSender->setText(senderFieldText(envelope)); |
162 // time |
146 // Time. |
163 HbExtendedLocale locale = HbExtendedLocale::system(); |
147 HbExtendedLocale locale = HbExtendedLocale::system(); |
164 QDateTime localTime = envelope.sentTime().addSecs(locale.universalTimeOffset()); |
148 QDateTime localTime = envelope.sentTime().addSecs(locale.universalTimeOffset()); |
165 QDate sentLocalDate = localTime.date(); |
149 QDate sentLocalDate = localTime.date(); |
166 QDate currentdate = QDate::currentDate(); |
150 QDate currentdate = QDate::currentDate(); |
167 if (dividersActive || sentLocalDate == currentdate) { |
151 if (dividersActive || sentLocalDate == currentdate) { |
198 break; |
182 break; |
199 case NmMessagePriorityNormal: |
183 case NmMessagePriorityNormal: |
200 default: |
184 default: |
201 break; |
185 break; |
202 } |
186 } |
203 // attachments |
187 // Attachments. |
204 HbIconItem *attaIcon = (priorityIs ? mIcon2 : mIcon1); |
188 HbIconItem *attaIcon = (priorityIs ? mIcon2 : mIcon1); |
205 if (envelope.hasAttachments()) { |
189 if (envelope.hasAttachments()) { |
206 HbIcon &icon = NmIcons::getIcon(NmIcons::NmIconAttachment); |
190 HbIcon &icon = NmIcons::getIcon(NmIcons::NmIconAttachment); |
207 attaIcon->setIcon(icon); |
191 attaIcon->setIcon(icon); |
208 attaIcon->setObjectName("ListViewItemMessageIconAttachment"); |
192 attaIcon->setObjectName("ListViewItemMessageIconAttachment"); |
209 attaIcon->show(); |
193 attaIcon->show(); |
210 } |
194 } |
211 // message read status |
195 // Message read status. |
212 bool msgReadStatus(envelope.isRead()); |
196 bool msgReadStatus(envelope.isRead()); |
213 HbFrameDrawer *drawer(NULL); |
197 HbFrameDrawer *drawer(NULL); |
214 HbStyle::setItemName(mNewMsgIcon, "msgicon"); |
198 HbStyle::setItemName(mNewMsgIcon, "msgicon"); |
215 if (!msgReadStatus) { |
199 if (!msgReadStatus) { |
216 |
|
217 setFontsUnread(); |
200 setFontsUnread(); |
218 mNewMsgIcon->setObjectName("ListViewItemMessageIconUnread"); |
201 mNewMsgIcon->setObjectName("ListViewItemMessageIconUnread"); |
219 drawer = new HbFrameDrawer("qtg_fr_list_new_item", |
202 drawer = new HbFrameDrawer("qtg_fr_list_new_item", |
220 HbFrameDrawer::ThreePiecesVertical); |
203 HbFrameDrawer::ThreePiecesVertical); |
221 drawer->setFillWholeRect(false); |
204 drawer->setFillWholeRect(false); |
222 // Set drawer. Takes ownership of the drawer and deletes previous drawer. |
205 // Set drawer. Takes ownership of the drawer and deletes previous drawer. |
223 mNewMsgIcon->setFrameDrawer(drawer); |
206 mNewMsgIcon->setFrameDrawer(drawer); |
224 mNewMsgIcon->show(); |
207 mNewMsgIcon->show(); |
225 } else { |
208 } else { |
226 |
|
227 setFontsRead(); |
209 setFontsRead(); |
228 mNewMsgIcon->setObjectName("ListViewItemMessageIconRead"); |
210 mNewMsgIcon->setObjectName("ListViewItemMessageIconRead"); |
229 drawer = new HbFrameDrawer(); // Create empty drawer |
211 drawer = new HbFrameDrawer(); // Create empty drawer. |
230 drawer->setFillWholeRect(false); |
212 drawer->setFillWholeRect(false); |
231 // Set drawer. Takes ownership of the drawer and deletes previous drawer. |
213 // Set drawer. Takes ownership of the drawer and deletes previous drawer. |
232 mNewMsgIcon->setFrameDrawer(drawer); |
214 mNewMsgIcon->setFrameDrawer(drawer); |
233 mNewMsgIcon->hide(); |
215 mNewMsgIcon->hide(); |
234 } |
216 } |
235 } |
217 } |
236 |
218 |
237 /*! |
219 /*! |
238 setFontsUnread |
220 Set fonts unread. |
239 */ |
221 */ |
240 void NmMessageListViewItem::setFontsUnread() |
222 void NmMessageListViewItem::setFontsUnread() |
241 { |
223 { |
242 NM_FUNCTION; |
|
243 |
|
244 static QColor colorRole = HbColorScheme::color("qtc_list_item_title_normal"); |
224 static QColor colorRole = HbColorScheme::color("qtc_list_item_title_normal"); |
245 HbFontSpec fontSpec(HbFontSpec::Primary); |
225 HbFontSpec fontSpec(HbFontSpec::Primary); |
246 setFonts(colorRole, fontSpec); |
226 setFonts(colorRole, fontSpec); |
247 } |
227 } |
248 |
228 |
249 /*! |
229 /*! |
250 setFontsRead |
230 Set fonts read. |
251 */ |
231 */ |
252 void NmMessageListViewItem::setFontsRead() |
232 void NmMessageListViewItem::setFontsRead() |
253 { |
233 { |
254 NM_FUNCTION; |
|
255 |
|
256 static QColor colorRole = HbColorScheme::color("qtc_list_item_content_normal"); |
234 static QColor colorRole = HbColorScheme::color("qtc_list_item_content_normal"); |
257 HbFontSpec fontSpec(HbFontSpec::Secondary); |
235 HbFontSpec fontSpec(HbFontSpec::Secondary); |
258 setFonts(colorRole, fontSpec); |
236 setFonts(colorRole, fontSpec); |
259 } |
237 } |
260 |
238 |
261 /*! |
239 /*! |
262 getFontSizes. |
240 Get font sizes. |
263 */ |
241 */ |
264 void NmMessageListViewItem::getFontSizes() |
242 void NmMessageListViewItem::getFontSizes() |
265 { |
243 { |
266 NM_FUNCTION; |
244 // Get font sizes from style. |
267 |
|
268 // Get font sizes from style |
|
269 qreal currentSize; |
245 qreal currentSize; |
270 bool found = style()->parameter(QString("hb-param-text-height-primary"), currentSize ); |
246 bool found = style()->parameter(QString("hb-param-text-height-primary"), currentSize ); |
271 if (found) { |
247 if (found) { |
272 mPrimarySize = currentSize; |
248 mPrimarySize = currentSize; |
273 } |
249 } |