19 |
19 |
20 #include <QDebug> |
20 #include <QDebug> |
21 #include <QTime> |
21 #include <QTime> |
22 #include <QGraphicsLinearLayout> |
22 #include <QGraphicsLinearLayout> |
23 |
23 |
24 #include <hblabel.h> |
24 #include <HbExtendedLocale> |
25 #include <hbextendedlocale.h> |
25 #include <HbMainWindow> |
26 |
26 |
27 #include "snsrswipewidget.h" |
27 #include "snsrswipewidget.h" |
28 #include "snsrindicatorwidget.h" |
28 #include "snsrindicatorwidget.h" |
|
29 #include "snsrlabel.h" |
29 |
30 |
30 /*! |
31 /*! |
31 \class SnsrDigitalClockContainer |
32 \class SnsrDigitalClockContainer |
32 \ingroup group_snsrbigclockscreensaverplugin |
33 \ingroup group_snsrbigclockscreensaverplugin |
33 \brief Container used for preparing layout for digital clock. |
34 \brief Container used for preparing layout for digital clock. |
64 mAmPmLabel(0), |
65 mAmPmLabel(0), |
65 mDateLabel(0)/*, |
66 mDateLabel(0)/*, |
66 mSwipeWidget(0)*/ |
67 mSwipeWidget(0)*/ |
67 { |
68 { |
68 SCREENSAVER_TEST_FUNC_ENTRY("SnsrDigitalClockContainer::SnsrDigitalClockContainer") |
69 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") |
70 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::SnsrDigitalClockContainer") |
105 } |
71 } |
106 |
72 |
107 /*! |
73 /*! |
108 Destructs the class. |
74 Destructs the class. |
109 */ |
75 */ |
110 SnsrDigitalClockContainer::~SnsrDigitalClockContainer() |
76 SnsrDigitalClockContainer::~SnsrDigitalClockContainer() |
111 { |
77 { |
|
78 resetIndicatorConnections(); |
112 //mTimeLabel, mAmPmLabel, mDateLabel - deleted by the parent |
79 //mTimeLabel, mAmPmLabel, mDateLabel - deleted by the parent |
113 } |
80 } |
114 |
81 |
115 /*! |
82 /*! |
116 Updates displayed time and date. |
83 Updates displayed time and date. |
128 // However it seems to be recommended to use hbExtendedLocale to get |
95 // However it seems to be recommended to use hbExtendedLocale to get |
129 // proper time formatting for all locales and settings.. |
96 // proper time formatting for all locales and settings.. |
130 mTimeLabel->setPlainText( |
97 mTimeLabel->setPlainText( |
131 HbExtendedLocale().format(QTime::currentTime(), gTimeFormatStr) |
98 HbExtendedLocale().format(QTime::currentTime(), gTimeFormatStr) |
132 ); |
99 ); |
133 // if clock type is 24, this will return an empty string. |
100 |
|
101 // if clock type is 24h, this will return an empty string. |
134 mAmPmLabel->setPlainText( |
102 mAmPmLabel->setPlainText( |
135 HbExtendedLocale().format(QTime::currentTime(), gAmPmFormatStr) |
103 HbExtendedLocale().format(QTime::currentTime(), gAmPmFormatStr) |
136 ); |
104 ); |
137 |
105 |
138 // date |
106 // date |
149 } |
117 } |
150 |
118 |
151 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::update") |
119 SCREENSAVER_TEST_FUNC_EXIT("SnsrDigitalClockContainer::update") |
152 } |
120 } |
153 |
121 |
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() |
122 int SnsrDigitalClockContainer::updateIntervalInMilliseconds() |
191 { |
123 { |
192 return 1000; |
124 return 1000; |
193 } |
125 } |
194 |
126 |
|
127 void SnsrDigitalClockContainer::loadWidgets() |
|
128 { |
|
129 // reset widget pointers, any previous widgets are already deleted by now |
|
130 mMainView = 0; |
|
131 mDateLabel = 0; |
|
132 mTimeLabel = 0; |
|
133 mAmPmLabel = 0; |
|
134 mIndicatorWidget = 0; |
|
135 |
|
136 // load widgets from docml |
|
137 bool ok(false); |
|
138 qDebug() << gDigitalLayoutDocml; |
|
139 mDocumentObjects = mDocumentLoader.load(gDigitalLayoutDocml, &ok); |
|
140 Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid DocML file."); |
|
141 |
|
142 if (ok) { |
|
143 mMainView = mDocumentLoader.findWidget(gMainViewName); |
|
144 mDateLabel = qobject_cast<SnsrLabel *>( |
|
145 mDocumentLoader.findWidget(gDateLabelName)); |
|
146 mTimeLabel = qobject_cast<SnsrLabel *>( |
|
147 mDocumentLoader.findWidget(gTimeLabelName)); |
|
148 mAmPmLabel = qobject_cast<SnsrLabel *>( |
|
149 mDocumentLoader.findWidget(gAmPmLabelName)); |
|
150 mIndicatorWidget = qobject_cast<SnsrIndicatorWidget *>( |
|
151 mDocumentLoader.findWidget(gIndicatorWidgetName)); |
|
152 // implement swipewidget later on |
|
153 /*mSwipeWidget = qobject_cast<SnsrSwipeWidget *>( |
|
154 mDocumentLoader.findWidget(gSwipeWidgetName));*/ |
|
155 |
|
156 Q_ASSERT_X( |
|
157 mMainView && mDateLabel && mTimeLabel && mAmPmLabel && |
|
158 mIndicatorWidget /*&& mSwipeWidget*/, |
|
159 gDigitalLayoutDocml, "Objects not found in DocML file." |
|
160 ); |
|
161 |
|
162 // In case of landscape layout, read also the landscape delta section |
|
163 if ( mCurrentOrientation == Qt::Horizontal ) { |
|
164 qDebug() << "loading: " << gDigitalLayoutDocml << ", section: " << gLandscapeSectionName; |
|
165 mDocumentLoader.load(gDigitalLayoutDocml, gLandscapeSectionName, &ok); |
|
166 Q_ASSERT_X(ok, gDigitalLayoutDocml, "Invalid section in DocML file."); |
|
167 } |
|
168 |
|
169 mIndicatorWidget->setLayoutType(SnsrIndicatorWidget::IndicatorsCentered); |
|
170 initIndicatorWidget(); |
|
171 |
|
172 mBackgroundContainerLayout->addItem(mMainView); |
|
173 |
|
174 //connect( mSwipeWidget, SIGNAL(swipeDownDetected()), SIGNAL(unlockRequested()) ); |
|
175 //mSwipeWidget->start(); |
|
176 } |
|
177 } |
|
178 |