45
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 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: Clockwidget
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
#include <QGraphicsLinearLayout>
|
|
20 |
|
|
21 |
// User includes
|
|
22 |
#include "clockwidget.h"
|
|
23 |
#include "analogclockwidget.h"
|
|
24 |
#include "digitalclockwidget.h"
|
57
|
25 |
#include "OstTraceDefinitions.h"
|
|
26 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
27 |
#include "clockwidgetTraces.h"
|
|
28 |
#endif
|
|
29 |
|
45
|
30 |
|
|
31 |
/*!
|
|
32 |
\class ClockWidget
|
|
33 |
|
|
34 |
This is the generic wrapper for the clockwidget which manages analog and ditial clockwidgets.
|
|
35 |
*/
|
|
36 |
|
|
37 |
/*!
|
|
38 |
Constructor.
|
|
39 |
*/
|
|
40 |
ClockWidget::ClockWidget(QGraphicsItem *parent, Qt::WindowFlags flags)
|
|
41 |
: HbWidget(parent, flags),
|
|
42 |
mClockType(ClockTypeDigital)
|
|
43 |
{
|
57
|
44 |
OstTraceFunctionEntry0( CLOCKWIDGET_CLOCKWIDGET_ENTRY );
|
45
|
45 |
loadClockWidget();
|
57
|
46 |
OstTraceFunctionExit0( CLOCKWIDGET_CLOCKWIDGET_EXIT );
|
45
|
47 |
}
|
|
48 |
|
|
49 |
/*!
|
|
50 |
Destructor.
|
|
51 |
*/
|
|
52 |
ClockWidget::~ClockWidget()
|
|
53 |
{
|
57
|
54 |
OstTraceFunctionEntry0( DUP1_CLOCKWIDGET_CLOCKWIDGET_ENTRY );
|
45
|
55 |
|
57
|
56 |
OstTraceFunctionExit0( DUP1_CLOCKWIDGET_CLOCKWIDGET_EXIT );
|
45
|
57 |
}
|
|
58 |
|
|
59 |
/*!
|
|
60 |
Returns the clock type.
|
|
61 |
*/
|
|
62 |
ClockWidget::ClockType ClockWidget::clockType() const
|
|
63 |
{
|
57
|
64 |
OstTraceFunctionEntry0( CLOCKWIDGET_CLOCKTYPE_ENTRY );
|
|
65 |
OstTraceFunctionExit0( CLOCKWIDGET_CLOCKTYPE_EXIT );
|
45
|
66 |
return mClockType;
|
|
67 |
}
|
|
68 |
|
|
69 |
/*!
|
|
70 |
Sets the clock type;
|
|
71 |
*/
|
|
72 |
void ClockWidget::setClockType(const ClockType &type)
|
|
73 |
{
|
57
|
74 |
OstTraceFunctionEntry0( CLOCKWIDGET_SETCLOCKTYPE_ENTRY );
|
45
|
75 |
if (type == ClockTypeAnalog) {
|
|
76 |
if(type != mClockType){
|
|
77 |
mClockType = ClockTypeAnalog;
|
|
78 |
updateClockWidget();
|
|
79 |
}
|
|
80 |
} else {
|
|
81 |
if(type != mClockType){
|
|
82 |
mClockType = ClockTypeDigital;
|
|
83 |
updateClockWidget();
|
|
84 |
}
|
|
85 |
}
|
57
|
86 |
OstTraceFunctionExit0( CLOCKWIDGET_SETCLOCKTYPE_EXIT );
|
45
|
87 |
}
|
|
88 |
|
|
89 |
/*!
|
|
90 |
Updates the clock time with every second
|
|
91 |
*/
|
|
92 |
void ClockWidget::updateTime()
|
|
93 |
{
|
57
|
94 |
OstTraceFunctionEntry0( CLOCKWIDGET_UPDATETIME_ENTRY );
|
45
|
95 |
if (mClockType == ClockTypeAnalog) {
|
|
96 |
mAnalogClock->tick();
|
|
97 |
} else {
|
|
98 |
mDigitalClock->updatePrimitives();
|
|
99 |
}
|
57
|
100 |
OstTraceFunctionExit0( CLOCKWIDGET_UPDATETIME_EXIT );
|
45
|
101 |
}
|
|
102 |
|
|
103 |
/*!
|
|
104 |
Constructs the clockwidget based upon its type.
|
|
105 |
*/
|
|
106 |
void ClockWidget::loadClockWidget()
|
|
107 |
{
|
57
|
108 |
OstTraceFunctionEntry0( CLOCKWIDGET_LOADCLOCKWIDGET_ENTRY );
|
45
|
109 |
mLayout = new QGraphicsLinearLayout(Qt::Vertical);
|
|
110 |
mLayout->setContentsMargins(0,0,0,0);
|
|
111 |
|
|
112 |
if (mClockType == ClockTypeAnalog) {
|
|
113 |
mAnalogClock = new AnalogClockWidget(this);
|
|
114 |
mLayout->addItem(mAnalogClock);
|
|
115 |
} else {
|
|
116 |
bool useAmPm = false;
|
|
117 |
mDigitalClock = new DigitalClockWidget(useAmPm, this);
|
|
118 |
mLayout->addItem(mDigitalClock);
|
|
119 |
}
|
|
120 |
setLayout(mLayout);
|
57
|
121 |
OstTraceFunctionExit0( CLOCKWIDGET_LOADCLOCKWIDGET_EXIT );
|
45
|
122 |
}
|
|
123 |
|
|
124 |
/*!
|
|
125 |
Constructs the clockwidget based upon its type.
|
|
126 |
*/
|
|
127 |
void ClockWidget::updateClockWidget()
|
|
128 |
{
|
57
|
129 |
OstTraceFunctionEntry0( CLOCKWIDGET_UPDATECLOCKWIDGET_ENTRY );
|
45
|
130 |
if (mClockType == ClockTypeAnalog) {
|
|
131 |
mLayout->removeItem(mDigitalClock);
|
|
132 |
delete mDigitalClock;
|
|
133 |
if (!mAnalogClock) {
|
|
134 |
mAnalogClock = new AnalogClockWidget(this);
|
|
135 |
}
|
|
136 |
mLayout->addItem(mAnalogClock);
|
|
137 |
} else {
|
|
138 |
mLayout->removeItem(mAnalogClock);
|
|
139 |
delete mAnalogClock;
|
|
140 |
if(!mDigitalClock){
|
|
141 |
bool useAmPm = false; // find out this fronm the settings utility
|
|
142 |
mDigitalClock = new DigitalClockWidget(useAmPm, this);
|
|
143 |
}
|
|
144 |
mLayout->addItem(mDigitalClock);
|
|
145 |
}
|
57
|
146 |
OstTraceFunctionExit0( CLOCKWIDGET_UPDATECLOCKWIDGET_EXIT );
|
45
|
147 |
}
|
|
148 |
|
|
149 |
ClockWidget::TimeFormat ClockWidget::timeFormat() const
|
|
150 |
{
|
57
|
151 |
OstTraceFunctionEntry0( CLOCKWIDGET_TIMEFORMAT_ENTRY );
|
|
152 |
OstTraceFunctionExit0( CLOCKWIDGET_TIMEFORMAT_EXIT );
|
45
|
153 |
return mTimeFormat;
|
|
154 |
}
|
|
155 |
|
|
156 |
void ClockWidget::setTimeFormat(const TimeFormat &timeFormat)
|
|
157 |
{
|
57
|
158 |
OstTraceFunctionEntry0( CLOCKWIDGET_SETTIMEFORMAT_ENTRY );
|
45
|
159 |
if(mDigitalClock){
|
|
160 |
mTimeFormat = timeFormat;
|
|
161 |
if (timeFormat == ClockWidget::TimeFormat12Hrs) {
|
|
162 |
mDigitalClock->setAmPm(true);
|
|
163 |
} else {
|
|
164 |
mDigitalClock->setAmPm(false);
|
|
165 |
}
|
|
166 |
}
|
57
|
167 |
OstTraceFunctionExit0( CLOCKWIDGET_SETTIMEFORMAT_EXIT );
|
45
|
168 |
}
|
|
169 |
// End of file --Don't remove this.
|