|
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 digital clock. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "snsrdigitalclockcontainer.h" |
|
19 |
|
20 #include <QDebug> |
|
21 #include <QTime> |
|
22 #include <QGraphicsLinearLayout> |
|
23 |
|
24 #include <hblabel.h> |
|
25 #include <hbextendedlocale.h> |
|
26 |
|
27 #include "snsrswipewidget.h" |
|
28 #include "snsrindicatorwidget.h" |
|
29 |
|
30 /*! |
|
31 \class SnsrDigitalClockContainer |
|
32 \ingroup group_snsrbigclockscreensaverplugin |
|
33 \brief Container used for preparing layout for digital clock. |
|
34 */ |
|
35 |
|
36 const char *gDigitalLayoutDocml = ":/xml/snsrbigclockscreensaverdigital.docml"; |
|
37 extern const char *gPortraitSectionName; |
|
38 extern const char *gLandscapeSectionName; |
|
39 |
|
40 extern const char *gMainViewName; |
|
41 |
|
42 const char *gTimeLabelName = "timeLabel"; |
|
43 const char *gAmPmLabelName = "amPmLabel"; |
|
44 extern const char *gDateLabelName; |
|
45 |
|
46 extern const char *gDateFormatVerticalStr; |
|
47 extern const char *gDateFormatHorizontalStr; |
|
48 |
|
49 // This is same as r_qtn_time_usual_with_zero defined in |
|
50 // hbi18ndef.h expect am/pm place holders are removed. |
|
51 const char *gTimeFormatStr = "%:0%J%:1%T%:3"; |
|
52 const char *gAmPmFormatStr = "%B"; |
|
53 |
|
54 extern const char *gIndicatorWidgetName; |
|
55 extern const char *gSwipeWidgetName; |
|
56 |
|
57 |
|
58 /*! |
|
59 Constructs a new SnsrDigitalClockContainer. |
|
60 */ |
|
61 SnsrDigitalClockContainer::SnsrDigitalClockContainer() : |
|
62 SnsrBigClockContainer(), |
|
63 mTimeLabel(0), |
|
64 mAmPmLabel(0), |
|
65 mDateLabel(0)/*, |
|
66 mSwipeWidget(0)*/ |
|
67 { |
|
68 SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::SnsrDigitalClockContainer") |
|
69 |
|
70 bool ok(false); |
|
71 // load digital clock |
|
72 qDebug() << gDigitalLayoutDocml; |
|
73 mDocumentObjects = mDocumentLoader.load(gDigitalLayoutDocml, &ok); |
|
74 Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid DocML file."); |
|
75 |
|
76 if (ok) { |
|
77 mMainView = mDocumentLoader.findWidget(gMainViewName); |
|
78 mDateLabel = qobject_cast<HbLabel *>( |
|
79 mDocumentLoader.findWidget(gDateLabelName)); |
|
80 mTimeLabel = qobject_cast<HbLabel *>( |
|
81 mDocumentLoader.findWidget(gTimeLabelName)); |
|
82 mAmPmLabel = qobject_cast<HbLabel *>( |
|
83 mDocumentLoader.findWidget(gAmPmLabelName)); |
|
84 mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>( |
|
85 mDocumentLoader.findWidget(gIndicatorWidgetName)); |
|
86 // implement swipewidget later on |
|
87 /*mSwipeWidget = qobject_cast<SnsrSwipeWidget *>( |
|
88 mDocumentLoader.findWidget(gSwipeWidgetName));*/ |
|
89 |
|
90 Q_ASSERT_X( |
|
91 mMainView && mDateLabel && mTimeLabel && mAmPmLabel && |
|
92 mIndicatorWidget /*&& mSwipeWidget*/, |
|
93 gDigitalLayoutDocml, "Objects not found in DocML file." |
|
94 ); |
|
95 |
|
96 //connect( mSwipeWidget, SIGNAL(swipeDownDetected()), SIGNAL(unlockRequested()) ); |
|
97 |
|
98 mIndicatorWidget->setLayoutType(SnsrIndicatorWidget::IndicatorsCentered); |
|
99 |
|
100 mBackgroundContainerLayout->addItem(mMainView); |
|
101 // mSwipeWidget->start(); |
|
102 } |
|
103 |
|
104 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::SnsrDigitalClockContainer") |
|
105 } |
|
106 |
|
107 /*! |
|
108 Destructs the class. |
|
109 */ |
|
110 SnsrDigitalClockContainer::~SnsrDigitalClockContainer() |
|
111 { |
|
112 //mTimeLabel, mAmPmLabel, mDateLabel - deleted by the parent |
|
113 } |
|
114 |
|
115 /*! |
|
116 Updates displayed time and date. |
|
117 */ |
|
118 void SnsrDigitalClockContainer::update() |
|
119 { |
|
120 SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::update") |
|
121 |
|
122 // time |
|
123 // Even though the format string (hh:mm) contain the leading zero, it's |
|
124 // removed always when clock type is 12h -> h:mm. |
|
125 |
|
126 // TODO: within this method call, you find a comment in code that |
|
127 // it's intentional to remove leading zero always with 12h type clock. |
|
128 // However it seems to be recommended to use hbExtendedLocale to get |
|
129 // proper time formatting for all locales and settings.. |
|
130 mTimeLabel->setPlainText( |
|
131 HbExtendedLocale().format(QTime::currentTime(), gTimeFormatStr) |
|
132 ); |
|
133 // if clock type is 24, this will return an empty string. |
|
134 mAmPmLabel->setPlainText( |
|
135 HbExtendedLocale().format(QTime::currentTime(), gAmPmFormatStr) |
|
136 ); |
|
137 |
|
138 // date |
|
139 if (mCurrentOrientation == Qt::Vertical) { |
|
140 mDateLabel->setPlainText( |
|
141 HbExtendedLocale().format( |
|
142 QDate::currentDate(), gDateFormatVerticalStr) |
|
143 ); |
|
144 } else { |
|
145 mDateLabel->setPlainText( |
|
146 HbExtendedLocale().format( |
|
147 QDate::currentDate(), gDateFormatHorizontalStr) |
|
148 ); |
|
149 } |
|
150 |
|
151 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::update") |
|
152 } |
|
153 |
|
154 /*! |
|
155 Changes screensaver layout basing on orientation changes. |
|
156 \param orientation Current orientation. |
|
157 */ |
|
158 void SnsrDigitalClockContainer::changeLayout(Qt::Orientation orientation) |
|
159 { |
|
160 SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::changeLayout") |
|
161 |
|
162 bool ok(false); |
|
163 if (mCurrentOrientation != orientation) { |
|
164 mCurrentOrientation = orientation; |
|
165 |
|
166 // hide controls to avoid screen flickering |
|
167 mMainView->hide(); |
|
168 |
|
169 QString sectionToLoad(""); |
|
170 if (mCurrentOrientation == Qt::Horizontal) { |
|
171 sectionToLoad = gLandscapeSectionName; |
|
172 } |
|
173 qDebug() << "loading: " << gDigitalLayoutDocml << ", section: " |
|
174 << sectionToLoad; |
|
175 mDocumentLoader.load(gDigitalLayoutDocml, sectionToLoad, &ok); |
|
176 // view is rebuilt and ready to show |
|
177 update(); |
|
178 mMainView->show(); |
|
179 Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid section in DocML file."); |
|
180 } |
|
181 // update anyway - this is needed in situations when screensaver goes to |
|
182 // foreground but layout change did not occur |
|
183 if (!ok) { |
|
184 update(); |
|
185 } |
|
186 |
|
187 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::changeLayout") |
|
188 } |
|
189 |
|
190 int SnsrDigitalClockContainer::updateIntervalInMilliseconds() |
|
191 { |
|
192 return 1000; |
|
193 } |
|
194 |