17 |
17 |
18 #include <QApplication> |
18 #include <QApplication> |
19 |
19 |
20 #include <HbInstance> |
20 #include <HbInstance> |
21 #include <HbMainWindow> |
21 #include <HbMainWindow> |
22 #include <HbDeviceProfile> |
22 #include <hbevent.h> |
23 |
23 |
24 #include "hsdomainmodeldatastructures.h" |
24 #include "hsdomainmodeldatastructures.h" |
25 #include "hsscene.h" |
25 #include "hsscene.h" |
26 #include "hspage.h" |
26 #include "hspage.h" |
27 #include "hswidgethost.h" |
27 #include "hswidgethost.h" |
28 #include "hsdatabase.h" |
28 #include "hsdatabase.h" |
29 #include "hswallpaper.h" |
29 #include "hswallpaper.h" |
30 #include "hsconfiguration.h" |
30 #include "hsconfiguration.h" |
31 |
31 |
|
32 |
|
33 /*! |
|
34 \class HsScene |
|
35 \ingroup group_hsdomainmodel |
|
36 \brief Represents a scene in the framework. |
|
37 HsScene can have a wallpaper. |
|
38 */ |
|
39 |
32 /*! |
40 /*! |
33 Destructor. |
41 Destructor. |
34 */ |
42 */ |
35 HsScene::~HsScene() |
43 HsScene::~HsScene() |
36 { |
44 { |
56 HsSceneData sceneData; |
64 HsSceneData sceneData; |
57 if (!db->scene(sceneData)) { |
65 if (!db->scene(sceneData)) { |
58 return false; |
66 return false; |
59 } |
67 } |
60 |
68 |
61 mMaximumPageCount = HsConfiguration::maximumPageCount(); |
69 mDatabaseId = sceneData.id; |
62 |
|
63 calculateWidgetSizeLimitations(); |
|
64 |
|
65 if (sceneData.portraitWallpaper.isEmpty()) { |
|
66 mWallpaper->setImagesById(); |
|
67 } else { |
|
68 mWallpaper->setImagesByPaths( |
|
69 sceneData.landscapeWallpaper, |
|
70 sceneData.portraitWallpaper); |
|
71 } |
|
72 |
70 |
73 QList<HsPageData> pageDatas; |
71 QList<HsPageData> pageDatas; |
74 if (!db->pages(pageDatas) || pageDatas.empty()) { |
72 if (!db->pages(pageDatas) || pageDatas.empty()) { |
75 return false; |
73 return false; |
76 } |
74 } |
77 |
75 |
|
76 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::SceneWallpaper) { |
|
77 mWallpaper = new HsSceneWallpaper(this); |
|
78 } |
|
79 |
78 foreach (HsPageData pageData, pageDatas) { |
80 foreach (HsPageData pageData, pageDatas) { |
79 HsPage *page = new HsPage; |
81 HsPage *page = new HsPage; |
80 page->setDatabaseId(pageData.id); |
82 page->setDatabaseId(pageData.id); |
81 if (page->load()) { |
83 if (page->load()) { |
82 mPages.append(page); |
84 mPages.append(page); |
83 } else { |
85 } else { |
84 delete page; |
86 delete page; |
85 continue; |
87 continue; |
86 } |
88 } |
87 if (pageData.id == HsConfiguration::defaultPageId()) { |
89 if (pageData.id == HSCONFIGURATION_GET(defaultPageId)) { |
88 mActivePage = page; |
90 mActivePage = page; |
89 mActivePage->setRemovable(false); |
91 mActivePage->setRemovable(false); |
90 } |
92 } |
91 } |
93 } |
92 |
94 |
93 QApplication::instance()->installEventFilter(this); |
|
94 |
|
95 return true; |
95 return true; |
96 } |
96 } |
97 |
97 |
98 /*! |
98 /*! |
99 Calculate maximum and minimum widget sizes |
99 Return wallpaper. |
100 */ |
|
101 void HsScene::calculateWidgetSizeLimitations() |
|
102 { |
|
103 // 1un = 6.7px = 2mm |
|
104 mMaximumWidgetSizeInUnits = QSizeF(HsConfiguration::maximumWidgetWidth(), |
|
105 HsConfiguration::maximumWidgetHeight()); |
|
106 mMinimumWidgetSizeInUnits = QSizeF(HsConfiguration::minimumWidgetWidth(), |
|
107 HsConfiguration::minimumWidgetHeight()); |
|
108 HbDeviceProfile profile; |
|
109 qreal unitToPixelFactor = profile.unitValue(); |
|
110 mMaximumWidgetSizeInPixels = unitToPixelFactor * mMaximumWidgetSizeInUnits; |
|
111 mMinimumWidgetSizeInPixels = unitToPixelFactor * mMinimumWidgetSizeInUnits; |
|
112 } |
|
113 |
|
114 /*! |
|
115 Return wallpaper. |
|
116 */ |
100 */ |
117 HsWallpaper *HsScene::wallpaper() const |
101 HsWallpaper *HsScene::wallpaper() const |
118 { |
102 { |
119 return mWallpaper; |
103 return mWallpaper; |
120 } |
104 } |
124 */ |
108 */ |
125 QList<HsPage *> HsScene::pages() const |
109 QList<HsPage *> HsScene::pages() const |
126 { |
110 { |
127 return mPages; |
111 return mPages; |
128 } |
112 } |
129 |
113 |
130 /*! |
114 /*! |
131 Add page \a page. |
115 Add page \a page. |
132 */ |
116 */ |
133 bool HsScene::addPage(HsPage *page) |
117 bool HsScene::addPage(HsPage *page) |
134 { |
118 { |
135 if (!page) { |
119 if (!page) { |
136 return false; |
120 return false; |
137 } |
121 } |
138 |
122 |
139 if (mPages.contains(page)) { |
123 if (mPages.contains(page)) { |
140 return true; |
124 return true; |
141 } |
125 } |
142 |
126 |
143 HsDatabase *db = HsDatabase::instance(); |
127 HsDatabase *db = HsDatabase::instance(); |
144 |
128 |
145 HsPageData data; |
129 HsPageData data; |
146 data.id = page->databaseId(); |
130 data.id = page->databaseId(); |
147 if (!db->page(data)) { |
131 if (!db->page(data)) { |
148 return false; |
132 return false; |
149 } |
133 } |
203 db->commit(); |
187 db->commit(); |
204 |
188 |
205 mPages.removeOne(page); |
189 mPages.removeOne(page); |
206 return true; |
190 return true; |
207 } |
191 } |
208 |
192 |
209 /*! |
193 /*! |
210 Set active page \a page. |
194 Set active page \a page. |
211 */ |
195 */ |
212 bool HsScene::setActivePage(HsPage *page) |
196 bool HsScene::setActivePage(HsPage *page) |
213 { |
197 { |
214 if (!page) { |
198 if (!page) { |
215 return false; |
199 return false; |
216 } |
200 } |
217 |
201 |
218 if (!mPages.contains(page)) { |
202 if (!mPages.contains(page)) { |
219 return false; |
203 return false; |
220 } |
204 } |
221 |
205 |
222 if (page == mActivePage) { |
206 if (page == mActivePage) { |
223 return true; |
207 return true; |
224 } |
208 } |
225 |
209 |
226 mActivePage = page; |
210 mActivePage = page; |
|
211 emit activePageChanged(); |
227 |
212 |
228 foreach (HsPage *p, mPages) { |
213 foreach (HsPage *p, mPages) { |
229 if (p == mActivePage) { |
214 if (p == mActivePage) { |
230 p->showWidgets(); |
215 p->showWidgets(); |
231 } else { |
216 } else { |
262 { |
247 { |
263 return mPages.indexOf(mActivePage); |
248 return mPages.indexOf(mActivePage); |
264 } |
249 } |
265 |
250 |
266 /*! |
251 /*! |
267 Return maximum number of pages. |
|
268 */ |
|
269 int HsScene::maximumPageCount() const |
|
270 { |
|
271 return mMaximumPageCount; |
|
272 } |
|
273 |
|
274 /*! |
|
275 Return maximum widget size in pixels. |
|
276 */ |
|
277 QSizeF HsScene::maximumWidgetSizeInPixels() const |
|
278 { |
|
279 return mMaximumWidgetSizeInPixels; |
|
280 } |
|
281 |
|
282 /*! |
|
283 Return minimum widget size in pixels. |
|
284 */ |
|
285 QSizeF HsScene::minimumWidgetSizeInPixels() const |
|
286 { |
|
287 return mMinimumWidgetSizeInPixels; |
|
288 } |
|
289 |
|
290 /*! |
|
291 Return maximum widget size in units. |
|
292 */ |
|
293 QSizeF HsScene::maximumWidgetSizeInUnits() const |
|
294 { |
|
295 return mMaximumWidgetSizeInUnits; |
|
296 } |
|
297 |
|
298 /*! |
|
299 Return minimum widget size in units. |
|
300 */ |
|
301 QSizeF HsScene::minimumWidgetSizeInUnits() const |
|
302 { |
|
303 return mMinimumWidgetSizeInUnits; |
|
304 } |
|
305 |
|
306 /*! |
|
307 Set active widget \a widget. |
252 Set active widget \a widget. |
308 */ |
253 */ |
309 void HsScene::setActiveWidget(HsWidgetHost *widget) |
254 void HsScene::setActiveWidget(HsWidgetHost *widget) |
310 { |
255 { |
311 mActiveWidget = widget; |
256 mActiveWidget = widget; |
312 } |
257 } |
313 |
258 |
314 /*! |
259 /*! |
315 Return active widget. |
260 Return active widget. |
316 */ |
261 */ |
317 HsWidgetHost *HsScene::activeWidget() const |
262 HsWidgetHost *HsScene::activeWidget() const |
318 { |
263 { |
319 return mActiveWidget; |
264 return mActiveWidget; |
320 } |
265 } |
321 /*! |
266 /*! |
322 Toggle application online state. Defaults |
267 Toggle application online state. Defaults |
323 to true. |
268 to true. |
324 */ |
269 */ |
325 void HsScene::setOnline(bool online) |
270 void HsScene::setOnline(bool online) |
326 { |
271 { |
327 mIsOnline = online; |
272 mIsOnline = online; |
337 { |
282 { |
338 return mIsOnline; |
283 return mIsOnline; |
339 } |
284 } |
340 |
285 |
341 /*! |
286 /*! |
342 Singleton. |
287 Singleton. |
343 */ |
288 */ |
344 HsScene *HsScene::instance() |
289 HsScene *HsScene::instance() |
345 { |
290 { |
346 if (!mInstance) { |
|
347 mInstance = new HsScene; |
|
348 mInstance->setParent(HsScene::mainWindow()); |
|
349 } |
|
350 return mInstance; |
291 return mInstance; |
351 } |
292 } |
352 |
293 |
|
294 HsScene *HsScene::takeInstance() |
|
295 { |
|
296 HsScene *instance = mInstance; |
|
297 mInstance = 0; |
|
298 return instance; |
|
299 } |
|
300 |
|
301 void HsScene::setInstance(HsScene *instance) |
|
302 { |
|
303 if (mInstance != instance) { |
|
304 delete mInstance; |
|
305 mInstance = instance; |
|
306 } |
|
307 } |
|
308 |
353 /*! |
309 /*! |
354 Return main window. |
310 Return main window. |
355 */ |
311 */ |
356 HbMainWindow *HsScene::mainWindow() |
312 HbMainWindow *HsScene::mainWindow() |
357 { |
313 { |
369 /*! |
325 /*! |
370 Listens for application background/foreground changes. |
326 Listens for application background/foreground changes. |
371 */ |
327 */ |
372 bool HsScene::eventFilter(QObject *watched, QEvent *event) |
328 bool HsScene::eventFilter(QObject *watched, QEvent *event) |
373 { |
329 { |
374 switch (event->type()) { |
330 if (event->type() == QEvent::ApplicationDeactivate && !mIsBackground) { |
375 case QEvent::ApplicationActivate: |
331 qDebug() << "QEvent::ApplicationDeactivate: calling hide for active page widgets"; |
|
332 mActivePage->hideWidgets(); |
|
333 mIsBackground = true; |
|
334 } else if (event->type() == QEvent::ApplicationActivate && mIsBackground) { |
|
335 if(!mIsSleeping) { |
|
336 qDebug() << "QEvent::ApplicationActivate: not sleeping, calling show for active page widgets"; |
376 mActivePage->showWidgets(); |
337 mActivePage->showWidgets(); |
377 break; |
338 } |
378 case QEvent::ApplicationDeactivate: |
339 mIsBackground = false; |
379 mActivePage->hideWidgets(); |
340 } else if (event->type() == HbEvent::SleepModeEnter && !mIsSleeping) { |
380 break; |
341 qDebug() << "HbEvent::SleepModeEnter: calling hide for active page widgets"; |
381 default: |
342 mActivePage->hideWidgets(); |
382 break; |
343 mIsSleeping = true; |
383 } |
344 } else if (event->type() == HbEvent::SleepModeExit && mIsSleeping) { |
|
345 if(!mIsBackground) { |
|
346 qDebug() << "HbEvent::SleepModeExit: in foreground, calling show for active page widgets"; |
|
347 mActivePage->showWidgets(); |
|
348 } |
|
349 mIsSleeping = false; |
|
350 } |
|
351 |
384 return QObject::eventFilter(watched, event); |
352 return QObject::eventFilter(watched, event); |
385 } |
353 } |
386 |
354 |
387 /*! |
355 /*! |
388 Constructor |
356 Constructor |
389 */ |
357 */ |
390 HsScene::HsScene(QObject *parent) |
358 HsScene::HsScene(QObject *parent) |
391 : QObject(parent), |
359 : QObject(parent), |
392 mDatabaseId(-1), |
360 mDatabaseId(-1), |
393 mWallpaper(0), |
361 mWallpaper(0), |
394 mActivePage(0), |
362 mActivePage(0), |
395 mActiveWidget(0), |
363 mActiveWidget(0), |
396 mIsOnline(true), |
364 mIsOnline(true), |
397 mMaximumPageCount(1), |
365 mIsBackground(false), |
398 mMaximumWidgetSizeInPixels(321.6, 261.3), |
366 mIsSleeping(false) |
399 mMinimumWidgetSizeInPixels(58.625, 58.625), |
367 { |
400 mMaximumWidgetSizeInUnits(48, 39), |
|
401 mMinimumWidgetSizeInUnits(8.75, 8.75) |
|
402 { |
|
403 mWallpaper = new HsWallpaper; |
|
404 } |
368 } |
405 |
369 |
406 /*! |
370 /*! |
407 Points to the scene instance. |
371 Points to the scene instance. |
408 */ |
372 */ |