|
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 <HbExtendedLocale> |
|
25 #include <HbMainWindow> |
|
26 |
|
27 #include "snsroledclockwidget.h" |
|
28 #include "snsrindicatorwidget.h" |
|
29 #include "snsrlabel.h" |
|
30 |
|
31 /*! |
|
32 \class SnsrOledAnalogClockContainer |
|
33 \ingroup group_snsrbigclockscreensaverplugin |
|
34 \brief Container used for preparing layout for oled analog clock. |
|
35 */ |
|
36 |
|
37 const char *gOledAnalogLayoutDocml = ":/xml/snsrbigclockscreensaveroledanalog.docml"; |
|
38 extern const char *gPortraitSectionName; |
|
39 extern const char *gLandscapeSectionName; |
|
40 |
|
41 extern const char *gMainViewName; |
|
42 extern const char *gMainContainerName; |
|
43 extern const char *gClockContainerName; |
|
44 extern const char *gIndicatorWidgetName; |
|
45 |
|
46 extern const char *gDateLabelName; |
|
47 extern const char *gDateFormatStr; |
|
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 SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::SnsrOledAnalogClockContainer") |
|
61 } |
|
62 |
|
63 /*! |
|
64 Destructs the class. |
|
65 */ |
|
66 SnsrOledAnalogClockContainer::~SnsrOledAnalogClockContainer() |
|
67 { |
|
68 resetIndicatorConnections(); |
|
69 //mOledClockWidget etc - deleted by the parent |
|
70 } |
|
71 |
|
72 /*! |
|
73 Updates OLED analog clock widget position. |
|
74 */ |
|
75 void SnsrOledAnalogClockContainer::updatePosition() |
|
76 { |
|
77 QSizeF containerSize = mMainContainer->size(); |
|
78 |
|
79 // Container must have a valid size to enable calculating the |
|
80 // destination position for the clock. |
|
81 if ( containerSize.width() > 0 && containerSize.height() > 0 ) { |
|
82 containerSize -= mClockContainer->size(); |
|
83 QRectF containerRect( mMainContainer->pos(), containerSize ); |
|
84 if ( mInitialize ) { |
|
85 // disconnect container from parent layout, |
|
86 // connected container resets its position to the one defined in docml |
|
87 // after label text updates |
|
88 mClockContainer->setParentLayoutItem(0); |
|
89 |
|
90 QPointF clockPos = nextRandomPosition( mClockContainer->pos(), mDestPosition, containerRect ); |
|
91 mClockContainer->setPos( clockPos ); |
|
92 } |
|
93 else { |
|
94 mDestPosition = randomPosition( containerRect ); |
|
95 mInitialize = true; |
|
96 } |
|
97 } |
|
98 } |
|
99 |
|
100 /*! |
|
101 Updates displayed time. |
|
102 */ |
|
103 void SnsrOledAnalogClockContainer::update() |
|
104 { |
|
105 SCREENSAVER_TEST_FUNC_ENTRY("SnsrOledAnalogClockContainer::update") |
|
106 |
|
107 // time |
|
108 mOledClockWidget->tick(); |
|
109 |
|
110 // date |
|
111 mDateLabel->setPlainText( |
|
112 HbExtendedLocale().format(QDate::currentDate(), gDateFormatStr) |
|
113 ); |
|
114 |
|
115 // position |
|
116 updatePosition(); |
|
117 |
|
118 SCREENSAVER_TEST_FUNC_EXIT("SnsrOledAnalogClockContainer::update") |
|
119 } |
|
120 |
|
121 int SnsrOledAnalogClockContainer::updateIntervalInMilliseconds() |
|
122 { |
|
123 return 60*1000; |
|
124 } |
|
125 |
|
126 /*! |
|
127 @copydoc Screensaver::DisplayPowerMode() |
|
128 */ |
|
129 Screensaver::ScreenPowerMode SnsrOledAnalogClockContainer::displayPowerMode() |
|
130 { |
|
131 return Screensaver::ScreenModeLowPower; |
|
132 } |
|
133 |
|
134 /*! |
|
135 @copydoc SnsrBigClockContainer::getActiveScreenRows() |
|
136 */ |
|
137 void SnsrOledAnalogClockContainer::getActiveScreenRows(int *firstActiveRow, int *lastActiveRow) |
|
138 { |
|
139 if ( mClockContainer ) { |
|
140 QRect clockRect( mClockContainer->pos().toPoint(), |
|
141 mClockContainer->size().toSize() ); |
|
142 if ( mCurrentOrientation == Qt::Vertical ) { |
|
143 *firstActiveRow = clockRect.top(); |
|
144 *lastActiveRow = clockRect.bottom() + 1; |
|
145 } |
|
146 else { |
|
147 *firstActiveRow = clockRect.left(); |
|
148 *lastActiveRow = clockRect.right() + 1; |
|
149 } |
|
150 } |
|
151 } |
|
152 |
|
153 /*! |
|
154 Orientation is locked in power save mode as sensors are off anyway, |
|
155 at least after some timeout. |
|
156 */ |
|
157 bool SnsrOledAnalogClockContainer::isOrientationLocked() |
|
158 { |
|
159 return true; |
|
160 } |
|
161 |
|
162 void SnsrOledAnalogClockContainer::loadWidgets() |
|
163 { |
|
164 bool ok(true); |
|
165 |
|
166 // reset widget pointers, any previous widgets are already deleted by now |
|
167 mMainView = 0; |
|
168 mMainContainer = 0; |
|
169 mClockContainer = 0; |
|
170 mOledClockWidget = 0; |
|
171 mDateLabel = 0; |
|
172 mIndicatorWidget = 0; |
|
173 mInitialize = false; |
|
174 |
|
175 // load widgets from docml |
|
176 qDebug() << gOledAnalogLayoutDocml; |
|
177 mDocumentObjects = mDocumentLoader.load(gOledAnalogLayoutDocml, &ok); |
|
178 Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid DocML file."); |
|
179 if (ok) { |
|
180 mMainView = mDocumentLoader.findWidget(gMainViewName); |
|
181 mMainContainer = mDocumentLoader.findWidget(gMainContainerName); |
|
182 mClockContainer = mDocumentLoader.findWidget(gClockContainerName); |
|
183 mOledClockWidget = qobject_cast<SnsrOledClockWidget *>( |
|
184 mDocumentLoader.findWidget(gOledAnalogClockWidgetName)); |
|
185 mDateLabel = qobject_cast<SnsrLabel *>( |
|
186 mDocumentLoader.findWidget(gDateLabelName)); |
|
187 mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>( |
|
188 mDocumentLoader.findWidget(gIndicatorWidgetName)); |
|
189 Q_ASSERT_X( |
|
190 mMainView && mMainContainer && mClockContainer |
|
191 && mOledClockWidget && mDateLabel && mIndicatorWidget, |
|
192 gOledAnalogLayoutDocml, "Objects not found in DocML file." |
|
193 ); |
|
194 |
|
195 // In case of landscape layout, read also the landscape delta section |
|
196 if ( mCurrentOrientation == Qt::Horizontal ) { |
|
197 qDebug() << "loading: " << gOledAnalogLayoutDocml << ", section: " << gLandscapeSectionName; |
|
198 mDocumentLoader.load(gOledAnalogLayoutDocml, gLandscapeSectionName, &ok); |
|
199 Q_ASSERT_X(ok, gOledAnalogLayoutDocml, "Invalid section in DocML file."); |
|
200 } |
|
201 |
|
202 mIndicatorWidget->setIconColorType(SnsrIndicatorWidget::FixedColorForPowerSaveMode); |
|
203 connectIndicatorWidgetToModel(); |
|
204 |
|
205 mDateLabel->setTextColorType(SnsrLabel::FixedColorForPowerSaveMode); |
|
206 |
|
207 mBackgroundContainerLayout->addItem(mMainView); |
|
208 } |
|
209 } |
|
210 |
|
211 // end of file |