author | hgs |
Mon, 13 Sep 2010 13:03:23 +0300 | |
changeset 86 | e4f038c420f7 |
parent 81 | 7dd137878ff8 |
child 90 | 3ac3aaebaee5 |
permissions | -rw-r--r-- |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
1 |
/* |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
* This component and the accompanying materials are made available |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
* under the terms of "Eclipse Public License v1.0" |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
* which accompanies this distribution, and is available |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
* |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
* Initial Contributors: |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
* Nokia Corporation - initial contribution. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
* |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
* Contributors: |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
* |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
* Description: |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
* |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
|
81 | 18 |
#include <QHash> |
19 |
||
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
#include <HbInstance> |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
|
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
22 |
#include "hsdomainmodeldatastructures.h" |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#include "hspage.h" |
69 | 24 |
#include "hspagevisual.h" |
62 | 25 |
#include "hspagetoucharea.h" |
26 |
#include "hspagenewwidgetlayout.h" |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
27 |
#include "hsscene.h" |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
28 |
#include "hsdatabase.h" |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
29 |
#include "hswidgethost.h" |
69 | 30 |
#include "hswidgethostvisual.h" |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
31 |
#include "hswallpaper.h" |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
32 |
#include "hswidgetpositioningonwidgetadd.h" |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
33 |
#include "hswidgetpositioningonorientationchange.h" |
62 | 34 |
#include "hsconfiguration.h" |
69 | 35 |
#include "hsgui.h" |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
36 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
37 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
38 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
39 |
\class HsPage |
62 | 40 |
\ingroup group_hsdomainmodel |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
41 |
\brief Represents a page in the framework. |
62 | 42 |
HsPage contains group of widgets. HsPage can have a wallpaper. |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
43 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
44 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
45 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
46 |
Constructor. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
47 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
48 |
\a parent Owner. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
49 |
\a aFlags Window flags. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
50 |
*/ |
69 | 51 |
HsPage::HsPage(QObject* parent) |
52 |
: QObject(parent), |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
53 |
mDatabaseId(-1), |
69 | 54 |
mPageVisual(new HsPageVisual), |
62 | 55 |
mWallpaper(0), |
56 |
mRemovable(true), |
|
63 | 57 |
mPageMargin(0.0) |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
58 |
{ |
69 | 59 |
|
63 | 60 |
//Page margin |
61 |
mPageMargin = HSCONFIGURATION_GET(pageMargin); |
|
62 |
connect(HsConfiguration::instance(), SIGNAL(propertyChanged(QString)), SLOT(onPageMarginChanged(QString))); |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
63 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
64 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
65 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
66 |
Destructor. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
67 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
HsPage::~HsPage() |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
69 |
{ |
69 | 70 |
// visuals are owned by widget host, detach those from page visual |
71 |
HsWidgetHostVisual *visual(0); |
|
72 |
foreach (HsWidgetHost *widget, mWidgets) { |
|
73 |
visual = widget->visual(); |
|
74 |
visual->setParent(0); |
|
75 |
if (visual->scene()) { |
|
76 |
visual->scene()->removeItem(visual); |
|
77 |
} |
|
78 |
} |
|
79 |
||
80 |
foreach (HsWidgetHost *widget, mNewWidgets) { |
|
81 |
visual = widget->visual(); |
|
82 |
visual->setParent(0); |
|
83 |
if (visual->scene()) { |
|
84 |
visual->scene()->removeItem(visual); |
|
85 |
} |
|
86 |
} |
|
87 |
||
88 |
foreach (HsWidgetHost *widget, mUnavailableWidgets) { |
|
89 |
visual = widget->visual(); |
|
90 |
visual->setParent(0); |
|
91 |
if (visual->scene()) { |
|
92 |
visual->scene()->removeItem(visual); |
|
93 |
} |
|
94 |
} |
|
95 |
qDeleteAll(mWidgets); |
|
96 |
qDeleteAll(mNewWidgets); |
|
97 |
qDeleteAll(mUnavailableWidgets); |
|
98 |
||
99 |
delete mPageVisual; |
|
62 | 100 |
delete mWallpaper; |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
101 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
102 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
103 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
104 |
Returns the database id. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
105 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
106 |
int HsPage::databaseId() const |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
107 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
108 |
return mDatabaseId; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
109 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
110 |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
111 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
112 |
Sets the database id to \a id. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
113 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
114 |
void HsPage::setDatabaseId(int id) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
115 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
116 |
mDatabaseId = id; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
117 |
} |
69 | 118 |
/* |
62 | 119 |
void HsPage::setGeometry(const QRectF &rect) |
120 |
{ |
|
121 |
if (mTouchArea) { |
|
122 |
mTouchArea->resize(rect.size()); |
|
123 |
} |
|
124 |
||
125 |
HbWidget::setGeometry(rect); |
|
126 |
} |
|
69 | 127 |
*/ |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
128 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
129 |
Loads widgets. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
130 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
131 |
bool HsPage::load() |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
132 |
{ |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
133 |
if (mDatabaseId < 0) { |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
134 |
return false; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
135 |
} |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
136 |
|
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
137 |
HsDatabase *db = HsDatabase::instance(); |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
138 |
|
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
139 |
QList<HsWidgetData> datas; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
140 |
if (!db->widgets(mDatabaseId, datas)) { |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
141 |
return false; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
142 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
143 |
|
62 | 144 |
if (HSCONFIGURATION_GET(sceneType) == HsConfiguration::PageWallpapers) { |
145 |
mWallpaper = new HsPageWallpaper(this); |
|
146 |
} |
|
147 |
||
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
148 |
foreach (HsWidgetData data, datas) { |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
149 |
HsWidgetHost *widget = new HsWidgetHost(data.id); |
69 | 150 |
if (!widget->loadPresentation(Qt::Horizontal) && |
151 |
!widget->loadPresentation(Qt::Vertical)) { |
|
152 |
widget->setPage(this); |
|
153 |
widget->visual()->hide(); |
|
154 |
connectWidget(widget); |
|
155 |
mNewWidgets << widget; |
|
156 |
} |
|
157 |
else { |
|
158 |
mWidgets.append(widget); |
|
159 |
connectWidget(widget); |
|
160 |
widget->setPage(this); |
|
161 |
widget->visual()->setParentItem(this->visual()); |
|
162 |
widget->startWidget(isDefaultPage()); |
|
163 |
} |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
164 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
165 |
|
69 | 166 |
connect(HsGui::instance(), |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
167 |
SIGNAL(orientationChanged(Qt::Orientation)), |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
168 |
SLOT(onOrientationChanged(Qt::Orientation))); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
169 |
|
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
170 |
return true; |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
171 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
172 |
|
62 | 173 |
/*! |
63 | 174 |
Return wallpaper. |
62 | 175 |
*/ |
176 |
HsWallpaper *HsPage::wallpaper() const |
|
177 |
{ |
|
178 |
return mWallpaper; |
|
179 |
} |
|
180 |
/*! |
|
181 |
Add given existing \a widgetHost to a page. Returns true if successful |
|
182 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
183 |
bool HsPage::addExistingWidget(HsWidgetHost *widgetHost) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
184 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
185 |
if (!widgetHost) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
186 |
return false; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
187 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
188 |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
189 |
if (mWidgets.contains(widgetHost)) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
190 |
return true; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
191 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
192 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
193 |
if (!widgetHost->setPage(this)) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
194 |
return false; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
195 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
196 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
197 |
connectWidget(widgetHost); |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
198 |
mWidgets << widgetHost; |
69 | 199 |
widgetHost->visual()->setParentItem(visual()); |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
200 |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
201 |
return true; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
202 |
} |
63 | 203 |
|
62 | 204 |
/*! |
205 |
Remove given \a widgetHost from a page. Widget is not deleted. |
|
206 |
Returns true if successful |
|
207 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
208 |
bool HsPage::removeWidget(HsWidgetHost *widgetHost) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
209 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
210 |
if (!widgetHost || !widgetHost->setPage(0)) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
211 |
return false; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
212 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
213 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
214 |
disconnectWidget(widgetHost); |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
215 |
mWidgets.removeOne(widgetHost); |
69 | 216 |
widgetHost->visual()->setParentItem(0); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
217 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
218 |
return true; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
219 |
} |
63 | 220 |
|
62 | 221 |
/*! |
222 |
Returns list of new widgets belonging to a page. Widgets which are |
|
223 |
not yet layouted are considered as new widgets. |
|
224 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
225 |
QList<HsWidgetHost *> HsPage::newWidgets() |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
226 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
227 |
return mNewWidgets; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
228 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
229 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
230 |
/*! |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
231 |
Adds new widget into a page. Returns true if successfull. |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
232 |
*/ |
62 | 233 |
bool HsPage::addNewWidget(HsWidgetHost* widgetHost, const QPointF &touchPoint) |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
234 |
{ |
62 | 235 |
mTouchPoint = touchPoint; |
236 |
||
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
237 |
if (!widgetHost || mWidgets.contains(widgetHost)) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
238 |
return false; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
239 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
240 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
241 |
if (mNewWidgets.contains(widgetHost)) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
242 |
return true; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
243 |
} |
69 | 244 |
|
245 |
widgetHost->setPage(this); |
|
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
246 |
|
69 | 247 |
widgetHost->visual()->hide(); |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
248 |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
249 |
connectWidget(widgetHost); |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
250 |
mNewWidgets << widgetHost; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
251 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
252 |
return true; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
253 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
254 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
255 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
256 |
Layouts all the new widgets |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
257 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
258 |
void HsPage::layoutNewWidgets() |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
259 |
{ |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
260 |
if (mNewWidgets.isEmpty()) { |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
261 |
return; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
262 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
263 |
|
69 | 264 |
HsPageNewWidgetLayout *newWidgetLayout = static_cast<HsPageNewWidgetLayout *>(visual()->layout()); |
62 | 265 |
if (!newWidgetLayout) { |
266 |
newWidgetLayout = new HsPageNewWidgetLayout(mTouchPoint); |
|
69 | 267 |
visual()->setLayout(newWidgetLayout); |
62 | 268 |
} |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
269 |
updateZValues(); |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
270 |
HsWidgetHost *widget = 0; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
271 |
for (int i = 0; i < mNewWidgets.count(); ++i) { |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
272 |
widget = mNewWidgets.at(i); |
62 | 273 |
newWidgetLayout->addItem(widget); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
274 |
widget->setPage(this); |
69 | 275 |
widget->visual()->setParentItem(visual()); |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
276 |
widget->showWidget(); |
69 | 277 |
widget->visual()->show(); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
278 |
} |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
279 |
mWidgets << mNewWidgets; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
280 |
mNewWidgets.clear(); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
281 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
282 |
|
62 | 283 |
/*! |
63 | 284 |
Clears new widgets list and resets layout. |
285 |
*/ |
|
286 |
void HsPage::resetNewWidgets() |
|
287 |
{ |
|
288 |
mNewWidgets.clear(); |
|
69 | 289 |
visual()->setLayout(0); |
63 | 290 |
} |
291 |
||
292 |
/*! |
|
62 | 293 |
Remove page and all it's contained widgets from database |
294 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
295 |
bool HsPage::deleteFromDatabase() |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
296 |
{ |
69 | 297 |
|
298 |
HsWidgetHostVisual *visual(0); |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
299 |
foreach (HsWidgetHost *widget, mWidgets) { |
69 | 300 |
visual = widget->visual(); |
301 |
visual->setParent(0); |
|
302 |
if (visual->scene()) { |
|
303 |
visual->scene()->removeItem(visual); |
|
304 |
} |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
305 |
widget->remove(); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
306 |
} |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
307 |
mWidgets.clear(); |
69 | 308 |
|
62 | 309 |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
310 |
foreach (HsWidgetHost *widget, mNewWidgets) { |
69 | 311 |
visual = widget->visual(); |
312 |
visual->setParent(0); |
|
313 |
if (visual->scene()) { |
|
314 |
visual->scene()->removeItem(visual); |
|
315 |
} |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
316 |
widget->remove(); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
317 |
} |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
318 |
mNewWidgets.clear(); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
319 |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
320 |
foreach (HsWidgetHost *widget, mUnavailableWidgets) { |
69 | 321 |
visual = widget->visual(); |
322 |
visual->setParent(0); |
|
323 |
if (visual->scene()) { |
|
324 |
visual->scene()->removeItem(visual); |
|
325 |
} |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
326 |
widget->remove(); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
327 |
} |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
328 |
mUnavailableWidgets.clear(); |
63 | 329 |
|
330 |
if (mWallpaper) { |
|
331 |
mWallpaper->remove(); |
|
332 |
} |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
333 |
return HsDatabase::instance()->deletePage(mDatabaseId); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
334 |
} |
63 | 335 |
|
62 | 336 |
/*! |
337 |
Return list of widgets belonging to a page |
|
338 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
339 |
QList<HsWidgetHost *> HsPage::widgets() const |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
340 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
341 |
return mWidgets; |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
342 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
343 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
344 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
345 |
Returns true if the page can be removed. Otherwise, |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
346 |
returns false. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
347 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
348 |
bool HsPage::isRemovable() const |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
349 |
{ |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
350 |
return mRemovable; |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
351 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
352 |
|
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
353 |
/*! |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
354 |
Sets removable flag to \a removable. |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
355 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
356 |
void HsPage::setRemovable(bool removable) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
357 |
{ |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
358 |
mRemovable = removable; |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
359 |
} |
63 | 360 |
|
62 | 361 |
/*! |
362 |
Return true if page is default page. |
|
363 |
*/ |
|
364 |
bool HsPage::isDefaultPage() const |
|
365 |
{ |
|
366 |
return mDatabaseId == HSCONFIGURATION_GET(defaultPageId); |
|
367 |
} |
|
63 | 368 |
|
62 | 369 |
/*! |
370 |
Return true if page is active page. |
|
371 |
*/ |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
372 |
bool HsPage::isActivePage() const |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
373 |
{ |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
374 |
return this == HsScene::instance()->activePage(); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
375 |
} |
63 | 376 |
|
62 | 377 |
/*! |
378 |
Create page into database and return instance of a new page. |
|
379 |
*/ |
|
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
380 |
HsPage *HsPage::createInstance(const HsPageData &pageData) |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
381 |
{ |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
382 |
HsDatabase *db = HsDatabase::instance(); |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
383 |
Q_ASSERT(db); |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
384 |
|
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
385 |
HsPageData data(pageData); |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
386 |
if (db->insertPage(data)) { |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
387 |
HsPage *page = new HsPage; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
388 |
page->setDatabaseId(data.id); |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
389 |
return page; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
390 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
391 |
|
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
392 |
return 0; |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
393 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
394 |
|
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
395 |
/*! |
63 | 396 |
The widget is bounded in the rectangle which is smaller by pageMargin on all sides of page. |
397 |
*/ |
|
398 |
QPointF HsPage::adjustedWidgetPosition(const QRectF &origWidgetRect) |
|
399 |
{ |
|
400 |
QRectF widgetAreaRect = contentGeometry(); |
|
401 |
qreal widgetX = qBound(widgetAreaRect.left(), origWidgetRect.x(), widgetAreaRect.right() - origWidgetRect.width()); |
|
402 |
qreal widgetY = qBound(widgetAreaRect.top(), origWidgetRect.y(), widgetAreaRect.bottom() - origWidgetRect.height()); |
|
403 |
||
404 |
return QPointF(widgetX, widgetY); |
|
405 |
} |
|
406 |
||
407 |
/*! |
|
408 |
Returns rect of rectangular where widgets are allowed to be placed in the page. |
|
409 |
*/ |
|
410 |
QRectF HsPage::contentGeometry() |
|
411 |
{ |
|
69 | 412 |
return contentGeometry(HsGui::instance()->orientation()); |
63 | 413 |
} |
414 |
||
415 |
/*! |
|
416 |
Returns rect of rectangular where widgets are allowed to be placed in the page. |
|
417 |
*/ |
|
418 |
QRectF HsPage::contentGeometry(Qt::Orientation orientation) |
|
419 |
{ |
|
69 | 420 |
QRectF pageRect = HsGui::instance()->layoutRect(); |
63 | 421 |
|
69 | 422 |
if (orientation != HsGui::instance()->orientation()) { |
63 | 423 |
qreal width = pageRect.width(); |
424 |
qreal height = pageRect.height(); |
|
425 |
pageRect.setWidth(height); |
|
426 |
pageRect.setHeight(width); |
|
427 |
} |
|
428 |
||
429 |
//Take care of chrome in both orientation |
|
430 |
pageRect.setTop(64); |
|
431 |
||
432 |
//Shrink by page margins at each side |
|
433 |
return pageRect.adjusted(mPageMargin, mPageMargin, -mPageMargin, -mPageMargin); |
|
434 |
} |
|
435 |
||
436 |
/*! |
|
437 |
Returns rect of rectangular where widgets are allowed to be placed in the page. |
|
438 |
*/ |
|
439 |
QRectF HsPage::contentRect() |
|
440 |
{ |
|
69 | 441 |
return contentRect(HsGui::instance()->orientation()); |
63 | 442 |
} |
443 |
||
444 |
/*! |
|
445 |
Returns rect of rectangular where widgets are allowed to be placed in the page. |
|
446 |
*/ |
|
447 |
QRectF HsPage::contentRect(Qt::Orientation orientation) |
|
448 |
{ |
|
449 |
QRectF rect = contentGeometry(orientation); |
|
450 |
rect.moveTopLeft(QPointF(0,0)); |
|
451 |
return rect; |
|
452 |
} |
|
453 |
||
69 | 454 |
HsPageVisual *HsPage::visual() const |
455 |
{ |
|
456 |
return mPageVisual; |
|
457 |
} |
|
63 | 458 |
/*! |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
459 |
Calls onShow() for contained widgets. |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
460 |
*/ |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
461 |
void HsPage::showWidgets() |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
462 |
{ |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
463 |
foreach (HsWidgetHost *widget, mWidgets) { |
69 | 464 |
if (widget->visual()->parentItem() == visual()) { |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
465 |
widget->showWidget(); |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
466 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
467 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
468 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
469 |
|
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
470 |
/*! |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
471 |
Calls onHide() for contained widgets. |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
472 |
*/ |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
473 |
void HsPage::hideWidgets() |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
474 |
{ |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
475 |
foreach (HsWidgetHost *widget, mWidgets) { |
69 | 476 |
if (widget->visual()->parentItem() == visual()) { |
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
477 |
widget->hideWidget(); |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
478 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
479 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
480 |
} |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
481 |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
482 |
/*! |
63 | 483 |
Propagate online state to widgets. |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
484 |
*/ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
485 |
void HsPage::setOnline(bool online) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
486 |
{ |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
487 |
foreach (HsWidgetHost *widget, mNewWidgets) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
488 |
widget->setOnline(online); |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
489 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
490 |
foreach (HsWidgetHost *widget, mWidgets) { |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
491 |
widget->setOnline(online); |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
492 |
} |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
493 |
} |
63 | 494 |
|
62 | 495 |
/*! |
496 |
Update widgets z-values and persist those. Active widget has top most |
|
497 |
z-value. |
|
498 |
*/ |
|
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
499 |
void HsPage::updateZValues() |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
500 |
{ |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
501 |
int z = 0; |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
502 |
|
81 | 503 |
QHash<int, qreal> widgetZValues; |
504 |
||
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
505 |
if (!mWidgets.isEmpty()) { |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
506 |
QMultiMap<qreal, HsWidgetHost *> map; |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
507 |
foreach (HsWidgetHost *widget, mWidgets) { |
69 | 508 |
map.insert(widget->visual()->zValue(), widget); |
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
509 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
510 |
|
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
511 |
QList<HsWidgetHost *> sortedWidgets = map.values(); |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
512 |
|
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
513 |
HsWidgetHost *activeWidget = HsScene::instance()->activeWidget(); |
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
514 |
if (sortedWidgets.contains(activeWidget)) { |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
515 |
sortedWidgets.removeOne(activeWidget); |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
516 |
sortedWidgets.append(activeWidget); |
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
517 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
518 |
|
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
519 |
foreach (HsWidgetHost *widget, sortedWidgets) { |
81 | 520 |
widgetZValues.insert(widget->databaseId(), z); |
69 | 521 |
widget->visual()->setZValue(z++); |
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
522 |
} |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
523 |
} |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
524 |
|
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
525 |
if (!mNewWidgets.isEmpty()) { |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
526 |
foreach (HsWidgetHost *widget, mNewWidgets) { |
81 | 527 |
widgetZValues.insert(widget->databaseId(), z); |
69 | 528 |
widget->visual()->setZValue(z++); |
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
529 |
} |
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
530 |
} |
81 | 531 |
|
532 |
if (!widgetZValues.isEmpty()) { |
|
533 |
HsDatabase::instance()->updateWidgetZValues( |
|
534 |
widgetZValues, HsGui::instance()->orientation()); |
|
535 |
} |
|
39
4e8ebe173323
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
536 |
} |
62 | 537 |
/*! |
538 |
Return this page's index. |
|
539 |
*/ |
|
51
4785f57bf3d4
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
540 |
int HsPage::pageIndex() |
4785f57bf3d4
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
541 |
{ |
4785f57bf3d4
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
542 |
return HsScene::instance()->pages().indexOf(this); |
4785f57bf3d4
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
46
diff
changeset
|
543 |
} |
62 | 544 |
/*! |
545 |
Create touch area for page. |
|
546 |
*/ |
|
69 | 547 |
/*void HsPage::setupTouchArea() |
62 | 548 |
{ |
549 |
mTouchArea = new HsPageTouchArea(this); |
|
550 |
mTouchArea->setZValue(-1); |
|
69 | 551 |
}*/ |
62 | 552 |
/*! |
553 |
Utility to connect widget signals to page. |
|
554 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
555 |
void HsPage::connectWidget(HsWidgetHost *widget) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
556 |
{ |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
557 |
connect(widget, SIGNAL(finished()), SLOT(onWidgetFinished())); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
558 |
connect(widget, SIGNAL(faulted()), SLOT(onWidgetFaulted())); |
69 | 559 |
connect(widget->visual(), SIGNAL(resized()), SLOT(onWidgetResized())); |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
560 |
connect(widget, SIGNAL(available()), SLOT(onWidgetAvailable())); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
561 |
connect(widget, SIGNAL(unavailable()), SLOT(onWidgetUnavailable())); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
562 |
} |
62 | 563 |
/*! |
564 |
Disconnect widget signals from page |
|
565 |
*/ |
|
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
566 |
void HsPage::disconnectWidget(HsWidgetHost *widget) |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
567 |
{ |
69 | 568 |
widget->visual()->disconnect(this); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
569 |
widget->disconnect(this); |
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
570 |
} |
81 | 571 |
|
62 | 572 |
/*! |
573 |
Disconnect and remove widget |
|
574 |
*/ |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
575 |
void HsPage::onWidgetFinished() |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
576 |
{ |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
577 |
HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
578 |
|
36
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
579 |
// It can be in new widget list if we haven't layouted it yet |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
580 |
// or layouted new widget and widget list |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
581 |
if (!mNewWidgets.removeOne(widget)) { |
cdae8c6c3876
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
35
diff
changeset
|
582 |
mWidgets.removeOne(widget); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
583 |
} |
69 | 584 |
if (widget){ |
585 |
HsWidgetHostVisual *visual = widget->visual(); |
|
586 |
visual->setParentItem(0); |
|
587 |
if (visual->scene()) { |
|
588 |
visual->scene()->removeItem(visual); |
|
589 |
} |
|
81 | 590 |
disconnectWidget(widget); |
591 |
widget->remove(); |
|
69 | 592 |
} |
81 | 593 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
594 |
|
62 | 595 |
/*! |
596 |
Remove widget if it faulted |
|
597 |
*/ |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
598 |
void HsPage::onWidgetFaulted() |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
599 |
{ |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
600 |
onWidgetFinished(); |
35
f9ce957a272c
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
601 |
} |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
602 |
|
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
603 |
/*! |
62 | 604 |
Calculates new widget position on page when widget size changes. If page has layout then there are new widgets |
605 |
and we use layout to calculate new widget positions. |
|
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
606 |
*/ |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
607 |
void HsPage::onWidgetResized() |
46
23b5d6a29cce
Revision: 201017
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
39
diff
changeset
|
608 |
{ |
69 | 609 |
if (!visual()->layout()) { |
610 |
HsWidgetHostVisual *widgetVisual = qobject_cast<HsWidgetHostVisual *>(sender()); |
|
611 |
widgetVisual->setPos(adjustedWidgetPosition(widgetVisual->geometry())); |
|
62 | 612 |
} else { |
69 | 613 |
visual()->layout()->invalidate(); |
62 | 614 |
} |
615 |
} |
|
616 |
/*! |
|
617 |
Show widget if it came available |
|
618 |
*/ |
|
619 |
void HsPage::onWidgetAvailable() |
|
620 |
{ |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
621 |
HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
69 | 622 |
HsWidgetHostVisual *widgetVisual(widget->visual()); |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
623 |
|
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
624 |
mUnavailableWidgets.removeOne(widget); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
625 |
mWidgets.append(widget); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
626 |
|
69 | 627 |
widgetVisual->setParentItem(visual()); |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
628 |
widget->startWidget(isActivePage()); |
69 | 629 |
widgetVisual->show(); |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
630 |
} |
62 | 631 |
/*! |
632 |
Update internal bookkeeping and hide widget |
|
633 |
*/ |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
634 |
void HsPage::onWidgetUnavailable() |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
635 |
{ |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
636 |
HsWidgetHost *widget = qobject_cast<HsWidgetHost *>(sender()); |
69 | 637 |
HsWidgetHostVisual *widgetVisual(widget->visual()); |
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
638 |
|
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
639 |
if (mWidgets.contains(widget)) { |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
640 |
mWidgets.removeOne(widget); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
641 |
} else if (mNewWidgets.contains(widget)) { |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
642 |
mNewWidgets.removeOne(widget); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
643 |
} else { |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
644 |
return; |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
645 |
} |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
646 |
|
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
647 |
mUnavailableWidgets.append(widget); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
648 |
|
69 | 649 |
widgetVisual->hide(); |
650 |
widgetVisual->setParentItem(0); |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
651 |
} |
63 | 652 |
|
62 | 653 |
/*! |
654 |
Run positioning algorithm for widgets which don't have position on |
|
655 |
target orientation. Otherwise set orientation positions for widgets. |
|
656 |
*/ |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
657 |
void HsPage::onOrientationChanged(Qt::Orientation orientation) |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
658 |
{ |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
659 |
HsWidgetPositioningOnOrientationChange *converter = |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
660 |
HsWidgetPositioningOnOrientationChange::instance(); |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
661 |
|
63 | 662 |
Qt::Orientation orientationFrom = orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical; |
663 |
QRectF from = contentGeometry(orientationFrom); |
|
664 |
QRectF to = contentGeometry(orientation); |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
665 |
|
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
666 |
HsWidgetPresentationData presentation; |
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
667 |
presentation.orientation = orientation; |
69 | 668 |
|
86 | 669 |
HsPageVisual *pageVisual = visual(); |
69 | 670 |
HsWidgetHostVisual *visual(0); |
671 |
#ifdef HSWIDGETORGANIZER_ALGORITHM |
|
672 |
QList<HsWidgetHost*> newWidgets; |
|
673 |
#endif //HSWIDGETORGANIZER_ALGORITHM |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
674 |
foreach (HsWidgetHost *widget, mWidgets) { |
69 | 675 |
visual = widget->visual(); |
86 | 676 |
if ( pageVisual->isAncestorOf(visual)) { |
677 |
if (!widget->getPresentation(presentation)) { |
|
69 | 678 |
#ifndef HSWIDGETORGANIZER_ALGORITHM |
86 | 679 |
QList<QRectF> geometries = converter->convert( |
680 |
from, QList<QRectF>() << visual->geometry(), to); |
|
681 |
visual->setGeometry(geometries.first()); |
|
682 |
widget->savePresentation(); |
|
69 | 683 |
#else //HSWIDGETORGANIZER_ALGORITHM |
86 | 684 |
newWidgets << widget; |
69 | 685 |
#endif //HSWIDGETORGANIZER_ALGORITHM |
86 | 686 |
} else { |
687 |
QRectF adjustWidgetPosition; |
|
688 |
adjustWidgetPosition = visual->geometry(); |
|
689 |
adjustWidgetPosition.moveTopLeft(presentation.pos()); |
|
690 |
visual->setPos(adjustedWidgetPosition(adjustWidgetPosition)); |
|
691 |
visual->setZValue(presentation.zValue); |
|
692 |
widget->savePresentation(); //Needed to follow pageMargin dynamic change |
|
693 |
} |
|
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
694 |
} |
62 | 695 |
} |
69 | 696 |
|
697 |
#ifdef HSWIDGETORGANIZER_ALGORITHM |
|
698 |
// sort new widgets in order |
|
699 |
if (newWidgets.count()) { |
|
700 |
// TODO: read from configuration? or just use height for portrait and width for landscape (currently only height is used) |
|
701 |
sortOrder order(height); |
|
702 |
if(orientation == Qt::Horizontal) { |
|
703 |
order = width; |
|
704 |
} |
|
705 |
sortWidgets(order, newWidgets); |
|
706 |
// get rects for new widgets |
|
707 |
QList<QRectF> newRects; |
|
708 |
foreach (HsWidgetHost *newWidget, newWidgets) { |
|
709 |
newRects << QRectF(QPointF(), newWidget->visual()->preferredSize()); |
|
710 |
} |
|
711 |
||
712 |
// get page rect |
|
713 |
QRectF pageRect = contentGeometry(); |
|
714 |
||
715 |
// scan existing widgets rects |
|
716 |
QList<QRectF> existingRects; |
|
717 |
foreach (HsWidgetHost *widget, mWidgets) { |
|
718 |
if (!newWidgets.contains(widget)) { |
|
719 |
existingRects << QRectF(widget->visual()->pos(), widget->visual()->preferredSize()); |
|
720 |
} |
|
721 |
} |
|
722 |
||
723 |
// calculate new widget positions with "stuck 'em all"-algorithm |
|
724 |
HsWidgetPositioningOnWidgetAdd *algorithm = |
|
725 |
HsWidgetPositioningOnWidgetAdd::instance(); |
|
726 |
QList<QRectF> calculatedRects = |
|
727 |
algorithm->convert(pageRect, existingRects, newRects, QPointF()); |
|
728 |
||
729 |
for ( int i=0; i<newWidgets.count(); i++) { |
|
730 |
int j = mWidgets.indexOf(newWidgets.at(i)); |
|
731 |
mWidgets.at(j)->visual()->setGeometry(calculatedRects.at(i)); |
|
732 |
mWidgets.at(j)->savePresentation(); |
|
733 |
} |
|
734 |
} |
|
735 |
#endif //HSWIDGETORGANIZER_ALGORITHM |
|
736 |
||
55
03646e8da489
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
51
diff
changeset
|
737 |
} |
62 | 738 |
|
63 | 739 |
void HsPage::onPageMarginChanged(const QString &value) |
62 | 740 |
{ |
63 | 741 |
if (value == "pageMargin") { |
742 |
mPageMargin = HSCONFIGURATION_GET(pageMargin); |
|
69 | 743 |
HsWidgetHostVisual *visual(0); |
63 | 744 |
if (!mWidgets.isEmpty()) { |
745 |
foreach (HsWidgetHost *widget, mWidgets) { |
|
69 | 746 |
visual = widget->visual(); |
747 |
visual->setPos(adjustedWidgetPosition(visual->geometry())); |
|
63 | 748 |
widget->savePresentation(); |
749 |
} |
|
750 |
} |
|
751 |
||
752 |
if (!mNewWidgets.isEmpty()) { |
|
753 |
foreach (HsWidgetHost *widget, mNewWidgets) { |
|
69 | 754 |
visual = widget->visual(); |
755 |
visual->setPos(adjustedWidgetPosition(visual->geometry())); |
|
63 | 756 |
widget->savePresentation(); |
757 |
} |
|
758 |
} |
|
759 |
} |
|
62 | 760 |
} |
69 | 761 |
#ifdef HSWIDGETORGANIZER_ALGORITHM |
762 |
// TODO: sorting should be done in algorithm class, make widget<->rect mapping here and move sortWidgets function to algorithm side |
|
763 |
/*! |
|
764 |
Sorts widgets in height/width order |
|
765 |
*/ |
|
766 |
void HsPage::sortWidgets(sortOrder order, QList<HsWidgetHost*> &widgets) |
|
767 |
{ |
|
768 |
QList<HsWidgetHost*> tmpWidgets; |
|
769 |
||
770 |
for ( int i = 0; i < widgets.count(); i++) { |
|
771 |
int index = 0; |
|
772 |
// add first widget to sorted list |
|
773 |
if (i == 0) { |
|
774 |
tmpWidgets << widgets.at(i); |
|
775 |
} else { |
|
776 |
// go through existing widgets in the sorted list |
|
777 |
for ( int j = 0; j < tmpWidgets.count(); j++) { |
|
778 |
// sort widgets in height order |
|
779 |
if (order == height) { |
|
780 |
/* if widgets heigth is smaller on already |
|
781 |
existing ones in the list -> increment index |
|
782 |
*/ |
|
783 |
if (widgets.at(i)->visual()->preferredHeight() <= tmpWidgets.at(j)->visual()->preferredHeight()) { |
|
784 |
index++; |
|
785 |
} |
|
786 |
// sort widgets in width order |
|
787 |
} else { |
|
788 |
/* if widgets width is smaller on already |
|
789 |
existing ones in the sorted list -> increment index |
|
790 |
*/ |
|
791 |
if (widgets.at(i)->visual()->preferredWidth() <= tmpWidgets.at(j)->visual()->preferredWidth()) { |
|
792 |
index++; |
|
793 |
} |
|
794 |
} |
|
795 |
} |
|
796 |
// add widget to its correct index in sorted list |
|
797 |
tmpWidgets.insert(index, widgets.at(i)); |
|
798 |
} |
|
799 |
} |
|
800 |
widgets = tmpWidgets; |
|
801 |
} |
|
802 |
#endif //HSWIDGETORGANIZER_ALGORITHM |