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: Day view control of calendar
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
63
|
18 |
// System includes
|
45
|
19 |
#include <QPainter>
|
|
20 |
#include <QPen>
|
63
|
21 |
#include <HbColorScheme>
|
45
|
22 |
|
63
|
23 |
// User includes
|
45
|
24 |
#include "calendaystatusstrip.h"
|
|
25 |
|
63
|
26 |
// Constants
|
45
|
27 |
qreal const CalenDayStatusStrip::mMinute = 60;
|
|
28 |
qreal const CalenDayStatusStrip::mMinimumTime = 5;
|
|
29 |
|
|
30 |
/*!
|
|
31 |
Constructor
|
|
32 |
*/
|
|
33 |
CalenDayStatusStrip::CalenDayStatusStrip(HbWidget *parent)
|
|
34 |
: HbWidget(parent), mRange(2),
|
63
|
35 |
mDrawingStyle(CalenDayStatusStrip::Filled)
|
45
|
36 |
{
|
|
37 |
setFlag(QGraphicsItem::ItemHasNoContents,false);
|
|
38 |
|
|
39 |
}
|
|
40 |
|
|
41 |
/*!
|
|
42 |
Destructor
|
|
43 |
*/
|
|
44 |
CalenDayStatusStrip::~CalenDayStatusStrip()
|
|
45 |
{
|
|
46 |
|
|
47 |
}
|
|
48 |
|
|
49 |
/*!
|
57
|
50 |
\brief Returns range between two filled lines in StripWithLines drawing
|
45
|
51 |
styles.
|
|
52 |
|
|
53 |
\sa CalenDayStatusStrip::DrawingStyle, setRange
|
|
54 |
*/
|
|
55 |
qreal CalenDayStatusStrip::range() const
|
|
56 |
{
|
|
57 |
return mRange;
|
|
58 |
}
|
|
59 |
|
|
60 |
/*!
|
57
|
61 |
\brief Returns style of drawing.
|
45
|
62 |
|
|
63 |
\sa CalenDayStatusStrip::DrawingStyle, setDrawingStyle
|
|
64 |
*/
|
|
65 |
CalenDayStatusStrip::DrawingStyle CalenDayStatusStrip::drawingStyle() const
|
|
66 |
{
|
|
67 |
return mDrawingStyle;
|
|
68 |
}
|
|
69 |
|
|
70 |
/*!
|
57
|
71 |
\brief Returns original start and entime fo event
|
45
|
72 |
|
|
73 |
\sa setStartEndTime
|
|
74 |
*/
|
|
75 |
QPair<QTime,QTime> CalenDayStatusStrip::startEndTime() const
|
|
76 |
{
|
|
77 |
return mStartEndEventTime;
|
|
78 |
}
|
|
79 |
|
|
80 |
/*!
|
57
|
81 |
\brief It sets range between two filled lines in StripWithLines drawing
|
45
|
82 |
styles.
|
|
83 |
|
57
|
84 |
\param range Range between two filled lines
|
45
|
85 |
|
|
86 |
\sa CalenDayStatusStrip::DrawingStyle, range
|
|
87 |
*/
|
|
88 |
void CalenDayStatusStrip::setRange(qreal range)
|
|
89 |
{
|
|
90 |
mRange = range;
|
|
91 |
}
|
|
92 |
|
|
93 |
/*!
|
57
|
94 |
\brief It sets drawing style of strip
|
45
|
95 |
|
|
96 |
\param drawingStyle Style of strip drawing.
|
|
97 |
|
|
98 |
\sa CalenDayStatusStrip::DrawingStyle, drawingStyle
|
|
99 |
*/
|
|
100 |
void
|
|
101 |
CalenDayStatusStrip::setDrawingStyle(CalenDayStatusStrip::DrawingStyle drawingStyle)
|
|
102 |
{
|
|
103 |
mDrawingStyle = drawingStyle;
|
|
104 |
}
|
|
105 |
|
|
106 |
/*!
|
57
|
107 |
It sets start and end time of event
|
45
|
108 |
|
|
109 |
\param startTime Start of event
|
|
110 |
\param endTime End of event
|
|
111 |
*/
|
|
112 |
void CalenDayStatusStrip::setStartEndTime(const QTime &startTime,
|
|
113 |
const QTime &endTime)
|
|
114 |
{
|
|
115 |
mStartEndEventTime.first = startTime;
|
|
116 |
mStartEndEventTime.second = endTime;
|
|
117 |
|
|
118 |
//check if startEndEvent is longer than mMinimumTimeminutes;
|
|
119 |
if (mStartEndEventTime.first.secsTo(mStartEndEventTime.second) < mMinute * mMinimumTime) {
|
|
120 |
mStartEndEventTime.second = QTime(mStartEndEventTime.first.hour(),
|
|
121 |
mStartEndEventTime.first.minute() + mMinimumTime);
|
|
122 |
}
|
|
123 |
}
|
|
124 |
|
|
125 |
/*!
|
|
126 |
\brief Reimplemented function...
|
|
127 |
|
|
128 |
Reimplemented function to draw status strip.
|
|
129 |
It is based on CalenDayStatusStrip::DrawingStyle, range and color
|
|
130 |
*/
|
|
131 |
void CalenDayStatusStrip::paint(
|
|
132 |
QPainter *painter,
|
|
133 |
const QStyleOptionGraphicsItem *option,
|
|
134 |
QWidget *widget)
|
|
135 |
{
|
|
136 |
Q_UNUSED(option);
|
|
137 |
Q_UNUSED(widget);
|
|
138 |
|
|
139 |
//calculate bubble start and end time of bubble
|
|
140 |
QPair<QTime, QTime> startEndEvent =
|
|
141 |
calculateStartEndPostion(mStartEndEventTime.first,
|
|
142 |
mStartEndEventTime.second
|
|
143 |
);
|
|
144 |
//calculate how big is Minute
|
|
145 |
qreal minuteHeight = calculateMinuteHeight(startEndEvent.first,
|
|
146 |
startEndEvent.second
|
|
147 |
);
|
|
148 |
|
|
149 |
painter->save();// saves the painter state.
|
|
150 |
|
|
151 |
|
|
152 |
//calculate how long is event in minutes
|
|
153 |
qreal eventMinutes =
|
|
154 |
mStartEndEventTime.first.secsTo(mStartEndEventTime.second) / mMinute;
|
|
155 |
//calculate height and width of status stripe
|
|
156 |
qreal dx = size().width() - 1;
|
|
157 |
qreal dy = eventMinutes * minuteHeight;
|
|
158 |
|
|
159 |
//calculate time from wehre it should be drawed
|
|
160 |
qreal startTime =
|
|
161 |
startEndEvent.first.secsTo(mStartEndEventTime.first) / mMinute;
|
|
162 |
//this is done because bubble can be drawed from half hour
|
|
163 |
startTime = startTime > 30 ? startTime - 30 : startTime;
|
|
164 |
//calculate status stripe height
|
|
165 |
qreal startTimeHeight = startTime * minuteHeight;
|
|
166 |
|
|
167 |
//set bounding rect of drawed area
|
|
168 |
QRectF bounding(boundingRect());
|
|
169 |
//set size smaller by 1px in each side
|
|
170 |
bounding.setRect(bounding.left() + 1, bounding.top() + startTimeHeight,
|
|
171 |
dx - 1, dy - 1
|
|
172 |
);
|
|
173 |
|
|
174 |
//set clip region
|
|
175 |
painter->setClipRect(bounding, Qt::IntersectClip);
|
|
176 |
|
|
177 |
//prepare brush and paint
|
63
|
178 |
QBrush brush(HbColorScheme::color("qtc_cal_month_current_day"));
|
45
|
179 |
painter->setBrush(brush);
|
|
180 |
QPen pen;
|
|
181 |
pen.setWidth(1);
|
|
182 |
pen.setBrush(brush);
|
|
183 |
pen.setCapStyle(Qt::RoundCap);
|
|
184 |
pen.setJoinStyle(Qt::RoundJoin);
|
|
185 |
|
|
186 |
painter->setPen(pen);
|
|
187 |
QPointF startPoint(0, dy + dx);
|
|
188 |
|
|
189 |
switch (mDrawingStyle) {
|
|
190 |
case StripWithLines:
|
|
191 |
for (int i = 0; startPoint.y() > 0; i++) {
|
|
192 |
painter->drawPolygon(diagonalLine(startPoint, dx, 3));
|
|
193 |
startPoint.setY(startPoint.y() - 6 - mRange);
|
|
194 |
}
|
|
195 |
case OnlyFrame:
|
|
196 |
painter->setBrush(Qt::NoBrush);
|
|
197 |
break;
|
|
198 |
}
|
|
199 |
|
|
200 |
//draw rectangle
|
|
201 |
painter->drawRect(bounding);
|
|
202 |
|
|
203 |
// restore the painter
|
|
204 |
painter->restore();
|
|
205 |
}
|
|
206 |
|
|
207 |
/*!
|
57
|
208 |
\brief It preapres points to draw filled polygon when StripWithLines style is
|
45
|
209 |
on.
|
|
210 |
*/
|
|
211 |
QPolygonF
|
|
212 |
CalenDayStatusStrip::diagonalLine(QPointF startPoint, qreal dx, qreal dy)
|
|
213 |
{
|
|
214 |
QPolygonF polygon;
|
|
215 |
polygon << QPointF(startPoint.x(), startPoint.y());
|
|
216 |
polygon << QPointF(startPoint.x(), startPoint.y() - dy);
|
|
217 |
polygon << QPointF(startPoint.x() + dx, startPoint.y() - 2 * dy);
|
|
218 |
polygon << QPointF(startPoint.x() + dx, startPoint.y() - dy);
|
|
219 |
return polygon;
|
|
220 |
}
|
|
221 |
|
|
222 |
/*!
|
57
|
223 |
Returns time for position 0 and height in widget
|
45
|
224 |
|
|
225 |
\param startTime Start of event
|
|
226 |
\param endTime End of event
|
|
227 |
\return Draw region of bubble
|
|
228 |
*/
|
|
229 |
QPair<QTime,QTime> CalenDayStatusStrip::calculateStartEndPostion(
|
|
230 |
const QTime &startTime,
|
|
231 |
const QTime &endTime
|
|
232 |
)
|
|
233 |
{
|
|
234 |
|
|
235 |
QTime start;
|
|
236 |
QTime end;
|
|
237 |
|
|
238 |
if (startTime.minute() < 30) {
|
|
239 |
start = QTime(startTime.hour(), 0);
|
|
240 |
}
|
|
241 |
else {
|
|
242 |
start = QTime(startTime.hour(), 30);
|
|
243 |
}
|
|
244 |
|
|
245 |
if (endTime.minute() == 0) {
|
|
246 |
end = endTime;
|
|
247 |
}
|
55
|
248 |
else if (endTime.hour() == 23 and endTime.minute() > 30) {
|
45
|
249 |
end = QTime(endTime.hour(), 59);
|
|
250 |
}
|
|
251 |
else if (endTime.minute() <= 30) {
|
|
252 |
end = QTime(endTime.hour(), 30);
|
|
253 |
}
|
|
254 |
else {
|
|
255 |
end = QTime(endTime.hour() + 1, 0);
|
|
256 |
}
|
|
257 |
|
|
258 |
return QPair<QTime, QTime> (start, end);
|
|
259 |
}
|
|
260 |
|
|
261 |
/*!
|
57
|
262 |
Calculates height of one minute from widget height, and start/end time.
|
45
|
263 |
*/
|
|
264 |
qreal CalenDayStatusStrip::calculateMinuteHeight(const QTime &start,
|
|
265 |
const QTime &end)
|
|
266 |
{
|
|
267 |
qreal min = start.secsTo(end) / mMinute;
|
|
268 |
|
|
269 |
qreal height = size().height();
|
|
270 |
|
|
271 |
return height / min;
|
|
272 |
}
|