81
|
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 "cnthistoryviewitemwidget.h"
|
|
19 |
#include "cntdebug.h"
|
|
20 |
|
|
21 |
#include <cnthistorymodel.h>
|
|
22 |
#include <hbiconitem.h>
|
|
23 |
#include <hbtextitem.h>
|
|
24 |
#include <hbframedrawer.h>
|
|
25 |
#include <hbframeitem.h>
|
|
26 |
|
|
27 |
#define NEW_EVENT_FRAME "qtg_fr_list_new_item"
|
|
28 |
#define INCOMING_FOCUS_FRAME "qtg_fr_convlist_received_pressed"
|
|
29 |
#define OUTGOING_FOCUS_FRAME "qtg_fr_convlist_sent_pressed"
|
|
30 |
|
|
31 |
CntHistoryViewItemWidget::CntHistoryViewItemWidget(QGraphicsItem *parent) :
|
|
32 |
HbWidget(parent),
|
|
33 |
mIcon(NULL),
|
|
34 |
mTitle(NULL),
|
|
35 |
mBodyText(NULL),
|
|
36 |
mTimeStamp(NULL),
|
|
37 |
mFrameItem(NULL),
|
|
38 |
mFocusItem(NULL),
|
|
39 |
mNewItem(NULL),
|
|
40 |
incoming(false),
|
|
41 |
newmessage(false)
|
|
42 |
{
|
|
43 |
CNT_ENTRY
|
|
44 |
|
|
45 |
setProperty("state", "normal");
|
|
46 |
|
|
47 |
CNT_EXIT
|
|
48 |
}
|
|
49 |
|
|
50 |
CntHistoryViewItemWidget::~CntHistoryViewItemWidget()
|
|
51 |
{
|
|
52 |
CNT_ENTRY
|
|
53 |
|
|
54 |
CNT_EXIT
|
|
55 |
}
|
|
56 |
|
|
57 |
void CntHistoryViewItemWidget::createPrimitives()
|
|
58 |
{
|
|
59 |
CNT_ENTRY
|
|
60 |
|
|
61 |
if (!icon.isNull())
|
|
62 |
{
|
|
63 |
if (!mIcon)
|
|
64 |
{
|
|
65 |
mIcon = new HbIconItem(this);
|
|
66 |
mIcon->setAlignment(Qt::AlignCenter);
|
|
67 |
mIcon->setIcon(icon);
|
|
68 |
style()->setItemName(mIcon, "icon-1");
|
|
69 |
}
|
|
70 |
}
|
|
71 |
else
|
|
72 |
{
|
|
73 |
if (mIcon)
|
|
74 |
{
|
|
75 |
delete mIcon;
|
|
76 |
}
|
|
77 |
mIcon = NULL;
|
|
78 |
}
|
|
79 |
|
|
80 |
if (!title.isNull())
|
|
81 |
{
|
|
82 |
if (!mTitle)
|
|
83 |
{
|
|
84 |
mTitle = new HbTextItem(this);
|
|
85 |
mTitle->setText(title);
|
|
86 |
style()->setItemName(mTitle, "text-1");
|
|
87 |
}
|
|
88 |
}
|
|
89 |
else
|
|
90 |
{
|
|
91 |
if (mTitle)
|
|
92 |
{
|
|
93 |
delete mTitle;
|
|
94 |
}
|
|
95 |
mTitle = NULL;
|
|
96 |
}
|
|
97 |
|
|
98 |
if (!bodyText.isNull())
|
|
99 |
{
|
|
100 |
if (!mBodyText)
|
|
101 |
{
|
|
102 |
mBodyText = new HbTextItem(this);
|
|
103 |
mBodyText->setText(bodyText);
|
|
104 |
style()->setItemName(mBodyText, "text-2");
|
|
105 |
}
|
|
106 |
}
|
|
107 |
else
|
|
108 |
{
|
|
109 |
if (mBodyText)
|
|
110 |
{
|
|
111 |
delete mBodyText;
|
|
112 |
}
|
|
113 |
mBodyText = NULL;
|
|
114 |
}
|
|
115 |
|
|
116 |
if (!timeStamp.isNull())
|
|
117 |
{
|
|
118 |
if (!mTimeStamp)
|
|
119 |
{
|
|
120 |
mTimeStamp = new HbTextItem(this);
|
|
121 |
mTimeStamp->setText(timeStamp);
|
|
122 |
style()->setItemName(mTimeStamp, "text-3");
|
|
123 |
}
|
|
124 |
}
|
|
125 |
else
|
|
126 |
{
|
|
127 |
if (mTimeStamp)
|
|
128 |
{
|
|
129 |
delete mTimeStamp;
|
|
130 |
}
|
|
131 |
mTimeStamp = NULL;
|
|
132 |
}
|
|
133 |
|
|
134 |
if (!mFrameItem)
|
|
135 |
{
|
|
136 |
mFrameItem = new HbFrameItem(this);
|
|
137 |
mFrameItem->frameDrawer().setFrameGraphicsName(backGround.frameGraphicsName());
|
|
138 |
mFrameItem->frameDrawer().setFrameType(backGround.frameType());
|
|
139 |
mFrameItem->setZValue(-2);
|
|
140 |
style()->setItemName(mFrameItem, "frame");
|
|
141 |
}
|
|
142 |
|
|
143 |
CNT_EXIT
|
|
144 |
}
|
|
145 |
|
|
146 |
void CntHistoryViewItemWidget::recreatePrimitives()
|
|
147 |
{
|
|
148 |
CNT_ENTRY
|
|
149 |
|
|
150 |
HbWidget::recreatePrimitives();
|
|
151 |
|
|
152 |
delete mIcon;
|
|
153 |
mIcon = NULL;
|
|
154 |
|
|
155 |
delete mTitle;
|
|
156 |
mTitle = NULL;
|
|
157 |
|
|
158 |
delete mBodyText;
|
|
159 |
mBodyText = NULL;
|
|
160 |
|
|
161 |
delete mTimeStamp;
|
|
162 |
mTimeStamp= NULL;
|
|
163 |
|
|
164 |
delete mFrameItem;
|
|
165 |
mFrameItem = NULL;
|
|
166 |
|
|
167 |
createPrimitives();
|
|
168 |
|
|
169 |
CNT_EXIT
|
|
170 |
}
|
|
171 |
|
|
172 |
void CntHistoryViewItemWidget::setModelIndex(const QModelIndex& index)
|
|
173 |
{
|
|
174 |
CNT_ENTRY
|
|
175 |
|
|
176 |
// CntHistoryModel ALWAYS returns 3x QString for Qt::DisplayRole
|
|
177 |
QStringList texts = index.data(Qt::DisplayRole).toStringList();
|
|
178 |
title = texts.at(0);
|
|
179 |
bodyText = texts.at(1);
|
|
180 |
timeStamp = texts.at(2);
|
|
181 |
|
|
182 |
icon = index.data(Qt::DecorationRole).value<HbIcon>();
|
|
183 |
|
|
184 |
backGround = index.data(Qt::BackgroundRole).value<HbFrameBackground>();
|
|
185 |
|
|
186 |
int flags = index.data(CntFlagsRole).toInt();
|
|
187 |
incoming = flags & CntIncoming ? true : false;
|
|
188 |
newmessage = flags & CntUnseen ? true : false;
|
|
189 |
|
|
190 |
if (newmessage)
|
|
191 |
{
|
|
192 |
if (!mNewItem)
|
|
193 |
{
|
|
194 |
mNewItem = new HbFrameItem(NEW_EVENT_FRAME, HbFrameDrawer::ThreePiecesVertical, this);
|
|
195 |
style()->setItemName(mNewItem, "newitem");
|
|
196 |
}
|
|
197 |
}
|
|
198 |
else
|
|
199 |
{
|
|
200 |
if (mNewItem)
|
|
201 |
{
|
|
202 |
delete mNewItem;
|
|
203 |
mNewItem = NULL;
|
|
204 |
}
|
|
205 |
}
|
|
206 |
|
|
207 |
recreatePrimitives();
|
|
208 |
repolish();
|
|
209 |
|
|
210 |
setProperty("state", "normal");
|
|
211 |
|
|
212 |
CNT_EXIT
|
|
213 |
}
|
|
214 |
|
|
215 |
void CntHistoryViewItemWidget::pressStateChanged(bool pressed)
|
|
216 |
{
|
|
217 |
CNT_ENTRY
|
|
218 |
|
|
219 |
if (pressed)
|
|
220 |
{
|
|
221 |
if (!mFocusItem)
|
|
222 |
{
|
|
223 |
if (incoming)
|
|
224 |
{
|
|
225 |
mFocusItem = new HbFrameItem(INCOMING_FOCUS_FRAME, HbFrameDrawer::NinePieces, this);
|
|
226 |
}
|
|
227 |
else
|
|
228 |
{
|
|
229 |
mFocusItem = new HbFrameItem(OUTGOING_FOCUS_FRAME, HbFrameDrawer::NinePieces, this);
|
|
230 |
}
|
|
231 |
mFocusItem->setZValue(-1.0);
|
|
232 |
style()->setItemName(mFocusItem, "focusframe");
|
|
233 |
}
|
|
234 |
|
|
235 |
setProperty("state", "pressed");
|
|
236 |
}
|
|
237 |
else
|
|
238 |
{
|
|
239 |
if (mFocusItem)
|
|
240 |
{
|
|
241 |
delete mFocusItem;
|
|
242 |
mFocusItem = NULL;
|
|
243 |
}
|
|
244 |
|
|
245 |
setProperty("state", "normal");
|
|
246 |
}
|
|
247 |
|
|
248 |
repolish();
|
|
249 |
|
|
250 |
CNT_EXIT
|
|
251 |
}
|