|
1 /* |
|
2 * Copyright (c) 2010 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: Event view item, exact size and position of event is set in |
|
15 * CalenDayContainer::setItemModelIndex based on event duration |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <HbFrameItem> |
|
21 #include <HbTextItem> |
|
22 #include <HbStyle> |
|
23 #include <HbColorScheme> |
|
24 #include <agendaentry.h> |
|
25 |
|
26 // User includes |
|
27 #include "calendaycommonheaders.h" |
|
28 #include "calendayitem.h" |
|
29 #include "calendaystatusstrip.h" |
|
30 #include "calendaymodel.h" |
|
31 #include "calendayutils.h" |
|
32 #include "calenagendautils.h" |
|
33 #include "calendaycontainer.h" |
|
34 |
|
35 /*! |
|
36 \brief Constructor. |
|
37 */ |
|
38 CalenDayItem::CalenDayItem(const CalenDayContainer *container) : |
|
39 mContainer(container), mUpdated(false), mBg(0), mEventDesc(0), |
|
40 mColorStripe(0), mEventDescMinWidth(0.0), mFrameMinWidth(0.0) |
|
41 { |
|
42 } |
|
43 |
|
44 /*! |
|
45 \brief Constructor. |
|
46 */ |
|
47 CalenDayItem::CalenDayItem(const CalenDayItem & source) : |
|
48 HbAbstractViewItem(source), mContainer(source.container()), |
|
49 mUpdated(false), mBg(0), mEventDesc(0), mColorStripe(0), |
|
50 mEventDescMinWidth(0.0), mFrameMinWidth(0.0) |
|
51 { |
|
52 mBg = new HbFrameItem("qtg_fr_cal_meeting_bg", HbFrameDrawer::NinePieces, |
|
53 this); |
|
54 mEventDesc = new HbTextItem(this); |
|
55 // TODO: probably ElideLeft needed for mirrored layout |
|
56 mEventDesc->setElideMode(Qt::ElideRight); |
|
57 mEventDesc->setTextWrapping(Hb::TextWrapAnywhere); |
|
58 mColorStripe = new CalenDayStatusStrip(this); |
|
59 |
|
60 HbStyle::setItemName(mBg, QLatin1String("backgroundFrame")); |
|
61 HbStyle::setItemName(mEventDesc, QLatin1String("eventDescription")); |
|
62 HbStyle::setItemName(static_cast<QGraphicsItem *> (mColorStripe), |
|
63 QLatin1String("colorStripe")); |
|
64 |
|
65 HbDeviceProfile deviceProfile; |
|
66 qreal stripeWidth = KCalenTimeStripWidth * deviceProfile.unitValue(); |
|
67 mColorStripe->setPreferredWidth(stripeWidth); |
|
68 |
|
69 // Minimum size of event frame (without/with description) |
|
70 mFrameMinWidth = KCalenMinEventWidth * deviceProfile.unitValue(); |
|
71 mEventDescMinWidth = KCalenMinTouchableEventWidth |
|
72 * deviceProfile.unitValue(); |
|
73 |
|
74 // Minimum width is assured by widgetml and css, additionally called here |
|
75 // to prevent minimum size hint caching inside effectiveSizeHint |
|
76 setMinimumWidth(stripeWidth); |
|
77 } |
|
78 |
|
79 /*! |
|
80 \brief Destructor. |
|
81 */ |
|
82 CalenDayItem::~CalenDayItem() |
|
83 { |
|
84 } |
|
85 |
|
86 /*! |
|
87 \brief Creates new instance of day item. |
|
88 |
|
89 \return New instance of day item. |
|
90 */ |
|
91 HbAbstractViewItem * CalenDayItem::createItem() |
|
92 { |
|
93 CalenDayItem* newItem = new CalenDayItem(*this); |
|
94 return newItem; |
|
95 } |
|
96 |
|
97 |
|
98 /*! |
|
99 \brief Sets data to be displayed on item. |
|
100 */ |
|
101 void CalenDayItem::updateChildItems() |
|
102 { |
|
103 // there is no need to update items after creation |
|
104 if (!mUpdated) { |
|
105 AgendaEntry entry; |
|
106 entry = modelIndex().data(CalenDayEntry).value<AgendaEntry> (); |
|
107 |
|
108 bool isAllDayEvent = CalenAgendaUtils::isAlldayEvent(entry); |
|
109 setDescription(entry, isAllDayEvent); |
|
110 setStatusStrip(entry, isAllDayEvent); |
|
111 |
|
112 mUpdated = true; |
|
113 } |
|
114 } |
|
115 |
|
116 |
|
117 /*! |
|
118 \brief Adds event description for the item. |
|
119 |
|
120 \param entry An for which description needs to be displayed. |
|
121 \param allDayEvent Flag that indicates whether an item is all day event |
|
122 */ |
|
123 void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent) |
|
124 { |
|
125 QString description(entry.summary()); |
|
126 QString location(entry.location()); |
|
127 |
|
128 int separtorPos = 0; |
|
129 if (!location.isEmpty()) { |
|
130 if (!description.isEmpty()) { |
|
131 separtorPos = description.count(); |
|
132 description.append(", "); |
|
133 } |
|
134 description.append(location); |
|
135 } |
|
136 |
|
137 if (description.isEmpty()) { |
|
138 description.append(hbTrId("txt_calendar_dblist_unnamed")); |
|
139 } |
|
140 |
|
141 //Description of all day events has to be displayed vertically |
|
142 if (allDayEvent) { |
|
143 QString verticalString; |
|
144 for (int i = 0; i < description.count(); i++) { |
|
145 verticalString.append(QString(description.at(i)) + "\n"); |
|
146 } |
|
147 |
|
148 // remove "\n" before comma separator if exist |
|
149 if (separtorPos) { |
|
150 verticalString.remove(2 * separtorPos - 1, 1); |
|
151 } |
|
152 description = verticalString; |
|
153 } |
|
154 |
|
155 mEventDesc->setText(description); |
|
156 } |
|
157 |
|
158 /*! |
|
159 \brief It set all needed things for status strip from Agenda Entry. |
|
160 |
|
161 \param entry Status Strip is created from Agenda Entry |
|
162 */ |
|
163 void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent) |
|
164 { |
|
165 if (!allDayEvent) { |
|
166 |
|
167 QDateTime startTime; |
|
168 QDateTime endTime; |
|
169 QDateTime currentDateTime; |
|
170 currentDateTime.setDate(container()->date()); |
|
171 |
|
172 CalenDayUtils::instance()->getEventValidStartEndTime(startTime, |
|
173 endTime, entry, currentDateTime); |
|
174 |
|
175 mColorStripe->setStartEndTime(startTime.time(), endTime.time()); |
|
176 } |
|
177 else { |
|
178 // This is workaround for displaying all-day events. |
|
179 // Now for MS Outlook compability all-day events' start and end time is |
|
180 // 00:00:00 and 00:00:00 next day respectively. |
|
181 // To draw it correctly we need times like those visible for user in |
|
182 // editor: 00:00:00 to 23:59:59 (the same day) |
|
183 mColorStripe->setStartEndTime(entry.startTime().time(), |
|
184 entry.endTime().time().addSecs(-1)); |
|
185 } |
|
186 |
|
187 switch (entry.status()) { |
|
188 case AgendaEntry::Confirmed: |
|
189 mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); |
|
190 break; |
|
191 case AgendaEntry::Tentative: |
|
192 mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines); |
|
193 break; |
|
194 case AgendaEntry::Cancelled: |
|
195 mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame); |
|
196 break; |
|
197 default: |
|
198 mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled); |
|
199 break; |
|
200 } |
|
201 } |
|
202 |
|
203 /*! |
|
204 \brief Reimplemented from HbWidget. Handles resize event. |
|
205 |
|
206 \param event Instance of an event to be handled. |
|
207 */ |
|
208 void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
209 { |
|
210 Q_UNUSED(event) |
|
211 |
|
212 qreal width = rect().width(); |
|
213 |
|
214 HbDeviceProfile deviceProfile; |
|
215 if (width < mEventDescMinWidth) { |
|
216 mColorStripe->setPreferredWidth(KCalenMinTimeStripWidth |
|
217 * deviceProfile.unitValue()); |
|
218 mEventDesc->hide(); |
|
219 } |
|
220 else { |
|
221 mColorStripe->setPreferredWidth(KCalenTimeStripWidth |
|
222 * deviceProfile.unitValue()); |
|
223 mEventDesc->show(); |
|
224 } |
|
225 |
|
226 if (width < mFrameMinWidth) { |
|
227 mBg->hide(); |
|
228 } |
|
229 else { |
|
230 mBg->show(); |
|
231 } |
|
232 |
|
233 // Necessary to switch layout |
|
234 repolish(); |
|
235 } |
|
236 |
|
237 // End of File |