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