90
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 <QApplication>
|
|
19 |
#include <QStateMachine>
|
|
20 |
#include <QState>
|
|
21 |
#include <QFinalState>
|
|
22 |
#include <QGraphicsLinearLayout>
|
|
23 |
#include <QParallelAnimationGroup>
|
|
24 |
#include <QPropertyAnimation>
|
|
25 |
#include <QGraphicsDropShadowEffect>
|
|
26 |
#include <QGraphicsSceneResizeEvent>
|
|
27 |
#include <QGesture>
|
|
28 |
#include <QGraphicsScene>
|
|
29 |
|
|
30 |
#include <qservicemanager.h>
|
|
31 |
#include <qservicefilter.h>
|
|
32 |
#include <qserviceinterfacedescriptor.h>
|
|
33 |
|
|
34 |
#include <HbInstantFeedback>
|
|
35 |
|
|
36 |
#include "hsdatabase.h"
|
|
37 |
#include "hsdomainmodeldatastructures.h"
|
|
38 |
#include "hsscene.h"
|
|
39 |
#include "hspage.h"
|
|
40 |
#include "hswidgethost.h"
|
|
41 |
#include "hswidgettoucharea.h"
|
|
42 |
#include "hswidgetcomponentregistry.h"
|
|
43 |
#include "hswidgetcomponent.h"
|
|
44 |
#include "hsconfiguration.h"
|
|
45 |
#include "testwidget.h"
|
|
46 |
|
|
47 |
// Helper macros for connecting state entry and exit actions.
|
|
48 |
#define ENTRY_ACTION(state, action) \
|
|
49 |
connect(state, SIGNAL(entered()), SLOT(action()));
|
|
50 |
#define EXIT_ACTION(state, action) \
|
|
51 |
connect(state, SIGNAL(exited()), SLOT(action()));
|
|
52 |
|
|
53 |
QTM_USE_NAMESPACE
|
|
54 |
|
|
55 |
HsWidgetHost::HsWidgetHost(int databaseId, QObject *parent)
|
|
56 |
: QObject(parent),
|
|
57 |
mDatabaseId(databaseId),
|
|
58 |
mStateMachine(0),
|
|
59 |
mWidget(0),
|
|
60 |
mPage(0),
|
|
61 |
mComponent(0),
|
|
62 |
mIsFinishing(false)
|
|
63 |
{
|
|
64 |
/* setFlag(QGraphicsItem::ItemClipsChildrenToShape);
|
|
65 |
setFlag(QGraphicsItem::ItemHasNoContents);
|
|
66 |
|
|
67 |
grabGesture(Qt::TapGesture);
|
|
68 |
grabGesture(Qt::TapAndHoldGesture);
|
|
69 |
grabGesture(Qt::PanGesture);
|
|
70 |
grabGesture(Qt::PinchGesture);
|
|
71 |
grabGesture(Qt::SwipeGesture);
|
|
72 |
grabGesture(Qt::CustomGesture);
|
|
73 |
|
|
74 |
setupTouchArea();
|
|
75 |
setupEffects();*/
|
|
76 |
setupStates();
|
|
77 |
}
|
|
78 |
|
|
79 |
HsWidgetHost::~HsWidgetHost()
|
|
80 |
{
|
|
81 |
}
|
|
82 |
|
|
83 |
HsWidgetHost *HsWidgetHost::createInstance(HsWidgetData &widgetData,
|
|
84 |
const QVariantHash &preferences)
|
|
85 |
{
|
|
86 |
Q_UNUSED(widgetData);
|
|
87 |
Q_UNUSED(preferences);
|
|
88 |
HsWidgetHost *host = NULL;
|
|
89 |
host = new HsWidgetHost(-1);
|
|
90 |
return host;
|
|
91 |
}
|
|
92 |
|
|
93 |
int HsWidgetHost::databaseId() const
|
|
94 |
{
|
|
95 |
return mDatabaseId;
|
|
96 |
}
|
|
97 |
|
|
98 |
bool HsWidgetHost::setPage(HsPage *page)
|
|
99 |
{
|
|
100 |
mPage = page;
|
|
101 |
return true;
|
|
102 |
}
|
|
103 |
|
|
104 |
HsPage *HsWidgetHost::page() const
|
|
105 |
{
|
|
106 |
return mPage;
|
|
107 |
}
|
|
108 |
|
|
109 |
bool HsWidgetHost::loadPresentation()
|
|
110 |
{
|
|
111 |
return true;
|
|
112 |
}
|
|
113 |
|
|
114 |
bool HsWidgetHost::loadPresentation(Qt::Orientation orientation)
|
|
115 |
{
|
|
116 |
Q_UNUSED(orientation)
|
|
117 |
return true;
|
|
118 |
}
|
|
119 |
|
|
120 |
bool HsWidgetHost::savePresentation()
|
|
121 |
{
|
|
122 |
return true;
|
|
123 |
}
|
|
124 |
|
|
125 |
bool HsWidgetHost::savePresentation(Qt::Orientation orientation)
|
|
126 |
{
|
|
127 |
Q_UNUSED(orientation)
|
|
128 |
return true;
|
|
129 |
}
|
|
130 |
|
|
131 |
bool HsWidgetHost::savePresentation(HsWidgetPresentationData &presentation)
|
|
132 |
{
|
|
133 |
Q_UNUSED(presentation)
|
|
134 |
return true;
|
|
135 |
}
|
|
136 |
|
|
137 |
bool HsWidgetHost::getPresentation(HsWidgetPresentationData &presentation)
|
|
138 |
{
|
|
139 |
Q_UNUSED(presentation)
|
|
140 |
return true;
|
|
141 |
}
|
|
142 |
|
|
143 |
bool HsWidgetHost::removePresentation(Qt::Orientation orientation)
|
|
144 |
{
|
|
145 |
Q_UNUSED(orientation)
|
|
146 |
return true;
|
|
147 |
}
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
void HsWidgetHost::startWidget(bool show)
|
|
152 |
{
|
|
153 |
if (show) {
|
|
154 |
emit event_startAndShow();
|
|
155 |
} else {
|
|
156 |
emit event_startAndHide();
|
|
157 |
}
|
|
158 |
}
|
|
159 |
|
|
160 |
void HsWidgetHost::showWidget()
|
|
161 |
{
|
|
162 |
emit event_show();
|
|
163 |
}
|
|
164 |
|
|
165 |
void HsWidgetHost::hideWidget()
|
|
166 |
{
|
|
167 |
emit event_hide();
|
|
168 |
}
|
|
169 |
|
|
170 |
void HsWidgetHost::setOnline(bool online)
|
|
171 |
{
|
|
172 |
mIsOnlineProperty.write(mWidget, online);
|
|
173 |
}
|
|
174 |
|
|
175 |
void HsWidgetHost::remove()
|
|
176 |
{
|
|
177 |
emit event_remove();
|
|
178 |
}
|
|
179 |
|
|
180 |
void HsWidgetHost::close()
|
|
181 |
{
|
|
182 |
emit event_close();
|
|
183 |
}
|
|
184 |
|
|
185 |
void HsWidgetHost::startDragEffect()
|
|
186 |
{
|
|
187 |
/* TODO: Uncomment after the Qt bug has been fixed.
|
|
188 |
QGraphicsDropShadowEffect *effect =
|
|
189 |
static_cast<QGraphicsDropShadowEffect *>(graphicsEffect());
|
|
190 |
*/
|
|
191 |
/* HbInstantFeedback::play(HbFeedback::ItemPick);
|
|
192 |
|
|
193 |
setTransformOriginPoint(rect().center());
|
|
194 |
|
|
195 |
QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup();
|
|
196 |
|
|
197 |
QPropertyAnimation *animation = new QPropertyAnimation(this, "scale");
|
|
198 |
animation->setDuration(HSCONFIGURATION_GET(widgetDragEffectDuration));
|
|
199 |
animation->setEndValue(1.1);
|
|
200 |
animationGroup->addAnimation(animation);
|
|
201 |
*/
|
|
202 |
/* TODO: Uncomment after the Qt bug has been fixed.
|
|
203 |
animation = new QPropertyAnimation(effect, "offset");
|
|
204 |
animation->setDuration(200);
|
|
205 |
animation->setEndValue(QPointF(8 ,8));
|
|
206 |
animationGroup->addAnimation(animation);
|
|
207 |
*/
|
|
208 |
|
|
209 |
// animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
|
210 |
}
|
|
211 |
|
|
212 |
void HsWidgetHost::startDropEffect()
|
|
213 |
{
|
|
214 |
/* TODO: Uncomment after the Qt bug has been fixed.
|
|
215 |
QGraphicsDropShadowEffect *effect =
|
|
216 |
static_cast<QGraphicsDropShadowEffect *>(graphicsEffect());
|
|
217 |
*/
|
|
218 |
/* HbInstantFeedback::play(HbFeedback::ItemDrop);
|
|
219 |
|
|
220 |
QParallelAnimationGroup *animationGroup = new QParallelAnimationGroup;
|
|
221 |
|
|
222 |
QPropertyAnimation *animation = new QPropertyAnimation(this, "scale");
|
|
223 |
animation->setDuration(HSCONFIGURATION_GET(widgetDropEffectDuration));
|
|
224 |
animation->setEndValue(1);
|
|
225 |
animationGroup->addAnimation(animation);
|
|
226 |
*/
|
|
227 |
/* TODO: Uncomment after the Qt bug has been fixed.
|
|
228 |
animation = new QPropertyAnimation(effect, "offset");
|
|
229 |
animation->setDuration(200);
|
|
230 |
animation->setEndValue(QPointF(3, 3));
|
|
231 |
animationGroup->addAnimation(animation);
|
|
232 |
*/
|
|
233 |
|
|
234 |
// animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
|
|
235 |
}
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
void HsWidgetHost::setupStates()
|
|
240 |
{
|
|
241 |
// State machine
|
|
242 |
|
|
243 |
mStateMachine = new QStateMachine(this);
|
|
244 |
mStateMachine->setAnimated(false);
|
|
245 |
|
|
246 |
// States
|
|
247 |
|
|
248 |
QState *state_component = new QState;
|
|
249 |
QState *state_unloaded = new QState(state_component);
|
|
250 |
QState *state_running = new QState(state_component);
|
|
251 |
QState *state_show = new QState(state_running);
|
|
252 |
QState *state_hide = new QState(state_running);
|
|
253 |
QState *state_finished = new QState;
|
|
254 |
QState *state_faulted = new QState;
|
|
255 |
QState *state_remove = new QState;
|
|
256 |
QFinalState *state_final = new QFinalState;
|
|
257 |
|
|
258 |
mStateMachine->addState(state_component);
|
|
259 |
mStateMachine->addState(state_finished);
|
|
260 |
mStateMachine->addState(state_faulted);
|
|
261 |
mStateMachine->addState(state_remove);
|
|
262 |
mStateMachine->addState(state_final);
|
|
263 |
|
|
264 |
mStateMachine->setInitialState(state_component);
|
|
265 |
state_component->setInitialState(state_unloaded);
|
|
266 |
state_running->setInitialState(state_hide);
|
|
267 |
|
|
268 |
// Transitions
|
|
269 |
|
|
270 |
state_component->addTransition(
|
|
271 |
this, SIGNAL(event_close()), state_final);
|
|
272 |
state_component->addTransition(
|
|
273 |
this, SIGNAL(event_remove()), state_remove);
|
|
274 |
state_component->addTransition(
|
|
275 |
this, SIGNAL(event_finished()), state_finished);
|
|
276 |
state_component->addTransition(
|
|
277 |
this, SIGNAL(event_faulted()), state_faulted);
|
|
278 |
|
|
279 |
state_unloaded->addTransition(
|
|
280 |
this, SIGNAL(event_startAndShow()), state_show);
|
|
281 |
state_unloaded->addTransition(
|
|
282 |
this, SIGNAL(event_startAndHide()), state_hide);
|
|
283 |
|
|
284 |
state_running->addTransition(
|
|
285 |
this, SIGNAL(event_unload()), state_unloaded);
|
|
286 |
|
|
287 |
state_show->addTransition(
|
|
288 |
this, SIGNAL(event_hide()), state_hide);
|
|
289 |
|
|
290 |
state_hide->addTransition(
|
|
291 |
this, SIGNAL(event_show()), state_show);
|
|
292 |
|
|
293 |
state_finished->addTransition(
|
|
294 |
this, SIGNAL(event_remove()), state_remove);
|
|
295 |
state_finished->addTransition(
|
|
296 |
this, SIGNAL(event_close()), state_final);
|
|
297 |
|
|
298 |
state_faulted->addTransition(
|
|
299 |
this, SIGNAL(event_remove()), state_remove);
|
|
300 |
state_faulted->addTransition(
|
|
301 |
this, SIGNAL(event_close()), state_final);
|
|
302 |
|
|
303 |
state_remove->addTransition(state_final);
|
|
304 |
|
|
305 |
// Actions
|
|
306 |
|
|
307 |
ENTRY_ACTION(state_component, action_connectComponent)
|
|
308 |
EXIT_ACTION(state_component, action_disconnectComponent)
|
|
309 |
|
|
310 |
ENTRY_ACTION(state_running, action_load)
|
|
311 |
ENTRY_ACTION(state_running, action_initialize)
|
|
312 |
EXIT_ACTION(state_running, action_uninitialize)
|
|
313 |
EXIT_ACTION(state_running, action_unload)
|
|
314 |
|
|
315 |
ENTRY_ACTION(state_show, action_show)
|
|
316 |
|
|
317 |
ENTRY_ACTION(state_hide, action_hide)
|
|
318 |
|
|
319 |
ENTRY_ACTION(state_finished, action_finished)
|
|
320 |
|
|
321 |
ENTRY_ACTION(state_faulted, action_faulted)
|
|
322 |
|
|
323 |
ENTRY_ACTION(state_remove, action_remove)
|
|
324 |
|
|
325 |
// Connect and start
|
|
326 |
|
|
327 |
connect(mStateMachine, SIGNAL(finished()), SLOT(deleteLater()),
|
|
328 |
Qt::QueuedConnection);
|
|
329 |
|
|
330 |
mStateMachine->start();
|
|
331 |
|
|
332 |
// Starts the state machine. QStateMachine start uses
|
|
333 |
// queued connection.
|
|
334 |
|
|
335 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
|
336 |
}
|
|
337 |
|
|
338 |
bool HsWidgetHost::setProperty(const char *name, QMetaProperty &property)
|
|
339 |
{
|
|
340 |
const QMetaObject *object = mWidget->metaObject();
|
|
341 |
int index = object->indexOfProperty(name);
|
|
342 |
property = object->property(index);
|
|
343 |
return index >= 0;
|
|
344 |
}
|
|
345 |
|
|
346 |
bool HsWidgetHost::setMethod(const char *signature, QMetaMethod &method)
|
|
347 |
{
|
|
348 |
const QMetaObject *object = mWidget->metaObject();
|
|
349 |
int index = object->indexOfMethod(
|
|
350 |
QMetaObject::normalizedSignature(signature));
|
|
351 |
method = object->method(index);
|
|
352 |
return index >= 0;
|
|
353 |
}
|
|
354 |
|
|
355 |
bool HsWidgetHost::hasSignal(const char *signature)
|
|
356 |
{
|
|
357 |
const QMetaObject *object = mWidget->metaObject();
|
|
358 |
int index = object->indexOfSignal(
|
|
359 |
QMetaObject::normalizedSignature(signature));
|
|
360 |
return index >= 0;
|
|
361 |
}
|
|
362 |
|
|
363 |
bool HsWidgetHost::setPreferencesToWidget()
|
|
364 |
{
|
|
365 |
return true;
|
|
366 |
}
|
|
367 |
|
|
368 |
void HsWidgetHost::action_connectComponent()
|
|
369 |
{
|
|
370 |
}
|
|
371 |
|
|
372 |
void HsWidgetHost::action_disconnectComponent()
|
|
373 |
{
|
|
374 |
}
|
|
375 |
|
|
376 |
void HsWidgetHost::action_load()
|
|
377 |
{
|
|
378 |
mWidget = new TestWidget;
|
|
379 |
|
|
380 |
if (!mWidget ||
|
|
381 |
!setMethod("onShow()", mOnShowMethod) ||
|
|
382 |
!setMethod("onHide()", mOnHideMethod)) {
|
|
383 |
mWidget = 0;
|
|
384 |
emit event_faulted();
|
|
385 |
return;
|
|
386 |
}
|
|
387 |
|
|
388 |
setMethod("onInitialize()", mOnInitializeMethod);
|
|
389 |
setMethod("onUninitialize()", mOnUninitializeMethod);
|
|
390 |
|
|
391 |
setProperty("isOnline", mIsOnlineProperty);
|
|
392 |
setProperty("rootPath", mRootPathProperty);
|
|
393 |
|
|
394 |
if (hasSignal("setPreferences(const QStringList&)")) {
|
|
395 |
connect(mWidget, SIGNAL(setPreferences(QStringList)),
|
|
396 |
SLOT(onSetPreferences(QStringList)));
|
|
397 |
}
|
|
398 |
if (hasSignal("finished()")) {
|
|
399 |
connect(mWidget, SIGNAL(finished()),
|
|
400 |
SLOT(onFinished()));
|
|
401 |
}
|
|
402 |
if (hasSignal("error()")) {
|
|
403 |
connect(mWidget, SIGNAL(error()),
|
|
404 |
SLOT(onError()));
|
|
405 |
}
|
|
406 |
|
|
407 |
mWidget->installEventFilter(this);
|
|
408 |
|
|
409 |
//HsScene *scene = HsScene::instance();
|
|
410 |
//setMaximumSize(scene->maximumWidgetSizeInPixels());
|
|
411 |
//setMinimumSize(scene->minimumWidgetSizeInPixels());
|
|
412 |
|
|
413 |
loadPresentation();
|
|
414 |
|
|
415 |
/* mWidget->setParentItem(this);
|
|
416 |
|
|
417 |
setNewSize(mWidget->size());
|
|
418 |
*/
|
|
419 |
}
|
|
420 |
|
|
421 |
void HsWidgetHost::action_unload()
|
|
422 |
{
|
|
423 |
delete mWidget;
|
|
424 |
mWidget = 0;
|
|
425 |
|
|
426 |
mOnInitializeMethod = QMetaMethod();
|
|
427 |
mOnShowMethod = QMetaMethod();
|
|
428 |
mOnHideMethod = QMetaMethod();
|
|
429 |
mOnUninitializeMethod = QMetaMethod();
|
|
430 |
mIsOnlineProperty = QMetaProperty();
|
|
431 |
mRootPathProperty = QMetaProperty();
|
|
432 |
}
|
|
433 |
|
|
434 |
void HsWidgetHost::action_initialize()
|
|
435 |
{
|
|
436 |
//mRootPathProperty.write(mWidget, mComponent->rootPath());
|
|
437 |
setPreferencesToWidget();
|
|
438 |
setOnline(HsScene::instance()->isOnline());
|
|
439 |
mOnInitializeMethod.invoke(mWidget);
|
|
440 |
}
|
|
441 |
|
|
442 |
void HsWidgetHost::action_uninitialize()
|
|
443 |
{
|
|
444 |
mOnUninitializeMethod.invoke(mWidget);
|
|
445 |
}
|
|
446 |
|
|
447 |
void HsWidgetHost::action_show()
|
|
448 |
{
|
|
449 |
if (!mIsFinishing) {
|
|
450 |
mOnShowMethod.invoke(mWidget);
|
|
451 |
}
|
|
452 |
}
|
|
453 |
|
|
454 |
void HsWidgetHost::action_hide()
|
|
455 |
{
|
|
456 |
if (!mIsFinishing) {
|
|
457 |
mOnHideMethod.invoke(mWidget);
|
|
458 |
}
|
|
459 |
}
|
|
460 |
|
|
461 |
void HsWidgetHost::action_finished()
|
|
462 |
{
|
|
463 |
emit finished();
|
|
464 |
}
|
|
465 |
|
|
466 |
void HsWidgetHost::action_faulted()
|
|
467 |
{
|
|
468 |
emit faulted();
|
|
469 |
}
|
|
470 |
|
|
471 |
void HsWidgetHost::action_remove()
|
|
472 |
{
|
|
473 |
mDatabaseId = -1;
|
|
474 |
}
|
|
475 |
|
|
476 |
void HsWidgetHost::action_notifyRemove()
|
|
477 |
{
|
|
478 |
}
|
|
479 |
|
|
480 |
void HsWidgetHost::onFinished()
|
|
481 |
{
|
|
482 |
mIsFinishing = true;
|
|
483 |
emit event_finished();
|
|
484 |
}
|
|
485 |
|
|
486 |
void HsWidgetHost::onError()
|
|
487 |
{
|
|
488 |
mIsFinishing = true;
|
|
489 |
emit event_faulted();
|
|
490 |
}
|
|
491 |
|
|
492 |
void HsWidgetHost::onSetPreferences(const QStringList &names)
|
|
493 |
{
|
|
494 |
Q_UNUSED(names)
|
|
495 |
}
|