|
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 |
|
20 #include <hbiconitem.h> |
|
21 #include <hbtextitem.h> |
|
22 #include <hbframedrawer.h> |
|
23 #include <hbframeitem.h> |
|
24 |
|
25 #define INCOMING_EVENT_FRAME ":/bubble/qtg_fr_convlist_received_normal" |
|
26 #define OUTGOING_EVENT_FRAME ":/bubble/qtg_fr_convlist_sent_normal" |
|
27 |
|
28 CntHistoryViewItemWidget::CntHistoryViewItemWidget(QGraphicsItem *parent) : |
|
29 HbWidget(parent), |
|
30 mIconLabel(0), |
|
31 mTitleLabel(0), |
|
32 mBodyTextLabel(0), |
|
33 mTimeStampLabel(0), |
|
34 mFrameLabel(0) |
|
35 { |
|
36 } |
|
37 |
|
38 CntHistoryViewItemWidget::~CntHistoryViewItemWidget() |
|
39 { |
|
40 } |
|
41 |
|
42 void CntHistoryViewItemWidget::createPrimitives() |
|
43 { |
|
44 //create frame first so it's painted below text labels |
|
45 if (!mFrameLabel) { |
|
46 HbFrameDrawer* frameDrawer = 0; |
|
47 if (mIncoming) { |
|
48 frameDrawer = new HbFrameDrawer(INCOMING_EVENT_FRAME, HbFrameDrawer::NinePieces); |
|
49 } |
|
50 else { |
|
51 frameDrawer = new HbFrameDrawer(OUTGOING_EVENT_FRAME, HbFrameDrawer::NinePieces); |
|
52 } |
|
53 mFrameLabel = new HbFrameItem(frameDrawer, this); |
|
54 style()->setItemName(mFrameLabel, "frame"); |
|
55 } |
|
56 |
|
57 //create icon |
|
58 if (!mIcon.isNull()) { |
|
59 if (!mIconLabel) { |
|
60 mIconLabel = new HbIconItem(this); |
|
61 mIconLabel->setIcon(mIcon); |
|
62 style()->setItemName(mIconLabel, "icon"); |
|
63 } |
|
64 } |
|
65 else { |
|
66 if (mIconLabel) { |
|
67 delete mIconLabel; |
|
68 } |
|
69 mIconLabel = 0; |
|
70 } |
|
71 |
|
72 //create title |
|
73 if (!mTitle.isNull()) { |
|
74 if (!mTitleLabel) { |
|
75 mTitleLabel = new HbTextItem(this); |
|
76 mTitleLabel->setText(mTitle); |
|
77 mTitleLabel->setTextWrapping(Hb::TextWordWrap); |
|
78 style()->setItemName(mTitleLabel, "title"); |
|
79 } |
|
80 } |
|
81 else { |
|
82 if (mTitleLabel) { |
|
83 delete mTitleLabel; |
|
84 } |
|
85 mTitleLabel = 0; |
|
86 } |
|
87 |
|
88 //create body text |
|
89 if (!mBodyText.isNull()) { |
|
90 if (!mBodyTextLabel) { |
|
91 mBodyTextLabel = new HbTextItem(this); |
|
92 mBodyTextLabel->setText(mBodyText); |
|
93 style()->setItemName(mBodyTextLabel, "bodyText"); |
|
94 } |
|
95 } |
|
96 else { |
|
97 if (mBodyTextLabel) { |
|
98 delete mBodyTextLabel; |
|
99 } |
|
100 mBodyTextLabel = 0; |
|
101 } |
|
102 |
|
103 //create timestamp |
|
104 if (!mTimeStamp.isNull()) { |
|
105 if (!mTimeStampLabel) { |
|
106 mTimeStampLabel = new HbTextItem(this); |
|
107 mTimeStampLabel->setText(mTimeStamp); |
|
108 style()->setItemName(mTimeStampLabel, "timeStamp"); |
|
109 } |
|
110 } |
|
111 else { |
|
112 if (mTimeStampLabel) { |
|
113 delete mTimeStampLabel; |
|
114 } |
|
115 mTimeStampLabel = 0; |
|
116 } |
|
117 } |
|
118 |
|
119 void CntHistoryViewItemWidget::recreatePrimitives() |
|
120 { |
|
121 HbWidget::recreatePrimitives(); |
|
122 |
|
123 delete mIconLabel; |
|
124 mIconLabel = 0; |
|
125 |
|
126 delete mTitleLabel; |
|
127 mTitleLabel = 0; |
|
128 |
|
129 delete mBodyTextLabel; |
|
130 mBodyTextLabel = 0; |
|
131 |
|
132 delete mTimeStampLabel; |
|
133 mTimeStampLabel = 0; |
|
134 |
|
135 createPrimitives(); |
|
136 } |
|
137 |
|
138 |
|
139 void CntHistoryViewItemWidget::updatePrimitives() |
|
140 { |
|
141 HbWidget::updatePrimitives(); |
|
142 } |
|
143 |
|
144 void CntHistoryViewItemWidget::setDetails(QString title, QString bodyText, |
|
145 QString timeStamp, QString iconName, bool incoming) |
|
146 { |
|
147 mIcon.clear(); |
|
148 mTitle.clear(); |
|
149 mBodyText.clear(); |
|
150 mTimeStamp.clear(); |
|
151 |
|
152 mIcon.setIconName(iconName); |
|
153 mTitle = title; |
|
154 mBodyText = bodyText; |
|
155 mTimeStamp = timeStamp; |
|
156 mIncoming = incoming; |
|
157 |
|
158 recreatePrimitives(); |
|
159 } |