97
|
1 |
/*
|
|
2 |
* Copyright (c) 2009-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: Analog Clock Widget.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "snsranalogclockwidget.h"
|
|
19 |
|
|
20 |
#include <QGraphicsSvgItem>
|
|
21 |
#include <QTime>
|
|
22 |
#include <QDebug>
|
|
23 |
#include <HbExtendedLocale>
|
|
24 |
#include <HbStyleLoader>
|
|
25 |
#include <HbIconItem>
|
|
26 |
#include <hbevent.h>
|
|
27 |
#include <HbColorScheme>
|
|
28 |
#include <HbTextItem>
|
|
29 |
|
|
30 |
|
|
31 |
const char *gClockCssFilePath =":/style/snsranalogclockwidget.css";
|
|
32 |
const char *gClockWidgetMLFilePath = ":/style/snsranalogclockwidget.widgetml";
|
|
33 |
|
|
34 |
const QString amPmLabelTextColorRole("qtc_screensaver_analog_clock");
|
|
35 |
|
|
36 |
/*!
|
|
37 |
\class SnsrAnalogClockWidget
|
|
38 |
\ingroup group_snsrbigclockscreensaverprovider
|
|
39 |
\brief Screensaver analog clock widget.
|
|
40 |
*/
|
|
41 |
|
|
42 |
/*!
|
|
43 |
Constructs a new SnsrAnalogClockWidget.
|
|
44 |
\param parent Parent object.
|
|
45 |
*/
|
|
46 |
SnsrAnalogClockWidget::SnsrAnalogClockWidget(QGraphicsItem* parent):
|
|
47 |
HbWidget(parent),
|
|
48 |
mClockBackground(0), mClockHourHand(0),
|
|
49 |
mClockMinuteHand(0), mClockSecondHand(0),
|
|
50 |
mClockAmPmLabel(0)
|
|
51 |
{
|
|
52 |
HbStyleLoader::registerFilePath(gClockCssFilePath);
|
|
53 |
HbStyleLoader::registerFilePath(gClockWidgetMLFilePath);
|
|
54 |
|
|
55 |
createPrimitives();
|
|
56 |
updatePrimitives();
|
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
Destructs the class.
|
|
61 |
*/
|
|
62 |
SnsrAnalogClockWidget::~SnsrAnalogClockWidget()
|
|
63 |
{
|
|
64 |
HbStyleLoader::unregisterFilePath( gClockCssFilePath );
|
|
65 |
HbStyleLoader::unregisterFilePath( gClockWidgetMLFilePath );
|
|
66 |
|
|
67 |
}
|
|
68 |
|
|
69 |
void SnsrAnalogClockWidget::polish( HbStyleParameters& params )
|
|
70 |
{
|
|
71 |
// TODO: updatePrimitives might not be needed to be called from here anymore (hb changes)?
|
|
72 |
HbWidget::polish(params);
|
|
73 |
updatePrimitives();
|
|
74 |
}
|
|
75 |
|
|
76 |
/*!
|
|
77 |
@copydoc HbWidget::resizeEvent()
|
|
78 |
*/
|
|
79 |
void SnsrAnalogClockWidget::resizeEvent(QGraphicsSceneResizeEvent *event)
|
|
80 |
{
|
|
81 |
HbWidget::resizeEvent(event);
|
|
82 |
updatePrimitives();
|
|
83 |
}
|
|
84 |
|
|
85 |
/*!
|
|
86 |
Creates all widget primitives.
|
|
87 |
*/
|
|
88 |
void SnsrAnalogClockWidget::createPrimitives()
|
|
89 |
{
|
|
90 |
// TODO: when final graphics are available in platform (qtg_graf_screensaver_clock_xxx)
|
|
91 |
// use them instead.
|
|
92 |
if (!mClockBackground) {
|
|
93 |
mClockBackground = new HbIconItem(QLatin1String("qtg_graf_clock_day_bg"), this);
|
|
94 |
HbStyle::setItemName(mClockBackground, QLatin1String("analog_clock_background"));
|
|
95 |
}
|
|
96 |
if (!mClockHourHand) {
|
|
97 |
mClockHourHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_hour"), this);
|
|
98 |
HbStyle::setItemName(mClockHourHand, QLatin1String("analog_clock_hour_hand"));
|
|
99 |
}
|
|
100 |
if (!mClockMinuteHand) {
|
|
101 |
mClockMinuteHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_min"), this);
|
|
102 |
HbStyle::setItemName(mClockMinuteHand, QLatin1String("analog_clock_minute_hand"));
|
|
103 |
}
|
|
104 |
if (!mClockSecondHand) {
|
|
105 |
mClockSecondHand = new HbIconItem(QLatin1String("qtg_graf_clock_day_sec"), this);
|
|
106 |
HbStyle::setItemName(mClockSecondHand, QLatin1String("analog_clock_second_hand"));
|
|
107 |
}
|
|
108 |
if (!mClockAmPmLabel) {
|
|
109 |
mClockAmPmLabel = new HbTextItem(this);
|
|
110 |
HbStyle::setItemName(mClockAmPmLabel, QLatin1String("analog_clock_am_pm_label"));
|
|
111 |
mClockAmPmLabel->setTextColor(HbColorScheme::color(amPmLabelTextColorRole));
|
|
112 |
mClockAmPmLabel->setMinimumLines(1);
|
|
113 |
mClockAmPmLabel->setMaximumLines(1);
|
|
114 |
mClockAmPmLabel->setTextWrapping(Hb::TextNoWrap);
|
|
115 |
HbFontSpec textFont(HbFontSpec::Primary);
|
|
116 |
qreal textHeight = 0;
|
|
117 |
style()->parameter(QLatin1String("hb-param-text-height-tiny"), textHeight);
|
|
118 |
textFont.setTextHeight(textHeight);
|
|
119 |
mClockAmPmLabel->setFontSpec(textFont);
|
|
120 |
}
|
|
121 |
}
|
|
122 |
|
|
123 |
/*!
|
|
124 |
@copydoc HbWidget::updatePrimitives()
|
|
125 |
*/
|
|
126 |
void SnsrAnalogClockWidget::updatePrimitives()
|
|
127 |
{
|
|
128 |
if (!mClockHourHand || !mClockMinuteHand || !mClockSecondHand || !mClockAmPmLabel) {
|
|
129 |
createPrimitives();
|
|
130 |
}
|
|
131 |
|
|
132 |
// Calculate angles for clock hands.
|
|
133 |
QTime time = QTime::currentTime();
|
|
134 |
qreal s = 6 * time.second();
|
|
135 |
qreal m = 6 * (time.minute() + s/360);
|
|
136 |
qreal h = 30 * ((time.hour() % 12) + m/360);
|
|
137 |
|
|
138 |
int x = mClockHourHand->preferredSize().width()/2;
|
|
139 |
int y = mClockHourHand->preferredSize().height()/2;
|
|
140 |
mClockHourHand->setTransform(QTransform().translate(x, y).rotate(h).translate(-x, -y));
|
|
141 |
|
|
142 |
x = mClockMinuteHand->preferredSize().width()/2;
|
|
143 |
y = mClockMinuteHand->preferredSize().height()/2;
|
|
144 |
mClockMinuteHand->setTransform(QTransform().translate(x, y).rotate(m).translate(-x, -y));
|
|
145 |
|
|
146 |
x = mClockSecondHand->preferredSize().width()/2;
|
|
147 |
y = mClockSecondHand->preferredSize().height()/2;
|
|
148 |
mClockSecondHand->setTransform(QTransform().translate(x, y).rotate(s).translate(-x, -y));
|
|
149 |
|
|
150 |
QString amPmString = (time.hour()<12) ? HbExtendedLocale().amText() : HbExtendedLocale().pmText();
|
|
151 |
mClockAmPmLabel->setText( amPmString );
|
|
152 |
}
|
|
153 |
|
|
154 |
/*!
|
|
155 |
Updates primitives when time change.
|
|
156 |
*/
|
|
157 |
void SnsrAnalogClockWidget::tick()
|
|
158 |
{
|
|
159 |
updatePrimitives();
|
|
160 |
}
|
|
161 |
|
|
162 |
/*!
|
|
163 |
\reimp
|
|
164 |
*/
|
|
165 |
void SnsrAnalogClockWidget::changeEvent(QEvent * event)
|
|
166 |
{
|
|
167 |
if (event->type() == HbEvent::ThemeChanged) {
|
|
168 |
mClockAmPmLabel->setTextColor(HbColorScheme::color(amPmLabelTextColorRole));
|
|
169 |
}
|
|
170 |
return HbWidget::changeEvent(event);
|
|
171 |
}
|