45
|
1 |
/*
|
57
|
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 |
*/
|
45
|
17 |
|
57
|
18 |
// System includes
|
45
|
19 |
#include <QGraphicsLinearLayout>
|
|
20 |
#include <QPainter>
|
57
|
21 |
#include <HbTextItem>
|
|
22 |
#include <HbStyle>
|
|
23 |
#include <HbColorScheme>
|
|
24 |
#include <HbFontSpec>
|
|
25 |
#include <HbExtendedLocale>
|
45
|
26 |
|
57
|
27 |
// User includes
|
45
|
28 |
#include "calendayhourelement.h"
|
|
29 |
#include "calendaycontainer.h"
|
|
30 |
#include "calendayhourscrollarea.h"
|
|
31 |
|
|
32 |
// Constants
|
57
|
33 |
/*!
|
|
34 |
\brief Time format is: [0-9][0-9]:[0-9][0-9]
|
|
35 |
*/
|
|
36 |
const int KCalenTimeFormatLength = 5;
|
45
|
37 |
|
|
38 |
/*!
|
57
|
39 |
\class CalenDayHourElement
|
|
40 |
\brief Hour element widget for Calendar's Day View
|
|
41 |
*/
|
|
42 |
|
|
43 |
/*!
|
|
44 |
\brief Constructor
|
|
45 |
|
|
46 |
\param time Time assigned to widget
|
|
47 |
\param parent Widget's parent
|
|
48 |
*/
|
|
49 |
CalenDayHourElement::CalenDayHourElement(
|
|
50 |
const QTime &time,
|
|
51 |
QGraphicsItem *parent) :
|
81
|
52 |
HbWidget(parent), mHour(time), mTimeTextItem(NULL), mAmpmTextItem(NULL)
|
45
|
53 |
{
|
|
54 |
// Necessary when widget implements own paint method
|
57
|
55 |
setFlag(QGraphicsItem::ItemHasNoContents, false);
|
81
|
56 |
|
45
|
57 |
HbDeviceProfile deviceProfile;
|
|
58 |
mUnitInPixels = deviceProfile.unitValue();
|
81
|
59 |
mHour = time;
|
45
|
60 |
|
57
|
61 |
// Initialize hour line color
|
81
|
62 |
mHourLineColor = HbColorScheme::color(KCalenHourLineColor);
|
|
63 |
|
|
64 |
mTimeTextItem = new HbTextItem(this);
|
|
65 |
mAmpmTextItem = new HbTextItem(this);
|
|
66 |
HbStyle::setItemName(mTimeTextItem, QLatin1String("time"));
|
|
67 |
HbStyle::setItemName(mAmpmTextItem, QLatin1String("ampm"));
|
|
68 |
|
|
69 |
setupWithLocale();
|
45
|
70 |
|
57
|
71 |
// Parent container is needed to update widget's time
|
45
|
72 |
mContainer = static_cast<CalenDayHourScrollArea*> (parent);
|
|
73 |
}
|
|
74 |
|
|
75 |
/*!
|
57
|
76 |
\brief Destructor
|
|
77 |
*/
|
45
|
78 |
CalenDayHourElement::~CalenDayHourElement()
|
|
79 |
{
|
|
80 |
}
|
|
81 |
|
|
82 |
/*!
|
57
|
83 |
\brief Customized paint() function
|
|
84 |
|
|
85 |
\param painter Painter
|
|
86 |
\param option Style option
|
|
87 |
\param widget
|
|
88 |
*/
|
45
|
89 |
void CalenDayHourElement::paint(
|
57
|
90 |
QPainter *painter,
|
|
91 |
const QStyleOptionGraphicsItem *option,
|
|
92 |
QWidget *widget)
|
45
|
93 |
{
|
|
94 |
Q_UNUSED(widget);
|
57
|
95 |
|
|
96 |
painter->save();
|
45
|
97 |
|
|
98 |
QRectF drawArea = option->rect;
|
|
99 |
|
57
|
100 |
// Draw full hour line
|
|
101 |
QPen linePen = QPen(mHourLineColor, KCalenHourLineThickness * mUnitInPixels);
|
45
|
102 |
painter->setPen(linePen);
|
57
|
103 |
|
45
|
104 |
QLineF fullHourLine(drawArea.bottomLeft(), drawArea.bottomRight());
|
|
105 |
painter->drawLine(fullHourLine);
|
|
106 |
|
57
|
107 |
// Draw extra line on top for midnight
|
45
|
108 |
if (mHour.hour() == 0) {
|
|
109 |
fullHourLine = QLineF(drawArea.topLeft(), drawArea.topRight());
|
|
110 |
painter->drawLine(fullHourLine);
|
57
|
111 |
}
|
|
112 |
|
45
|
113 |
QDateTime currentDateTime = QDateTime::currentDateTime();
|
|
114 |
|
57
|
115 |
// Draw the time line in theme color
|
45
|
116 |
if (mContainer) {
|
|
117 |
QDateTime containersDateTime = mContainer->dateTime();
|
57
|
118 |
|
|
119 |
if (currentDateTime.date() == containersDateTime.date()
|
|
120 |
&& currentDateTime.time().hour() == mHour.hour()) {
|
|
121 |
|
|
122 |
qreal currentTimeY = drawArea.height()
|
|
123 |
* currentDateTime.time().minute() / 60;
|
45
|
124 |
|
57
|
125 |
QColor color = HbColorScheme::color(KCalenTimeLineColor);
|
63
|
126 |
painter->setPen(QPen(color, KCalenCurrentTimeLineThickness
|
|
127 |
* mUnitInPixels, Qt::SolidLine, Qt::FlatCap));
|
57
|
128 |
QLineF currentTimeline(drawArea.left(), drawArea.top() + currentTimeY,
|
|
129 |
drawArea.right(), drawArea.top() + currentTimeY);
|
45
|
130 |
painter->drawLine(currentTimeline);
|
|
131 |
}
|
|
132 |
}
|
|
133 |
|
|
134 |
painter->restore();
|
|
135 |
}
|
|
136 |
|
55
|
137 |
/*!
|
57
|
138 |
\brief Sets time for hour element.
|
|
139 |
|
|
140 |
\param time Time to be set for hour element
|
55
|
141 |
*/
|
|
142 |
void CalenDayHourElement::setTime(const QTime &time)
|
|
143 |
{
|
|
144 |
mHour = time;
|
|
145 |
}
|
|
146 |
|
|
147 |
/*!
|
57
|
148 |
\brief Returns time of hour element.
|
|
149 |
|
|
150 |
\return Time of hour element
|
55
|
151 |
*/
|
|
152 |
QTime CalenDayHourElement::time() const
|
|
153 |
{
|
|
154 |
return mHour;
|
|
155 |
}
|
|
156 |
|
81
|
157 |
/*!
|
|
158 |
\brief SLOT updates control when system locale changes
|
|
159 |
*/
|
|
160 |
void CalenDayHourElement::localeChanged()
|
|
161 |
{
|
|
162 |
setupWithLocale();
|
|
163 |
repolish();
|
|
164 |
}
|
|
165 |
|
|
166 |
/*!
|
|
167 |
\brief Sets up internal data using current system locale.
|
|
168 |
*/
|
|
169 |
void CalenDayHourElement::setupWithLocale()
|
|
170 |
{
|
|
171 |
HbDeviceProfile deviceProfile;
|
|
172 |
|
|
173 |
// Create text items
|
|
174 |
HbExtendedLocale systemLocale = HbExtendedLocale::system();
|
|
175 |
|
|
176 |
// Get current time format and (if there's a need) separate time from am/pm text
|
|
177 |
QChar timeSeparator = ' ';
|
|
178 |
QStringList timeTextList = systemLocale.format(mHour, r_qtn_time_usual_with_zero).split(timeSeparator);
|
|
179 |
|
|
180 |
// If needed, prepend '0' to get proper time format: [0-9][0-9]:[0-9][0-9]
|
|
181 |
QString timeString = timeTextList[0];
|
|
182 |
if (timeString.length() < KCalenTimeFormatLength) {
|
|
183 |
timeString.prepend('0');
|
|
184 |
}
|
|
185 |
|
|
186 |
QString ampmString = "";
|
|
187 |
if (timeTextList.count() > 1) {
|
|
188 |
ampmString = timeTextList[1].toLower();
|
|
189 |
}
|
|
190 |
|
|
191 |
mTimeTextItem->setText(timeString);
|
|
192 |
mAmpmTextItem->setText(ampmString);
|
|
193 |
}
|
|
194 |
|
45
|
195 |
// End of File
|