45
|
1 |
/*
|
|
2 |
* Copyright (c) 2008 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: AnalogClockWidget
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <HbIconItem>
|
|
20 |
#include <HbStyleLoader>
|
|
21 |
#include <QTime>
|
|
22 |
#include <QTimer>
|
|
23 |
|
|
24 |
// User includes
|
|
25 |
#include "analogclockwidget.h"
|
57
|
26 |
#include "OstTraceDefinitions.h"
|
|
27 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
28 |
#include "analogclockwidgetTraces.h"
|
|
29 |
#endif
|
|
30 |
|
45
|
31 |
|
|
32 |
// Constants
|
|
33 |
const int clockUpdateInterval (1000); // msec
|
|
34 |
|
|
35 |
/*!
|
|
36 |
\class AnalogClockWidget
|
|
37 |
|
|
38 |
This class implements the analogclock widget which gets displayed
|
|
39 |
in the clockmainview when the clocktype is set to analog type.
|
55
|
40 |
*/
|
45
|
41 |
|
|
42 |
/*!
|
|
43 |
Constructor.
|
|
44 |
\param parent The parent of type QGraphicsItem.
|
|
45 |
*/
|
55
|
46 |
AnalogClockWidget::AnalogClockWidget(QGraphicsItem *parent) :
|
|
47 |
HbWidget(parent)
|
45
|
48 |
{
|
57
|
49 |
OstTraceFunctionEntry0( ANALOGCLOCKWIDGET_ANALOGCLOCKWIDGET_ENTRY );
|
55
|
50 |
bool result = HbStyleLoader::registerFilePath(
|
|
51 |
":/resource/analogclockwidget.widgetml");
|
|
52 |
result = HbStyleLoader::registerFilePath(
|
|
53 |
":/resource/analogclockwidget.css");
|
|
54 |
|
|
55 |
constructPrimitives();
|
|
56 |
mTimer = new QTimer(this);
|
|
57 |
connect(mTimer, SIGNAL(timeout()), SLOT(tick()));
|
57
|
58 |
OstTraceFunctionExit0( ANALOGCLOCKWIDGET_ANALOGCLOCKWIDGET_EXIT );
|
45
|
59 |
}
|
|
60 |
|
|
61 |
/*!
|
|
62 |
Destructor.
|
|
63 |
*/
|
|
64 |
AnalogClockWidget::~AnalogClockWidget()
|
55
|
65 |
{
|
57
|
66 |
OstTraceFunctionEntry0( DUP1_ANALOGCLOCKWIDGET_ANALOGCLOCKWIDGET_ENTRY );
|
55
|
67 |
mTimer->stop();
|
|
68 |
HbStyleLoader::unregisterFilePath(":/resource/analogclockwidget.widgetml");
|
|
69 |
HbStyleLoader::unregisterFilePath(":/resource/analogclockwidget.css");
|
57
|
70 |
OstTraceFunctionExit0( DUP1_ANALOGCLOCKWIDGET_ANALOGCLOCKWIDGET_EXIT );
|
45
|
71 |
}
|
|
72 |
|
|
73 |
/*!
|
55
|
74 |
Constructs the widget primitive items.
|
45
|
75 |
*/
|
55
|
76 |
void AnalogClockWidget::constructPrimitives()
|
45
|
77 |
{
|
57
|
78 |
OstTraceFunctionEntry0( ANALOGCLOCKWIDGET_CONSTRUCTPRIMITIVES_ENTRY );
|
55
|
79 |
if (!mClockBackground) {
|
|
80 |
mClockBackground = new HbIconItem(
|
|
81 |
QLatin1String("qtg_graf_clock_day_bg"), this);
|
|
82 |
HbStyle::setItemName(
|
|
83 |
mClockBackground, QLatin1String("clock_background"));
|
|
84 |
}
|
|
85 |
|
|
86 |
if (!mClockHourHand) {
|
|
87 |
mClockHourHand = new HbIconItem(
|
|
88 |
QLatin1String("qtg_graf_clock_day_hour"), this);
|
|
89 |
HbStyle::setItemName(
|
|
90 |
mClockHourHand, QLatin1String("clock_hour_hand"));
|
|
91 |
}
|
|
92 |
|
|
93 |
if (!mClockMinuteHand) {
|
|
94 |
mClockMinuteHand = new HbIconItem(
|
|
95 |
QLatin1String("qtg_graf_clock_day_min"), this);
|
|
96 |
HbStyle::setItemName(
|
|
97 |
mClockMinuteHand, QLatin1String("clock_minute_hand"));
|
|
98 |
}
|
|
99 |
|
|
100 |
if (!mClockSecondHand) {
|
|
101 |
mClockSecondHand = new HbIconItem(
|
|
102 |
QLatin1String("qtg_graf_clock_day_sec"), this);
|
|
103 |
HbStyle::setItemName(
|
|
104 |
mClockSecondHand, QLatin1String("clock_second_hand"));
|
|
105 |
}
|
57
|
106 |
OstTraceFunctionExit0( ANALOGCLOCKWIDGET_CONSTRUCTPRIMITIVES_EXIT );
|
45
|
107 |
}
|
|
108 |
|
|
109 |
/*!
|
55
|
110 |
Called on the derived classes to notify in cases when
|
|
111 |
the style primitives need to be updated.
|
45
|
112 |
*/
|
|
113 |
void AnalogClockWidget::updatePrimitives()
|
|
114 |
{
|
57
|
115 |
OstTraceFunctionEntry0( ANALOGCLOCKWIDGET_UPDATEPRIMITIVES_ENTRY );
|
55
|
116 |
if (!mClockBackground) {
|
|
117 |
mClockBackground = new HbIconItem(
|
|
118 |
QLatin1String("qtg_graf_clock_day_bg"), this);
|
|
119 |
HbStyle::setItemName(
|
|
120 |
mClockBackground, QLatin1String("clock_background"));
|
|
121 |
}
|
|
122 |
|
45
|
123 |
if (!mClockHourHand) {
|
55
|
124 |
mClockHourHand = new HbIconItem(
|
|
125 |
QLatin1String("qtg_graf_clock_day_hour"), this);
|
|
126 |
HbStyle::setItemName(
|
|
127 |
mClockHourHand, QLatin1String("clock_hour_hand"));
|
|
128 |
}
|
|
129 |
|
|
130 |
if (!mClockMinuteHand) {
|
|
131 |
mClockMinuteHand = new HbIconItem(
|
|
132 |
QLatin1String("qtg_graf_clock_day_min"), this);
|
|
133 |
HbStyle::setItemName(
|
|
134 |
mClockMinuteHand, QLatin1String("clock_minute_hand"));
|
|
135 |
}
|
|
136 |
|
|
137 |
if (!mClockSecondHand) {
|
|
138 |
mClockSecondHand = new HbIconItem(
|
|
139 |
QLatin1String("qtg_graf_clock_day_sec"), this);
|
|
140 |
HbStyle::setItemName(
|
|
141 |
mClockSecondHand, QLatin1String("clock_second_hand"));
|
|
142 |
}
|
|
143 |
|
|
144 |
QRectF hourHandGeometry = mClockHourHand->geometry();
|
|
145 |
QRectF minHandGeometry = mClockMinuteHand->geometry();
|
|
146 |
QRectF secHandGeometry = mClockSecondHand->geometry();
|
|
147 |
|
|
148 |
if ((hourHandGeometry.width() && hourHandGeometry.height()) &&
|
|
149 |
(minHandGeometry.width() && minHandGeometry.height()) &&
|
|
150 |
(secHandGeometry.width() && secHandGeometry.height())) {
|
|
151 |
// Calculate angles for clock hands.
|
|
152 |
QTime curTime = QTime::currentTime();
|
|
153 |
qreal seconds = 6 * curTime.second();
|
|
154 |
qreal minutes = 6 * (curTime.minute() + seconds / 360);
|
|
155 |
qreal hours = 30 * ((curTime.hour() % 12) + minutes / 360);
|
45
|
156 |
|
55
|
157 |
int x = hourHandGeometry.width()/2;
|
|
158 |
int y = hourHandGeometry.height()/2;
|
|
159 |
mClockHourHand->setTransform(
|
|
160 |
QTransform().translate(x, y).rotate(hours).translate(-x, -y));
|
|
161 |
|
|
162 |
x = minHandGeometry.width()/2;
|
|
163 |
y = minHandGeometry.height()/2;
|
|
164 |
mClockMinuteHand->setTransform(
|
|
165 |
QTransform().translate(x, y).rotate(minutes).translate(-x, -y));
|
45
|
166 |
|
55
|
167 |
x = secHandGeometry.width()/2;
|
|
168 |
y = secHandGeometry.height()/2;
|
|
169 |
mClockSecondHand->setTransform(
|
|
170 |
QTransform().translate(x, y).rotate(seconds).translate(-x, -y));
|
|
171 |
}
|
|
172 |
|
|
173 |
if (!mTimer->isActive()) {
|
|
174 |
mTimer->start(clockUpdateInterval);
|
|
175 |
}
|
57
|
176 |
OstTraceFunctionExit0( ANALOGCLOCKWIDGET_UPDATEPRIMITIVES_EXIT );
|
45
|
177 |
}
|
|
178 |
|
|
179 |
/*!
|
55
|
180 |
Updates clock visualization according to current time.
|
45
|
181 |
*/
|
|
182 |
void AnalogClockWidget::tick()
|
|
183 |
{
|
57
|
184 |
OstTraceFunctionEntry0( ANALOGCLOCKWIDGET_TICK_ENTRY );
|
55
|
185 |
updatePrimitives();
|
|
186 |
update();
|
57
|
187 |
OstTraceFunctionExit0( ANALOGCLOCKWIDGET_TICK_EXIT );
|
45
|
188 |
}
|
|
189 |
|
|
190 |
/*!
|
55
|
191 |
Sets the item's geometry to rect.
|
45
|
192 |
*/
|
55
|
193 |
void AnalogClockWidget::setGeometry(const QRectF &rect)
|
|
194 |
{
|
57
|
195 |
OstTraceFunctionEntry0( ANALOGCLOCKWIDGET_SETGEOMETRY_ENTRY );
|
55
|
196 |
HbWidget::setGeometry(rect);
|
|
197 |
updatePrimitives();
|
57
|
198 |
OstTraceFunctionExit0( ANALOGCLOCKWIDGET_SETGEOMETRY_EXIT );
|
55
|
199 |
}
|
45
|
200 |
|
|
201 |
// End of file --Don't remove this.
|