|
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" |
|
26 |
|
27 // Constants |
|
28 const int clockUpdateInterval (1000); // msec |
|
29 |
|
30 /*! |
|
31 \class AnalogClockWidget |
|
32 |
|
33 This class implements the analogclock widget which gets displayed |
|
34 in the clockmainview when the clocktype is set to analog type. |
|
35 */ |
|
36 |
|
37 /*! |
|
38 Constructor. |
|
39 \param parent The parent of type QGraphicsItem. |
|
40 */ |
|
41 AnalogClockWidget::AnalogClockWidget(QGraphicsItem *parent) |
|
42 : HbWidget(parent) |
|
43 { |
|
44 bool result = HbStyleLoader::registerFilePath(":/resource/analogclockwidget.widgetml"); |
|
45 result = HbStyleLoader::registerFilePath(":/resource/analogclockwidget.css"); |
|
46 |
|
47 updatePrimitives(); |
|
48 mTimer = new QTimer(this); |
|
49 connect(mTimer, SIGNAL(timeout()), SLOT(tick())); |
|
50 mTimer->start(clockUpdateInterval); |
|
51 } |
|
52 |
|
53 /*! |
|
54 Destructor. |
|
55 */ |
|
56 AnalogClockWidget::~AnalogClockWidget() |
|
57 { |
|
58 mTimer->stop(); |
|
59 HbStyleLoader::unregisterFilePath(":/resource"); |
|
60 } |
|
61 |
|
62 /*! |
|
63 Handles resize event from HbWidget |
|
64 */ |
|
65 void AnalogClockWidget::resizeEvent(QGraphicsSceneResizeEvent *event) |
|
66 { |
|
67 QGraphicsWidget::resizeEvent(event); |
|
68 updatePrimitives(); |
|
69 } |
|
70 |
|
71 /*! |
|
72 @copydoc HbWidget::updatePrimitives() |
|
73 */ |
|
74 void AnalogClockWidget::updatePrimitives() |
|
75 { |
|
76 if (!mClockBackground) { |
|
77 mClockBackground = new HbIconItem(QLatin1String("qtg_graf_clock_day_bg"), this); |
|
78 HbStyle::setItemName(mClockBackground, QLatin1String("clock_background")); |
|
79 } |
|
80 |
|
81 // Calculate angles for clock hands. |
|
82 QTime time = QTime::currentTime(); |
|
83 qreal s = 6 * time.second(); |
|
84 qreal m = 6 * (time.minute() + s/360); |
|
85 qreal h = 30 * ((time.hour() % 12) + m/360); |
|
86 |
|
87 if (!mClockHourHand) { |
|
88 mClockHourHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_hour"), this); |
|
89 HbStyle::setItemName(mClockHourHand, QLatin1String("clock_hour_hand")); |
|
90 } |
|
91 |
|
92 int x = mClockHourHand->geometry().width()/2; |
|
93 int y = mClockHourHand->geometry().height()/2; |
|
94 mClockHourHand->setTransform(QTransform().translate(x, y).rotate(h).translate(-x, -y)); |
|
95 |
|
96 if (!mClockMinuteHand) { |
|
97 mClockMinuteHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_min"), this); |
|
98 HbStyle::setItemName(mClockMinuteHand, QLatin1String("clock_minute_hand")); |
|
99 } |
|
100 |
|
101 x = mClockMinuteHand->geometry().width()/2; |
|
102 y = mClockMinuteHand->geometry().height()/2; |
|
103 mClockMinuteHand->setTransform(QTransform().translate(x, y).rotate(m).translate(-x, -y)); |
|
104 |
|
105 |
|
106 if (!mClockSecondHand) { |
|
107 mClockSecondHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_sec"), this); |
|
108 HbStyle::setItemName(mClockSecondHand, QLatin1String("clock_second_hand")); |
|
109 } |
|
110 |
|
111 x = mClockSecondHand->geometry().width()/2; |
|
112 y = mClockSecondHand->geometry().height()/2; |
|
113 mClockSecondHand->setTransform(QTransform().translate(x, y).rotate(s).translate(-x, -y)); |
|
114 |
|
115 } |
|
116 |
|
117 /*! |
|
118 Updates clock visualization according to current time |
|
119 */ |
|
120 void AnalogClockWidget::tick() |
|
121 { |
|
122 updatePrimitives(); |
|
123 update(); |
|
124 } |
|
125 |
|
126 /*! |
|
127 Handles polish event |
|
128 */ |
|
129 void AnalogClockWidget::polish( HbStyleParameters& params ) |
|
130 { |
|
131 HbWidget::polish(params); |
|
132 updatePrimitives(); |
|
133 } |
|
134 |
|
135 // End of file --Don't remove this. |