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