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>
|
83
|
25 |
#include <QGraphicsSceneMoveEvent>
|
45
|
26 |
|
63
|
27 |
// User includes
|
|
28 |
#include "calendaycommonheaders.h"
|
45
|
29 |
#include "calendayitem.h"
|
|
30 |
#include "calendaystatusstrip.h"
|
|
31 |
#include "calendaymodel.h"
|
55
|
32 |
#include "calendayutils.h"
|
57
|
33 |
#include "calenagendautils.h"
|
55
|
34 |
#include "calendaycontainer.h"
|
45
|
35 |
|
57
|
36 |
/*!
|
63
|
37 |
\brief Constructor.
|
|
38 |
*/
|
|
39 |
CalenDayItem::CalenDayItem(const CalenDayContainer *container) :
|
83
|
40 |
mUpdated(false), mEventDescMinWidth(0.0), mFrameMinWidth(0.0),
|
|
41 |
mBg(0), mEventDesc(0), mColorStripe(0),
|
|
42 |
mContainer(container), mBackgroundType(EStaticBackground)
|
45
|
43 |
{
|
|
44 |
}
|
|
45 |
|
57
|
46 |
/*!
|
63
|
47 |
\brief Constructor.
|
|
48 |
*/
|
45
|
49 |
CalenDayItem::CalenDayItem(const CalenDayItem & source) :
|
83
|
50 |
HbAbstractViewItem(source),
|
|
51 |
mUpdated(false), mEventDescMinWidth(0.0),
|
|
52 |
mFrameMinWidth(0.0), mBg(0), mEventDesc(0),
|
|
53 |
mColorStripe(0), mContainer(source.container()),
|
|
54 |
mBackgroundType(EStaticBackground)
|
57
|
55 |
{
|
83
|
56 |
mBg = new HbFrameItem("qtg_fr_cal_meeting_bg", HbFrameDrawer::NinePieces, this);
|
|
57 |
|
45
|
58 |
mEventDesc = new HbTextItem(this);
|
|
59 |
// TODO: probably ElideLeft needed for mirrored layout
|
|
60 |
mEventDesc->setElideMode(Qt::ElideRight);
|
|
61 |
mEventDesc->setTextWrapping(Hb::TextWrapAnywhere);
|
|
62 |
mColorStripe = new CalenDayStatusStrip(this);
|
63
|
63 |
|
45
|
64 |
HbStyle::setItemName(mBg, QLatin1String("backgroundFrame"));
|
|
65 |
HbStyle::setItemName(mEventDesc, QLatin1String("eventDescription"));
|
63
|
66 |
HbStyle::setItemName(static_cast<QGraphicsItem *> (mColorStripe),
|
|
67 |
QLatin1String("colorStripe"));
|
|
68 |
|
45
|
69 |
HbDeviceProfile deviceProfile;
|
63
|
70 |
qreal stripeWidth = KCalenTimeStripWidth * deviceProfile.unitValue();
|
|
71 |
mColorStripe->setPreferredWidth(stripeWidth);
|
|
72 |
|
|
73 |
// Minimum size of event frame (without/with description)
|
|
74 |
mFrameMinWidth = KCalenMinEventWidth * deviceProfile.unitValue();
|
|
75 |
mEventDescMinWidth = KCalenMinTouchableEventWidth
|
|
76 |
* deviceProfile.unitValue();
|
64
|
77 |
|
63
|
78 |
// Minimum width is assured by widgetml and css, additionally called here
|
|
79 |
// to prevent minimum size hint caching inside effectiveSizeHint
|
45
|
80 |
setMinimumWidth(stripeWidth);
|
83
|
81 |
|
|
82 |
connect(this, SIGNAL(backgroundTypeChanged(const CalenDayItem*)), mContainer, SLOT(updateFloatingItemsList(const CalenDayItem*)));
|
45
|
83 |
}
|
|
84 |
|
57
|
85 |
/*!
|
63
|
86 |
\brief Destructor.
|
|
87 |
*/
|
45
|
88 |
CalenDayItem::~CalenDayItem()
|
|
89 |
{
|
|
90 |
}
|
|
91 |
|
57
|
92 |
/*!
|
63
|
93 |
\brief Creates new instance of day item.
|
|
94 |
|
|
95 |
\return New instance of day item.
|
|
96 |
*/
|
45
|
97 |
HbAbstractViewItem * CalenDayItem::createItem()
|
|
98 |
{
|
|
99 |
CalenDayItem* newItem = new CalenDayItem(*this);
|
|
100 |
return newItem;
|
|
101 |
}
|
|
102 |
|
|
103 |
|
57
|
104 |
/*!
|
63
|
105 |
\brief Sets data to be displayed on item.
|
|
106 |
*/
|
45
|
107 |
void CalenDayItem::updateChildItems()
|
|
108 |
{
|
57
|
109 |
// there is no need to update items after creation
|
|
110 |
if (!mUpdated) {
|
|
111 |
AgendaEntry entry;
|
63
|
112 |
entry = modelIndex().data(CalenDayEntry).value<AgendaEntry> ();
|
57
|
113 |
|
63
|
114 |
bool isAllDayEvent = CalenAgendaUtils::isAlldayEvent(entry);
|
57
|
115 |
setDescription(entry, isAllDayEvent);
|
|
116 |
setStatusStrip(entry, isAllDayEvent);
|
|
117 |
|
|
118 |
mUpdated = true;
|
|
119 |
}
|
45
|
120 |
}
|
|
121 |
|
|
122 |
|
57
|
123 |
/*!
|
63
|
124 |
\brief Adds event description for the item.
|
|
125 |
|
|
126 |
\param entry An for which description needs to be displayed.
|
|
127 |
\param allDayEvent Flag that indicates whether an item is all day event
|
|
128 |
*/
|
45
|
129 |
void CalenDayItem::setDescription(const AgendaEntry &entry, bool allDayEvent)
|
|
130 |
{
|
63
|
131 |
QString description(entry.summary());
|
|
132 |
QString location(entry.location());
|
|
133 |
|
|
134 |
int separtorPos = 0;
|
|
135 |
if (!location.isEmpty()) {
|
|
136 |
if (!description.isEmpty()) {
|
|
137 |
separtorPos = description.count();
|
|
138 |
description.append(", ");
|
|
139 |
}
|
|
140 |
description.append(location);
|
|
141 |
}
|
|
142 |
|
|
143 |
if (description.isEmpty()) {
|
|
144 |
description.append(hbTrId("txt_calendar_dblist_unnamed"));
|
|
145 |
}
|
45
|
146 |
|
63
|
147 |
//Description of all day events has to be displayed vertically
|
|
148 |
if (allDayEvent) {
|
|
149 |
QString verticalString;
|
|
150 |
for (int i = 0; i < description.count(); i++) {
|
|
151 |
verticalString.append(QString(description.at(i)) + "\n");
|
|
152 |
}
|
|
153 |
|
|
154 |
// remove "\n" before comma separator if exist
|
|
155 |
if (separtorPos) {
|
|
156 |
verticalString.remove(2 * separtorPos - 1, 1);
|
|
157 |
}
|
|
158 |
description = verticalString;
|
|
159 |
}
|
|
160 |
|
|
161 |
mEventDesc->setText(description);
|
45
|
162 |
}
|
|
163 |
|
|
164 |
/*!
|
63
|
165 |
\brief It set all needed things for status strip from Agenda Entry.
|
|
166 |
|
|
167 |
\param entry Status Strip is created from Agenda Entry
|
|
168 |
*/
|
45
|
169 |
void CalenDayItem::setStatusStrip(const AgendaEntry &entry, bool allDayEvent)
|
|
170 |
{
|
|
171 |
if (!allDayEvent) {
|
55
|
172 |
|
|
173 |
QDateTime startTime;
|
|
174 |
QDateTime endTime;
|
|
175 |
QDateTime currentDateTime;
|
|
176 |
currentDateTime.setDate(container()->date());
|
|
177 |
|
63
|
178 |
CalenDayUtils::instance()->getEventValidStartEndTime(startTime,
|
|
179 |
endTime, entry, currentDateTime);
|
55
|
180 |
|
|
181 |
mColorStripe->setStartEndTime(startTime.time(), endTime.time());
|
|
182 |
}
|
|
183 |
else {
|
|
184 |
// This is workaround for displaying all-day events.
|
|
185 |
// Now for MS Outlook compability all-day events' start and end time is
|
|
186 |
// 00:00:00 and 00:00:00 next day respectively.
|
|
187 |
// To draw it correctly we need times like those visible for user in
|
|
188 |
// editor: 00:00:00 to 23:59:59 (the same day)
|
63
|
189 |
mColorStripe->setStartEndTime(entry.startTime().time(),
|
|
190 |
entry.endTime().time().addSecs(-1));
|
45
|
191 |
}
|
63
|
192 |
|
45
|
193 |
switch (entry.status()) {
|
|
194 |
case AgendaEntry::Confirmed:
|
|
195 |
mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
|
63
|
196 |
break;
|
45
|
197 |
case AgendaEntry::Tentative:
|
|
198 |
mColorStripe->setDrawingStyle(CalenDayStatusStrip::StripWithLines);
|
63
|
199 |
break;
|
45
|
200 |
case AgendaEntry::Cancelled:
|
|
201 |
mColorStripe->setDrawingStyle(CalenDayStatusStrip::OnlyFrame);
|
63
|
202 |
break;
|
45
|
203 |
default:
|
|
204 |
mColorStripe->setDrawingStyle(CalenDayStatusStrip::Filled);
|
63
|
205 |
break;
|
45
|
206 |
}
|
|
207 |
}
|
|
208 |
|
57
|
209 |
/*!
|
63
|
210 |
\brief Reimplemented from HbWidget. Handles resize event.
|
|
211 |
|
|
212 |
\param event Instance of an event to be handled.
|
|
213 |
*/
|
45
|
214 |
void CalenDayItem::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
215 |
{
|
|
216 |
Q_UNUSED(event)
|
|
217 |
|
|
218 |
qreal width = rect().width();
|
83
|
219 |
qreal height = rect().height();
|
|
220 |
|
|
221 |
//Backround height can't be bigger the screen. If event is long enough
|
|
222 |
//backround will start to float together with view content.
|
|
223 |
mBg->setMaximumHeight(CalenDayUtils::instance()->screenHeight());
|
45
|
224 |
|
64
|
225 |
HbDeviceProfile deviceProfile;
|
63
|
226 |
if (width < mEventDescMinWidth) {
|
64
|
227 |
mColorStripe->setPreferredWidth(KCalenMinTimeStripWidth
|
|
228 |
* deviceProfile.unitValue());
|
83
|
229 |
mBg->setMaximumWidth(KCalenMinEventWidth
|
|
230 |
* deviceProfile.unitValue());
|
45
|
231 |
mEventDesc->hide();
|
63
|
232 |
}
|
|
233 |
else {
|
64
|
234 |
mColorStripe->setPreferredWidth(KCalenTimeStripWidth
|
|
235 |
* deviceProfile.unitValue());
|
83
|
236 |
mBg->setMaximumWidth(CalenDayUtils::instance()->screenWidth());
|
45
|
237 |
mEventDesc->show();
|
|
238 |
}
|
63
|
239 |
|
|
240 |
if (width < mFrameMinWidth) {
|
45
|
241 |
mBg->hide();
|
63
|
242 |
}
|
|
243 |
else {
|
45
|
244 |
mBg->show();
|
|
245 |
}
|
83
|
246 |
|
|
247 |
//If following condition is fulfilled then background item needs to be
|
|
248 |
//switched to floating one.
|
|
249 |
if (height > CalenDayUtils::instance()->screenHeight()) {
|
|
250 |
|
|
251 |
//If background item is floating then it needs to be removed from
|
|
252 |
//layout (see css & widgetml). In this case we need to take care of setting its
|
|
253 |
//geometry by ourselves.
|
|
254 |
QRectF newRect = rect();
|
|
255 |
qreal baseY = pos().y();
|
|
256 |
qreal mappedY = mapFromScene(pos()).y();
|
|
257 |
qreal normalizedY = mappedY - baseY; //aligns background to the top of viewport
|
|
258 |
//Check whether background won't go out of the event's rectangle
|
|
259 |
if(normalizedY < newRect.top()){
|
|
260 |
normalizedY = newRect.top();
|
|
261 |
}
|
|
262 |
newRect.setY(normalizedY);
|
|
263 |
mBg->setGeometry(newRect);
|
|
264 |
|
|
265 |
//Notify the container about background type change.
|
|
266 |
//From now on this object is going to receive information
|
|
267 |
//about scrolling.
|
|
268 |
if (mBackgroundType == EStaticBackground) {
|
|
269 |
mBackgroundType = EFloatingBackground;
|
|
270 |
emit backgroundTypeChanged(this);
|
|
271 |
}
|
|
272 |
}else if (mBackgroundType == EFloatingBackground) {
|
|
273 |
mBackgroundType = EStaticBackground;
|
|
274 |
emit backgroundTypeChanged(this);
|
|
275 |
}
|
45
|
276 |
|
63
|
277 |
// Necessary to switch layout
|
45
|
278 |
repolish();
|
|
279 |
}
|
|
280 |
|
83
|
281 |
/*!
|
|
282 |
\brief This slot is triggered when backround type is set as EFloatingBackground.
|
|
283 |
It allows to scroll backround along with view content.
|
|
284 |
|
|
285 |
\param pos Positoin to which backround needs to be scrolled.
|
|
286 |
*/
|
|
287 |
void CalenDayItem::scrollBackground(const QPointF &pos)
|
|
288 |
{
|
|
289 |
qreal newY = mapFromParent(pos).y();
|
|
290 |
//margin to ensure that rounded corners will stay hidden
|
|
291 |
const qreal margin = 5.0;
|
|
292 |
|
|
293 |
if (newY > rect().top() && newY + mBg->rect().height() < rect().bottom()) {
|
|
294 |
|
|
295 |
mBg->setY(newY - margin);
|
|
296 |
}
|
|
297 |
else if (newY < rect().top()) { //condition for top boundary
|
|
298 |
|
|
299 |
mBg->setY(rect().top());
|
|
300 |
|
|
301 |
}else if (newY + mBg->rect().height() > rect().bottom()) { //condition for bottom boundary
|
|
302 |
|
|
303 |
mBg->setY(rect().bottom() - mBg->rect().height());
|
|
304 |
}
|
|
305 |
}
|
|
306 |
|
45
|
307 |
// End of File
|