62
|
1 |
/*
|
69
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
62
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
#include "hsdomainmodeldatastructures.h"
|
|
19 |
#include "hspagenewwidgetlayout.h"
|
|
20 |
#include "hsscene.h"
|
63
|
21 |
#include "hspage.h"
|
62
|
22 |
#include "hsdatabase.h"
|
|
23 |
#include "hswidgethost.h"
|
69
|
24 |
#include "hswidgethostvisual.h"
|
62
|
25 |
#include "hswallpaper.h"
|
|
26 |
#include "hswidgetpositioningonwidgetadd.h"
|
|
27 |
#include "hswidgetpositioningonorientationchange.h"
|
|
28 |
#include "hsconfiguration.h"
|
69
|
29 |
#include "hsgui.h"
|
62
|
30 |
|
|
31 |
|
|
32 |
/*!
|
|
33 |
\class HsPageNewWidgetLayout
|
|
34 |
\ingroup group_hsdomainmodel
|
|
35 |
\brief Represents a page in the framework.
|
|
36 |
HsPage is a parent for a group of widgets. HsPage can have a wallpaper.
|
|
37 |
*/
|
|
38 |
|
|
39 |
/*!
|
|
40 |
Constructor.
|
|
41 |
|
|
42 |
\a parent Owner.
|
|
43 |
*/
|
|
44 |
HsPageNewWidgetLayout::HsPageNewWidgetLayout(const QPointF &touchPoint,
|
|
45 |
QGraphicsLayoutItem *parent)
|
|
46 |
: QGraphicsLayout(parent),
|
|
47 |
mTouchPoint(touchPoint)
|
90
|
48 |
// add mWidgetRects
|
62
|
49 |
{
|
69
|
50 |
mSize = HsGui::instance()->layoutRect().size();
|
62
|
51 |
}
|
|
52 |
|
|
53 |
/*!
|
|
54 |
Destructor.
|
|
55 |
*/
|
|
56 |
HsPageNewWidgetLayout::~HsPageNewWidgetLayout()
|
|
57 |
{
|
|
58 |
}
|
|
59 |
|
|
60 |
/*!
|
|
61 |
Returns children count.
|
|
62 |
*/
|
|
63 |
int HsPageNewWidgetLayout::count() const
|
|
64 |
{
|
|
65 |
return mNewWidgets.count();
|
|
66 |
}
|
|
67 |
|
|
68 |
/*!
|
|
69 |
Returns item index of \a i.
|
|
70 |
*/
|
|
71 |
QGraphicsLayoutItem *HsPageNewWidgetLayout::itemAt(int i) const
|
|
72 |
{
|
69
|
73 |
return mNewWidgets.at(i)->visual();
|
62
|
74 |
}
|
|
75 |
|
|
76 |
/*!
|
|
77 |
Removes item \a index.
|
|
78 |
*/
|
|
79 |
void HsPageNewWidgetLayout::removeAt(int index)
|
|
80 |
{
|
|
81 |
mNewWidgets.removeAt(index);
|
|
82 |
}
|
|
83 |
|
|
84 |
/*!
|
|
85 |
Size hint.
|
|
86 |
*/
|
|
87 |
QSizeF HsPageNewWidgetLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
|
|
88 |
{
|
|
89 |
switch (which) {
|
|
90 |
case Qt::MinimumSize:
|
|
91 |
case Qt::PreferredSize:
|
|
92 |
return mSize;
|
|
93 |
case Qt::MaximumSize:
|
|
94 |
return mSize;
|
|
95 |
default:
|
|
96 |
break;
|
|
97 |
}
|
|
98 |
return constraint;
|
|
99 |
}
|
|
100 |
|
|
101 |
/*!
|
|
102 |
Recalculates children positions.
|
|
103 |
*/
|
|
104 |
void HsPageNewWidgetLayout::setGeometry(const QRectF &rect)
|
|
105 |
{
|
|
106 |
QGraphicsLayout::setGeometry(rect);
|
69
|
107 |
|
|
108 |
// get rects for new widgets
|
|
109 |
QList<QRectF> newRects;
|
62
|
110 |
foreach (HsWidgetHost *newWidget, mNewWidgets) {
|
69
|
111 |
newRects << QRectF(QPointF(), newWidget->visual()->preferredSize());
|
95
|
112 |
// temp fix for double setGeometry call
|
|
113 |
QRectF defaultRect = QRectF(0,0,58.625, 58.625);
|
|
114 |
if (QRectF(QPointF(), newWidget->visual()->preferredSize()) == defaultRect) {
|
|
115 |
return;
|
|
116 |
}
|
62
|
117 |
}
|
|
118 |
|
|
119 |
/* if there is touch point defined (widget added from context menu)
|
|
120 |
then there is only one widget in the list
|
|
121 |
-> set widget center point to this touch point
|
|
122 |
*/
|
90
|
123 |
if (mTouchPoint != QPointF() && newRects.count() == 1) {
|
69
|
124 |
QRectF widgetRect = newRects.at(0);
|
63
|
125 |
widgetRect.moveCenter(mTouchPoint);
|
|
126 |
widgetRect.moveTopLeft(HsScene::instance()->activePage()->adjustedWidgetPosition(widgetRect));
|
69
|
127 |
mNewWidgets.at(0)->visual()->setGeometry(widgetRect);
|
62
|
128 |
/* we have to save widget presentation data here after drawing
|
|
129 |
to get correct position for later use
|
|
130 |
*/
|
|
131 |
mNewWidgets.at(0)->savePresentation();
|
|
132 |
}
|
69
|
133 |
// otherwise calculate widget positions with algorithm
|
62
|
134 |
else {
|
69
|
135 |
// get page rect
|
|
136 |
QRectF pageRect = HsScene::instance()->activePage()->contentGeometry();
|
|
137 |
|
|
138 |
// scan existing widgets rects
|
|
139 |
QList<HsWidgetHost*> existingWidgets;
|
|
140 |
existingWidgets = HsScene::instance()->activePage()->widgets();
|
|
141 |
QList<QRectF> existingRects;
|
|
142 |
foreach (HsWidgetHost *widget, existingWidgets) {
|
|
143 |
if (!mNewWidgets.contains(widget)) {
|
|
144 |
existingRects << QRectF(widget->visual()->pos(), widget->visual()->preferredSize());
|
|
145 |
}
|
|
146 |
}
|
95
|
147 |
|
69
|
148 |
// calculate new widget positions with "stuck 'em all"-algorithm
|
62
|
149 |
HsWidgetPositioningOnWidgetAdd *algorithm =
|
|
150 |
HsWidgetPositioningOnWidgetAdd::instance();
|
95
|
151 |
HsWidgetPositioningOnWidgetAdd::Result result;
|
|
152 |
result = algorithm->convert(pageRect, existingRects, newRects, QPointF());
|
|
153 |
if (result.rectOrder != QList<int>()) {
|
|
154 |
// set new widgets to screen in sorted order and save presentation for each widget
|
|
155 |
for (int i = 0; i < mNewWidgets.count(); i++) {
|
|
156 |
int id = result.rectOrder.at(i);
|
|
157 |
// take visual
|
|
158 |
HsWidgetHostVisual *visual(mNewWidgets.at(id)->visual());
|
|
159 |
visual->setGeometry(result.calculatedRects.at(id));
|
|
160 |
// update z value
|
|
161 |
int zValue = visual->zValue();
|
|
162 |
visual->setZValue(zValue - id + i);
|
|
163 |
mNewWidgets.at(id)->savePresentation();
|
|
164 |
}
|
62
|
165 |
}
|
|
166 |
}
|
|
167 |
}
|
|
168 |
|
|
169 |
/*!
|
|
170 |
Adds item to layout.
|
|
171 |
*/
|
|
172 |
void HsPageNewWidgetLayout::addItem(HsWidgetHost *item)
|
|
173 |
{
|
|
174 |
mNewWidgets.append(item);
|
|
175 |
}
|