|
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 <HbExtendedLocale> |
|
25 #include <HbMainWindow> |
|
26 |
|
27 #include "snsrswipewidget.h" |
|
28 #include "snsrindicatorwidget.h" |
|
29 #include "snsrlabel.h" |
|
30 |
|
31 /*! |
|
32 \class SnsrDigitalClockContainer |
|
33 \ingroup group_snsrbigclockscreensaverplugin |
|
34 \brief Container used for preparing layout for digital clock. |
|
35 */ |
|
36 |
|
37 const char *gDigitalLayoutDocml = ":/xml/snsrbigclockscreensaverdigital.docml"; |
|
38 const char *gSwipeDigitalLayoutDocml = ":/xml/snsrbigclockscreensaverdigitalswipe.docml"; |
|
39 |
|
40 extern const char *gPortraitSectionName; |
|
41 extern const char *gLandscapeSectionName; |
|
42 |
|
43 extern const char *gMainViewName; |
|
44 |
|
45 const char *gTimeLabelName = "timeLabel"; |
|
46 const char *gAmPmLabelName = "amPmLabel"; |
|
47 extern const char *gDateLabelName; |
|
48 |
|
49 extern const char *gDateFormatStr; |
|
50 |
|
51 // This is same as r_qtn_time_usual_with_zero defined in |
|
52 // hbi18ndef.h expect am/pm place holders are removed. |
|
53 const char *gTimeFormatStr = "%:0%J%:1%T%:3"; |
|
54 |
|
55 extern const char *gIndicatorWidgetName; |
|
56 extern const char *gSwipeWidgetName; |
|
57 |
|
58 |
|
59 /*! |
|
60 Constructs a new SnsrDigitalClockContainer. |
|
61 */ |
|
62 SnsrDigitalClockContainer::SnsrDigitalClockContainer() : |
|
63 SnsrBigClockContainer(), |
|
64 mTimeLabel(0), |
|
65 mAmPmLabel(0), |
|
66 mDateLabel(0), |
|
67 mSwipeWidget(0) |
|
68 { |
|
69 SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::SnsrDigitalClockContainer") |
|
70 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::SnsrDigitalClockContainer") |
|
71 } |
|
72 |
|
73 /*! |
|
74 Destructs the class. |
|
75 */ |
|
76 SnsrDigitalClockContainer::~SnsrDigitalClockContainer() |
|
77 { |
|
78 resetIndicatorConnections(); |
|
79 //mTimeLabel, mAmPmLabel, mDateLabel - deleted by the parent |
|
80 } |
|
81 |
|
82 /*! |
|
83 Updates displayed time and date. |
|
84 */ |
|
85 void SnsrDigitalClockContainer::update() |
|
86 { |
|
87 SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::update") |
|
88 |
|
89 HbExtendedLocale locale = HbExtendedLocale::system(); |
|
90 |
|
91 // time |
|
92 // Even though the format string (hh:mm) contain the leading zero, it's |
|
93 // removed always when clock type is 12h -> h:mm. |
|
94 |
|
95 // TODO: within this method call, you find a comment in code that |
|
96 // it's intentional to remove leading zero always with 12h type clock. |
|
97 // However it seems to be recommended to use hbExtendedLocale to get |
|
98 // proper time formatting for all locales and settings.. |
|
99 mTimeLabel->setPlainText( |
|
100 locale.format(QTime::currentTime(), gTimeFormatStr) |
|
101 ); |
|
102 |
|
103 QString amPmString(""); |
|
104 if (locale.timeStyle() == HbExtendedLocale::Time12 ) { |
|
105 amPmString = (QTime::currentTime().hour()<12) ? locale.amText() : locale.pmText(); |
|
106 } |
|
107 mAmPmLabel->setPlainText( amPmString ); |
|
108 |
|
109 // date |
|
110 mDateLabel->setPlainText( |
|
111 locale.format(QDate::currentDate(), gDateFormatStr) |
|
112 ); |
|
113 |
|
114 if (mSwipeWidget) { |
|
115 mSwipeWidget->setCurrentOrientation(mCurrentOrientation); |
|
116 } |
|
117 |
|
118 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::update") |
|
119 } |
|
120 |
|
121 /*! |
|
122 @copydoc SnsrBigClockContainer::updateIntervalInMilliseconds() |
|
123 */ |
|
124 int SnsrDigitalClockContainer::updateIntervalInMilliseconds() |
|
125 { |
|
126 return 1000; |
|
127 } |
|
128 |
|
129 /*! |
|
130 @copydoc SnsrBigClockContainer::loadWidgets() |
|
131 */ |
|
132 void SnsrDigitalClockContainer::loadWidgets() |
|
133 { |
|
134 //if swipe is used we load the docml file containing it |
|
135 if ( swipeToUnlockSupported() ) { |
|
136 loadWidgets(gSwipeDigitalLayoutDocml); |
|
137 Q_ASSERT_X( mSwipeWidget, gSwipeDigitalLayoutDocml, "Swipe widget not found in DocML file."); |
|
138 connect( mSwipeWidget, SIGNAL(swipeDownDetected()), SIGNAL(unlockRequested()) ); |
|
139 } |
|
140 else { |
|
141 loadWidgets(gDigitalLayoutDocml); |
|
142 } |
|
143 } |
|
144 |
|
145 /*! |
|
146 Instantiate widgets from the given docml file |
|
147 */ |
|
148 void SnsrDigitalClockContainer::loadWidgets(const char* docmlName) |
|
149 { |
|
150 bool ok(true); |
|
151 |
|
152 // reset widget pointers, any previous widgets are already deleted by now |
|
153 mMainView = 0; |
|
154 mDateLabel = 0; |
|
155 mTimeLabel = 0; |
|
156 mAmPmLabel = 0; |
|
157 mIndicatorWidget = 0; |
|
158 mSwipeWidget = 0; |
|
159 // load widgets from docml |
|
160 qDebug() << docmlName; |
|
161 mDocumentObjects = mDocumentLoader.load(docmlName, &ok); |
|
162 Q_ASSERT_X(ok, docmlName, "Invalid DocML file."); |
|
163 if (ok) { |
|
164 mMainView = mDocumentLoader.findWidget(gMainViewName); |
|
165 mDateLabel = qobject_cast<SnsrLabel *>( |
|
166 mDocumentLoader.findWidget(gDateLabelName)); |
|
167 mTimeLabel = qobject_cast<SnsrLabel *>( |
|
168 mDocumentLoader.findWidget(gTimeLabelName)); |
|
169 mAmPmLabel = qobject_cast<SnsrLabel *>( |
|
170 mDocumentLoader.findWidget(gAmPmLabelName)); |
|
171 mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>( |
|
172 mDocumentLoader.findWidget(gIndicatorWidgetName)); |
|
173 mSwipeWidget = qobject_cast<SnsrSwipeWidget *>( |
|
174 mDocumentLoader.findWidget(gSwipeWidgetName)); |
|
175 |
|
176 Q_ASSERT_X( |
|
177 mMainView && mDateLabel && mTimeLabel && mAmPmLabel && |
|
178 mIndicatorWidget, |
|
179 docmlName, "Objects not found in DocML file." |
|
180 ); |
|
181 |
|
182 // In case of landscape layout, read also the landscape delta section |
|
183 if ( mCurrentOrientation == Qt::Horizontal ) { |
|
184 qDebug() << "loading: " << docmlName << ", section: " << gLandscapeSectionName; |
|
185 mDocumentLoader.load(docmlName, gLandscapeSectionName, &ok); |
|
186 Q_ASSERT_X(ok, docmlName, "Invalid section in DocML file."); |
|
187 } |
|
188 |
|
189 mIndicatorWidget->setIconColorType(SnsrIndicatorWidget::ThemedColorForActiveMode); |
|
190 connectIndicatorWidgetToModel(); |
|
191 |
|
192 mDateLabel->setTextColorType(SnsrLabel::ThemedColorForActiveMode); |
|
193 mTimeLabel->setTextColorType(SnsrLabel::ThemedColorForActiveMode); |
|
194 mAmPmLabel->setTextColorType(SnsrLabel::ThemedColorForActiveMode); |
|
195 |
|
196 mBackgroundContainerLayout->addItem(mMainView); |
|
197 } |
|
198 } |
|
199 |