20 #include <QGraphicsLinearLayout> |
20 #include <QGraphicsLinearLayout> |
21 #include <HbInstance> |
21 #include <HbInstance> |
22 |
22 |
23 #include "hsdomainmodeldatastructures.h" |
23 #include "hsdomainmodeldatastructures.h" |
24 #include "hspage.h" |
24 #include "hspage.h" |
|
25 #include "hspagenewwidgetlayout.h" |
25 #include "hsscene.h" |
26 #include "hsscene.h" |
26 #include "hsdatabase.h" |
27 #include "hsdatabase.h" |
27 #include "hswidgethost.h" |
28 #include "hswidgethost.h" |
28 #include "hswallpaper.h" |
29 #include "hswallpaper.h" |
29 #include "hswidgetpositioningonwidgetadd.h" |
30 #include "hswidgetpositioningonwidgetadd.h" |
30 #include "hswidgetpositioningonorientationchange.h" |
31 #include "hswidgetpositioningonorientationchange.h" |
|
32 #include "hsconfiguration.h" |
31 |
33 |
32 |
34 |
33 /*! |
35 /*! |
34 \class HsPage |
36 \class HsPage |
35 \ingroup group_hsutils |
37 \ingroup group_hsdomainmodel |
36 \brief Represents a page in the framework. |
38 \brief Represents a page in the framework. |
37 HsPage is a parent for a group of widgets. HsPage can have a wallpaper. |
39 HsPage is a parent for a group of widgets. HsPage can have a wallpaper. |
38 */ |
40 */ |
39 |
41 |
40 /*! |
42 /*! |
44 \a aFlags Window flags. |
46 \a aFlags Window flags. |
45 */ |
47 */ |
46 HsPage::HsPage(QGraphicsItem* parent) |
48 HsPage::HsPage(QGraphicsItem* parent) |
47 : HbWidget(parent), |
49 : HbWidget(parent), |
48 mDatabaseId(-1), |
50 mDatabaseId(-1), |
|
51 mWallpaper(0), |
49 mRemovable(true) |
52 mRemovable(true) |
50 { |
53 { |
51 setFlag(QGraphicsItem::ItemHasNoContents); |
54 setFlag(QGraphicsItem::ItemHasNoContents); |
52 setSizePolicy(QSizePolicy(QSizePolicy::Ignored, |
55 setSizePolicy(QSizePolicy(QSizePolicy::Ignored, |
53 QSizePolicy::Ignored)); |
56 QSizePolicy::Ignored)); |
88 HsDatabase *db = HsDatabase::instance(); |
92 HsDatabase *db = HsDatabase::instance(); |
89 |
93 |
90 QList<HsWidgetData> datas; |
94 QList<HsWidgetData> datas; |
91 if (!db->widgets(mDatabaseId, datas)) { |
95 if (!db->widgets(mDatabaseId, datas)) { |
92 return false; |
96 return false; |
|
97 } |
|
98 |
|
99 if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
|
100 mWallpaper = new HsPageWallpaper(this); |
93 } |
101 } |
94 |
102 |
95 foreach (HsWidgetData data, datas) { |
103 foreach (HsWidgetData data, datas) { |
96 HsWidgetHost *widget = new HsWidgetHost(data.id); |
104 HsWidgetHost *widget = new HsWidgetHost(data.id); |
97 mWidgets.append(widget); |
105 mWidgets.append(widget); |
98 connectWidget(widget); |
106 connectWidget(widget); |
99 widget->setPage(this); |
107 widget->setPage(this); |
100 widget->setParentItem(this); |
108 widget->setParentItem(this); |
101 widget->startWidget(); |
109 widget->startWidget(isDefaultPage()); |
102 } |
110 } |
103 |
111 |
104 connect(HsScene::mainWindow(), |
112 connect(HsScene::mainWindow(), |
105 SIGNAL(orientationChanged(Qt::Orientation)), |
113 SIGNAL(orientationChanged(Qt::Orientation)), |
106 SLOT(onOrientationChanged(Qt::Orientation))); |
114 SLOT(onOrientationChanged(Qt::Orientation))); |
107 |
115 |
108 return true; |
116 return true; |
|
117 } |
|
118 |
|
119 /*! |
|
120 Return wallpaper. |
|
121 */ |
|
122 HsWallpaper *HsPage::wallpaper() const |
|
123 { |
|
124 return mWallpaper; |
109 } |
125 } |
110 |
126 |
111 bool HsPage::addExistingWidget(HsWidgetHost *widgetHost) |
127 bool HsPage::addExistingWidget(HsWidgetHost *widgetHost) |
112 { |
128 { |
113 if (!widgetHost) { |
129 if (!widgetHost) { |
197 rects << newWidget->rect(); |
213 rects << newWidget->rect(); |
198 } |
214 } |
199 |
215 |
200 HsWidgetPositioningOnWidgetAdd *algorithm = |
216 HsWidgetPositioningOnWidgetAdd *algorithm = |
201 HsWidgetPositioningOnWidgetAdd::instance(); |
217 HsWidgetPositioningOnWidgetAdd::instance(); |
|
218 |
|
219 QRectF pageRect = HsScene::mainWindow()->layoutRect(); |
|
220 // chrome needs to be removed from the rect. |
|
221 pageRect.adjust( (qreal)0,(qreal)64,(qreal)0,(qreal)0); |
202 |
222 |
203 QList<QRectF> calculatedRects = |
223 QList<QRectF> calculatedRects = |
204 algorithm->convert(HsScene::mainWindow()->layoutRect(), rects, QPointF()); |
224 algorithm->convert(pageRect, rects, QPointF()); |
205 |
225 |
|
226 HsPageNewWidgetLayout *newWidgetLayout = static_cast<HsPageNewWidgetLayout *>(layout()); |
|
227 if (!newWidgetLayout) { |
|
228 newWidgetLayout = new HsPageNewWidgetLayout(); |
|
229 setLayout(newWidgetLayout); |
|
230 } |
206 updateZValues(); |
231 updateZValues(); |
207 |
|
208 HsWidgetHost *widget = 0; |
232 HsWidgetHost *widget = 0; |
209 for (int i = 0; i < mNewWidgets.count(); ++i) { |
233 for (int i = 0; i < mNewWidgets.count(); ++i) { |
210 widget = mNewWidgets.at(i); |
234 widget = mNewWidgets.at(i); |
|
235 newWidgetLayout->addItem(widget); |
211 widget->setGeometry(calculatedRects.at(i)); |
236 widget->setGeometry(calculatedRects.at(i)); |
212 widget->savePresentation(); |
237 widget->savePresentation(); |
213 widget->setPage(this); |
238 widget->setPage(this); |
214 widget->setParentItem(this); |
239 widget->setParentItem(this); |
215 widget->showWidget(); |
240 widget->showWidget(); |
258 Sets removable flag to \a removable. |
283 Sets removable flag to \a removable. |
259 */ |
284 */ |
260 void HsPage::setRemovable(bool removable) |
285 void HsPage::setRemovable(bool removable) |
261 { |
286 { |
262 mRemovable = removable; |
287 mRemovable = removable; |
|
288 } |
|
289 |
|
290 bool HsPage::isDefaultPage() const |
|
291 { |
|
292 return mDatabaseId == HSCONFIGURATION_GET(defaultPageId); |
263 } |
293 } |
264 |
294 |
265 bool HsPage::isActivePage() const |
295 bool HsPage::isActivePage() const |
266 { |
296 { |
267 return this == HsScene::instance()->activePage(); |
297 return this == HsScene::instance()->activePage(); |
388 { |
418 { |
389 onWidgetFinished(); |
419 onWidgetFinished(); |
390 } |
420 } |
391 |
421 |
392 /*! |
422 /*! |
393 Calculates new widget position on page when widget size changes |
423 Calculates new widget position on page when widget size changes. If page has layout then there are new widgets |
|
424 and we use layout to calculate new widget positions. |
394 */ |
425 */ |
395 void HsPage::onWidgetResized() |
426 void HsPage::onWidgetResized() |
396 { |
427 { |
|
428 if ( !layout() ) { |
|
429 HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
|
430 QRectF widgetRect = widget->geometry(); |
|
431 QRectF pageRect = HsScene::mainWindow()->layoutRect(); |
|
432 qreal widgetX = qBound(qreal(0), widgetRect.x(), pageRect.width() - widgetRect.width()); |
|
433 qreal widgetY = qBound(qreal(64), widgetRect.y(), pageRect.height() - widgetRect.height()); |
|
434 widget->setPos(widgetX, widgetY); |
|
435 } else { |
|
436 layout()->invalidate(); |
|
437 } |
|
438 } |
|
439 |
|
440 void HsPage::onWidgetAvailable() |
|
441 { |
397 HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
442 HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
398 |
443 |
399 QRectF widgetRect = widget->geometry(); |
|
400 |
|
401 QRectF pageRect = HsScene::mainWindow()->layoutRect(); |
|
402 |
|
403 qreal lowerBoundX = 0; |
|
404 |
|
405 qreal upperBoundX = pageRect.width() - widgetRect.width() / 2 - 10; |
|
406 upperBoundX = pageRect.width() - widgetRect.width(); |
|
407 |
|
408 qreal widgetX = qBound(lowerBoundX, widgetRect.x(), upperBoundX); |
|
409 qreal widgetY = qBound(qreal(64), widgetRect.y(), pageRect.height() - widgetRect.height()); |
|
410 |
|
411 widget->setPos(widgetX, widgetY); |
|
412 } |
|
413 |
|
414 void HsPage::onWidgetAvailable() |
|
415 { |
|
416 HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
|
417 |
|
418 mUnavailableWidgets.removeOne(widget); |
444 mUnavailableWidgets.removeOne(widget); |
419 mWidgets.append(widget); |
445 mWidgets.append(widget); |
420 |
446 |
421 widget->setParentItem(this); |
447 widget->setParentItem(this); |
422 widget->startWidget(isActivePage()); |
448 widget->startWidget(isActivePage()); |
423 widget->show(); |
449 widget->show(); |
424 } |
450 } |
425 |
451 |
426 void HsPage::onWidgetUnavailable() |
452 void HsPage::onWidgetUnavailable() |
427 { |
453 { |
428 HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
454 HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
429 |
455 |
430 if (mWidgets.contains(widget)) { |
456 if (mWidgets.contains(widget)) { |
441 widget->setParentItem(0); |
467 widget->setParentItem(0); |
442 } |
468 } |
443 |
469 |
444 void HsPage::onOrientationChanged(Qt::Orientation orientation) |
470 void HsPage::onOrientationChanged(Qt::Orientation orientation) |
445 { |
471 { |
446 QRectF rect = HsScene::mainWindow()->layoutRect(); |
472 QRectF rect = HsScene::mainWindow()->layoutRect(); |
447 |
473 |
448 HsWidgetPositioningOnOrientationChange *converter = |
474 HsWidgetPositioningOnOrientationChange *converter = |
449 HsWidgetPositioningOnOrientationChange::instance(); |
475 HsWidgetPositioningOnOrientationChange::instance(); |
450 |
476 |
451 qreal chrome = 64; |
477 qreal chrome = 64; |
452 QRectF from(0, chrome, rect.height(), rect.width() - chrome); |
478 QRectF from(0, chrome, rect.height(), rect.width() - chrome); |