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