62
|
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: Container for oled analog clock.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "snsroledanalogclockcontainer.h"
|
|
19 |
|
|
20 |
#include <QDebug>
|
|
21 |
#include <QGraphicsLinearLayout>
|
|
22 |
#include <QTimer>
|
|
23 |
#include <QTime>
|
|
24 |
#include <hblabel.h>
|
|
25 |
#include <hbextendedlocale.h>
|
|
26 |
|
|
27 |
#include "snsroledclockwidget.h"
|
|
28 |
#include "snsrindicatorwidget.h"
|
|
29 |
|
|
30 |
/*!
|
|
31 |
\class SnsrOledAnalogClockContainer
|
|
32 |
\ingroup group_snsrbigclockscreensaverplugin
|
|
33 |
\brief Container used for preparing layout for oled analog clock.
|
|
34 |
*/
|
|
35 |
|
|
36 |
const char *gOledAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveroledanalog.docml";
|
|
37 |
extern const char *gPortraitSectionName;
|
|
38 |
extern const char *gLandscapeSectionName;
|
|
39 |
|
|
40 |
extern const char *gMainViewName;
|
|
41 |
extern const char *gMainContainerName;
|
|
42 |
extern const char *gClockContainerName;
|
|
43 |
extern const char *gIndicatorWidgetName;
|
|
44 |
|
|
45 |
extern const char *gDateLabelName;
|
|
46 |
extern const char *gDateFormatVerticalStr;
|
|
47 |
extern const char *gDateFormatHorizontalStr;
|
|
48 |
|
|
49 |
const char *gOledAnalogClockWidgetName = "oledAnalogClockWidget";
|
|
50 |
|
|
51 |
|
|
52 |
/*!
|
|
53 |
Constructs a new SnsrOledAnalogClockContainer.
|
|
54 |
*/
|
|
55 |
SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer() :
|
|
56 |
SnsrBigClockContainer(), mClockContainer(0), mOledClockWidget(0),
|
|
57 |
mDateLabel(0), mDestPosition(QPointF()), mInitialize(false)
|
|
58 |
{
|
|
59 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer")
|
|
60 |
|
|
61 |
bool ok(false);
|
|
62 |
qDebug() << gOledAnalogLayoutDocml;
|
|
63 |
|
|
64 |
// load oled analog clock
|
|
65 |
mDocumentObjects = mDocumentLoader.load(gOledAnalogLayoutDocml, &ok);
|
|
66 |
Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid DocML file.");
|
|
67 |
if (ok) {
|
|
68 |
mMainView = mDocumentLoader.findWidget(gMainViewName);
|
|
69 |
mMainContainer = mDocumentLoader.findWidget(gMainContainerName);
|
|
70 |
mClockContainer = mDocumentLoader.findWidget(gClockContainerName);
|
|
71 |
mOledClockWidget = qobject_cast<SnsrOledClockWidget *>(
|
|
72 |
mDocumentLoader.findWidget(gOledAnalogClockWidgetName));
|
|
73 |
mDateLabel = qobject_cast<HbLabel *>(
|
|
74 |
mDocumentLoader.findWidget(gDateLabelName));
|
|
75 |
mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>(
|
|
76 |
mDocumentLoader.findWidget(gIndicatorWidgetName));
|
|
77 |
Q_ASSERT_X(
|
|
78 |
mMainView && mMainContainer && mClockContainer
|
|
79 |
&& mOledClockWidget && mDateLabel && mIndicatorWidget,
|
|
80 |
gOledAnalogLayoutDocml, "Objects not found in DocML file."
|
|
81 |
);
|
|
82 |
|
|
83 |
mIndicatorWidget->setLayoutType(SnsrIndicatorWidget::IndicatorsCentered);
|
|
84 |
|
|
85 |
mBackgroundContainerLayout->addItem(mMainView);
|
|
86 |
}
|
|
87 |
|
|
88 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer")
|
|
89 |
}
|
|
90 |
|
|
91 |
/*!
|
|
92 |
Destructs the class.
|
|
93 |
*/
|
|
94 |
SnsrOledAnalogClockContainer::~SnsrOledAnalogClockContainer()
|
|
95 |
{
|
|
96 |
//mOledClockWidget etc - deleted by the parent
|
|
97 |
}
|
|
98 |
|
|
99 |
/*!
|
|
100 |
Updates OLED analog clock widget position.
|
|
101 |
*/
|
|
102 |
void SnsrOledAnalogClockContainer::updatePosition()
|
|
103 |
{
|
|
104 |
QSizeF containerSize = mMainContainer->size();
|
|
105 |
|
|
106 |
// Container must have a valid size to enable calculating the
|
|
107 |
// destination position for the clock.
|
|
108 |
if ( containerSize.width() > 0 && containerSize.height() > 0 ) {
|
|
109 |
containerSize -= mClockContainer->boundingRect().size();
|
|
110 |
QRectF containerRect( mMainContainer->pos(), containerSize );
|
|
111 |
if ( mInitialize ) {
|
|
112 |
QPointF clockPos = nextRandomPosition( mClockContainer->pos(), mDestPosition, containerRect );
|
|
113 |
mClockContainer->setPos( clockPos );
|
|
114 |
}
|
|
115 |
else {
|
|
116 |
mDestPosition = randomPosition( containerRect );
|
|
117 |
mInitialize = true;
|
|
118 |
}
|
|
119 |
}
|
|
120 |
}
|
|
121 |
|
|
122 |
/*!
|
|
123 |
Updates displayed time.
|
|
124 |
*/
|
|
125 |
void SnsrOledAnalogClockContainer::update()
|
|
126 |
{
|
|
127 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::update")
|
|
128 |
|
|
129 |
// time
|
|
130 |
mOledClockWidget->tick();
|
|
131 |
|
|
132 |
// date
|
|
133 |
if (mCurrentOrientation == Qt::Vertical) {
|
|
134 |
mDateLabel->setPlainText(
|
|
135 |
HbExtendedLocale().format(QDate::currentDate(), gDateFormatVerticalStr)
|
|
136 |
);
|
|
137 |
} else {
|
|
138 |
mDateLabel->setPlainText(
|
|
139 |
HbExtendedLocale().format(QDate::currentDate(), gDateFormatHorizontalStr)
|
|
140 |
);
|
|
141 |
}
|
|
142 |
|
|
143 |
// position
|
|
144 |
updatePosition();
|
|
145 |
|
|
146 |
// TODO: Currently, both time and position are updated 10 times per second.
|
|
147 |
// These should happen only once per minute in the power save mode.
|
|
148 |
|
|
149 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::update")
|
|
150 |
}
|
|
151 |
|
|
152 |
/*!
|
|
153 |
Changes screensaver layout basing on orientation changes.
|
|
154 |
\param orientation Current orientation.
|
|
155 |
*/
|
|
156 |
void SnsrOledAnalogClockContainer::changeLayout(Qt::Orientation orientation)
|
|
157 |
{
|
|
158 |
SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::changeLayout")
|
|
159 |
|
|
160 |
bool ok(false);
|
|
161 |
if (mCurrentOrientation != orientation) {
|
|
162 |
mCurrentOrientation = orientation;
|
|
163 |
// hide controls to avoid screen flickering
|
|
164 |
mMainView->hide();
|
|
165 |
|
|
166 |
QString sectionToLoad("");
|
|
167 |
if (mCurrentOrientation == Qt::Horizontal) {
|
|
168 |
sectionToLoad = gLandscapeSectionName;
|
|
169 |
}
|
|
170 |
qDebug() << "loading: " << gOledAnalogLayoutDocml << ", section: " << sectionToLoad;
|
|
171 |
mDocumentLoader.load(gOledAnalogLayoutDocml, sectionToLoad, &ok);
|
|
172 |
Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid section in DocML file.");
|
|
173 |
|
|
174 |
// disconnect container from parent layout,
|
|
175 |
// connected container resets its position to the one defined in docml
|
|
176 |
// after label text updates
|
|
177 |
mClockContainer->setParentLayoutItem(0);
|
|
178 |
|
|
179 |
update();
|
|
180 |
|
|
181 |
// view is rebuilt and ready to show
|
|
182 |
mMainView->show();
|
|
183 |
}
|
|
184 |
|
|
185 |
// update anyway - this is needed in situations when screensaver goes to
|
|
186 |
// foreground but layout change did not occur
|
|
187 |
if (!ok) {
|
|
188 |
update();
|
|
189 |
}
|
|
190 |
|
|
191 |
SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::changeLayout")
|
|
192 |
}
|
|
193 |
|
|
194 |
int SnsrOledAnalogClockContainer::updateIntervalInMilliseconds()
|
|
195 |
{
|
|
196 |
return 60*1000;
|
|
197 |
}
|
|
198 |
|
|
199 |
// end of file
|