18 #include <HbInstance> |
18 #include <HbInstance> |
19 |
19 |
20 #include "hsdomainmodeldatastructures.h" |
20 #include "hsdomainmodeldatastructures.h" |
21 #include "hspagenewwidgetlayout.h" |
21 #include "hspagenewwidgetlayout.h" |
22 #include "hsscene.h" |
22 #include "hsscene.h" |
|
23 #include "hspage.h" |
23 #include "hsdatabase.h" |
24 #include "hsdatabase.h" |
24 #include "hswidgethost.h" |
25 #include "hswidgethost.h" |
25 #include "hswallpaper.h" |
26 #include "hswallpaper.h" |
26 #include "hswidgetpositioningonwidgetadd.h" |
27 #include "hswidgetpositioningonwidgetadd.h" |
27 #include "hswidgetpositioningonorientationchange.h" |
28 #include "hswidgetpositioningonorientationchange.h" |
111 /* if there is touch point defined (widget added from context menu) |
112 /* if there is touch point defined (widget added from context menu) |
112 then there is only one widget in the list |
113 then there is only one widget in the list |
113 -> set widget center point to this touch point |
114 -> set widget center point to this touch point |
114 */ |
115 */ |
115 if (mTouchPoint != QPointF() && mNewWidgets.count() == 1) { |
116 if (mTouchPoint != QPointF() && mNewWidgets.count() == 1) { |
116 QRectF pageRect = HsScene::mainWindow()->layoutRect(); |
117 QRectF widgetRect = rects.at(0); |
117 qreal widgetX = qBound(qreal(0), mTouchPoint.x() - rects.at(0).width() / 2, pageRect.width() - rects.at(0).width()); |
118 widgetRect.moveCenter(mTouchPoint); |
118 qreal widgetY = qBound(qreal(64), mTouchPoint.y() - rects.at(0).height() / 2, pageRect.height() - rects.at(0).height()); |
119 widgetRect.moveTopLeft(HsScene::instance()->activePage()->adjustedWidgetPosition(widgetRect)); |
119 mNewWidgets.at(0)->setGeometry(widgetX, |
120 mNewWidgets.at(0)->setGeometry(widgetRect); |
120 widgetY, |
|
121 rects.at(0).width(), |
|
122 rects.at(0).height()); |
|
123 /* we have to save widget presentation data here after drawing |
121 /* we have to save widget presentation data here after drawing |
124 to get correct position for later use |
122 to get correct position for later use |
125 */ |
123 */ |
126 mNewWidgets.at(0)->savePresentation(); |
124 mNewWidgets.at(0)->savePresentation(); |
127 } |
125 } |
128 // otherwise calculate position with algorithm |
126 // otherwise calculate position with algorithm |
129 else { |
127 else { |
130 HsWidgetPositioningOnWidgetAdd *algorithm = |
128 HsWidgetPositioningOnWidgetAdd *algorithm = |
131 HsWidgetPositioningOnWidgetAdd::instance(); |
129 HsWidgetPositioningOnWidgetAdd::instance(); |
132 QRectF pageRect = HsScene::mainWindow()->layoutRect(); |
130 QRectF pageRect = HsScene::instance()->activePage()->contentGeometry(); |
133 pageRect.adjust( (qreal)0,(qreal)64,(qreal)0,(qreal)0); |
|
134 QList<QRectF> calculatedRects = |
131 QList<QRectF> calculatedRects = |
135 algorithm->convert(pageRect, rects, QPointF()); |
132 algorithm->convert(pageRect, rects, QPointF()); |
136 |
133 |
137 for ( int i=0; i<mNewWidgets.count(); i++) { |
134 for ( int i=0; i<mNewWidgets.count(); i++) { |
138 mNewWidgets.at(i)->setGeometry(calculatedRects.at(i)); |
135 mNewWidgets.at(i)->setGeometry(calculatedRects.at(i)); |