18 #include <QMetaObject> |
18 #include <QMetaObject> |
19 #include <QGraphicsLinearLayout> |
19 #include <QGraphicsLinearLayout> |
20 #include <QParallelAnimationGroup> |
20 #include <QParallelAnimationGroup> |
21 #include <QPropertyAnimation> |
21 #include <QPropertyAnimation> |
22 #include <QGraphicsDropShadowEffect> |
22 #include <QGraphicsDropShadowEffect> |
|
23 #include <QGraphicsSceneResizeEvent> |
|
24 |
23 #include <qservicemanager.h> |
25 #include <qservicemanager.h> |
24 #include <qservicefilter.h> |
26 #include <qservicefilter.h> |
25 #include <qserviceinterfacedescriptor.h> |
27 #include <qserviceinterfacedescriptor.h> |
26 |
28 |
27 #include <HbInstance> |
29 #include <HbInstance> |
30 #include "hsdatabase.h" |
32 #include "hsdatabase.h" |
31 #include "hsdomainmodeldatastructures.h" |
33 #include "hsdomainmodeldatastructures.h" |
32 #include "hspage.h" |
34 #include "hspage.h" |
33 #include "hsapp_defs.h" |
35 #include "hsapp_defs.h" |
34 #include "hsscene.h" |
36 #include "hsscene.h" |
35 #include "cadefs.h" |
37 #include "hswidgetcomponentregistry.h" |
36 #include "canotifier.h" |
38 #include "hswidgetcomponent.h" |
37 #include "canotifierfilter.h" |
|
38 #include "caservice.h" |
|
39 #include "caquery.h" |
|
40 #include "caentry.h" |
|
41 |
39 |
42 QTM_USE_NAMESPACE |
40 QTM_USE_NAMESPACE |
43 |
41 |
44 /*! |
42 /*! |
45 \class HsWidgetHost |
43 \class HsWidgetHost |
69 HsWidgetHost::HsWidgetHost(int databaseId, QGraphicsItem *parent) |
67 HsWidgetHost::HsWidgetHost(int databaseId, QGraphicsItem *parent) |
70 : HbWidget(parent), |
68 : HbWidget(parent), |
71 mWidget(0), |
69 mWidget(0), |
72 mPage(0), |
70 mPage(0), |
73 mState(Constructed), |
71 mState(Constructed), |
74 mDatabaseId(databaseId) |
72 mDatabaseId(databaseId), |
75 { |
73 mTapAndHoldIcon(0) |
76 CaQuery query; |
74 { |
77 query.setEntryTypeNames(QStringList(widgetTypeName())); |
75 setFlags(QGraphicsItem::ItemClipsChildrenToShape); |
78 CaNotifierFilter filter(query); |
|
79 CaNotifier *notifier = CaService::instance()->createNotifier(filter); |
|
80 notifier->setParent(this); |
|
81 connect(notifier, |
|
82 SIGNAL(entryChanged(CaEntry,ChangeType)), |
|
83 SLOT(onEntryChanged(CaEntry,ChangeType)), Qt::QueuedConnection); |
|
84 |
76 |
85 /* TODO: Uncomment after the Qt bug has been fixed. |
77 /* TODO: Uncomment after the Qt bug has been fixed. |
86 QGraphicsDropShadowEffect *effect = |
78 QGraphicsDropShadowEffect *effect = |
87 new QGraphicsDropShadowEffect(this); |
79 new QGraphicsDropShadowEffect(this); |
88 effect->setColor(QColor(0, 0, 0, 150)); |
80 effect->setColor(QColor(0, 0, 0, 150)); |
115 data.id = mDatabaseId; |
108 data.id = mDatabaseId; |
116 if (!db->widget(data)) { |
109 if (!db->widget(data)) { |
117 return false; |
110 return false; |
118 } |
111 } |
119 |
112 |
120 mUri = data.uri; |
113 mUri = data.uri; |
121 |
|
122 // Create the hosted widget. |
114 // Create the hosted widget. |
123 QServiceManager manager; |
115 QServiceManager manager; |
124 QServiceFilter filter("com.nokia.symbian.IHomeScreenWidget"); |
116 QServiceFilter filter("com.nokia.symbian.IHomeScreenWidget"); |
125 filter.setServiceName(mUri); |
117 filter.setServiceName(mUri); |
126 QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter); |
118 QList<QServiceInterfaceDescriptor> interfaces = manager.findInterfaces(filter); |
138 delete widgetObject; |
130 delete widgetObject; |
139 return false; |
131 return false; |
140 } |
132 } |
141 |
133 |
142 setProperty("isOnline", mIsOnlineProperty); |
134 setProperty("isOnline", mIsOnlineProperty); |
|
135 setProperty("rootPath", mRootPathProperty); |
|
136 |
143 setMethod("onInitialize()", mOnInitializeMethod); |
137 setMethod("onInitialize()", mOnInitializeMethod); |
144 setMethod("onUninitialize()", mOnUninitializeMethod); |
138 setMethod("onUninitialize()", mOnUninitializeMethod); |
145 |
139 |
146 if (hasSignal("setPreferences(const QStringList&)")) { |
140 if (hasSignal("setPreferences(const QStringList&)")) { |
147 connect(mWidget, SIGNAL(setPreferences(QStringList)), |
141 connect(mWidget, SIGNAL(setPreferences(QStringList)), |
153 } |
147 } |
154 if (hasSignal("error()")) { |
148 if (hasSignal("error()")) { |
155 connect(mWidget, SIGNAL(error()), |
149 connect(mWidget, SIGNAL(error()), |
156 SLOT(onError())); |
150 SLOT(onError())); |
157 } |
151 } |
158 |
152 |
159 loadWidgetPresentation(); |
153 mWidget->installEventFilter(this); |
160 |
154 |
161 QGraphicsLinearLayout *layout = new QGraphicsLinearLayout; |
155 loadWidgetPresentation(); |
162 layout->setContentsMargins(0, 0, 0, 0); |
156 |
163 layout->addItem(mWidget); |
157 HsScene *scene = HsScene::instance(); |
164 setLayout(layout); |
158 setMaximumSize(scene->maximumWidgetSizeInPixels()); |
|
159 setMinimumSize(scene->minimumWidgetSizeInPixels()); |
|
160 |
|
161 mWidget->setParentItem(this); |
|
162 |
|
163 setNewSize(mWidget->size()); |
165 |
164 |
166 return true; |
165 return true; |
167 } |
166 } |
168 |
167 |
169 bool HsWidgetHost::setPage(HsPage *page) |
168 bool HsWidgetHost::setPage(HsPage *page) |
241 "portrait" : "landscape"; |
240 "portrait" : "landscape"; |
242 |
241 |
243 HsWidgetPresentationData data; |
242 HsWidgetPresentationData data; |
244 data.key = key; |
243 data.key = key; |
245 data.setPos(pos()); |
244 data.setPos(pos()); |
246 data.setSize(size()); |
|
247 data.zValue = zValue(); |
245 data.zValue = zValue(); |
248 data.widgetId = databaseId(); |
246 data.widgetId = databaseId(); |
249 |
247 |
250 return db->setWidgetPresentation(data); |
248 return db->setWidgetPresentation(data); |
251 } |
249 } |
252 |
250 |
253 /*! |
251 /*! |
254 Set widget presentation data. Return true if successfull |
252 Set widget presentation data. Return true if successfull. |
255 |
|
256 */ |
253 */ |
257 bool HsWidgetHost::setWidgetPresentationData(HsWidgetPresentationData &presentationData) |
254 bool HsWidgetHost::setWidgetPresentationData(HsWidgetPresentationData &presentationData) |
258 { |
255 { |
259 HsDatabase *db = HsDatabase::instance(); |
256 HsDatabase *db = HsDatabase::instance(); |
260 Q_ASSERT(db); |
257 Q_ASSERT(db); |
356 void HsWidgetHost::initializeWidget() |
353 void HsWidgetHost::initializeWidget() |
357 { |
354 { |
358 if (mState != Constructed) { |
355 if (mState != Constructed) { |
359 return; |
356 return; |
360 } |
357 } |
361 |
358 // bind component to instance |
|
359 HsWidgetComponent *component = HsWidgetComponentRegistry::instance()->component(mUri); |
|
360 Q_ASSERT(component); |
|
361 connect(component, SIGNAL(aboutToUninstall()), SLOT(onFinished()),Qt::QueuedConnection); |
|
362 mRootPathProperty.write(mWidget, component->rootPath()); |
|
363 |
362 setPreferencesToWidget(); |
364 setPreferencesToWidget(); |
363 setOnline(HsScene::instance()->isOnline()); |
365 setOnline(HsScene::instance()->isOnline()); |
364 mOnInitializeMethod.invoke(mWidget); |
366 mOnInitializeMethod.invoke(mWidget); |
365 |
367 |
366 mState = Initialized; |
368 mState = Initialized; |
478 |
481 |
479 animationGroup->start(QAbstractAnimation::DeleteWhenStopped); |
482 animationGroup->start(QAbstractAnimation::DeleteWhenStopped); |
480 } |
483 } |
481 |
484 |
482 /*! |
485 /*! |
|
486 Starts the tap-and-hold animation. |
|
487 */ |
|
488 void HsWidgetHost::startTapAndHoldAnimation() |
|
489 { |
|
490 mTapAndHoldIcon = new HbIconItem("tapandhold_animation"); |
|
491 mTapAndHoldIcon->setZValue(1e6); |
|
492 mTapAndHoldIcon->setParentItem(this); |
|
493 } |
|
494 |
|
495 /*! |
|
496 Stops the tap-and-hold animation. |
|
497 */ |
|
498 void HsWidgetHost::stopTapAndHoldAnimation() |
|
499 { |
|
500 delete mTapAndHoldIcon; |
|
501 mTapAndHoldIcon = 0; |
|
502 } |
|
503 |
|
504 /*! |
|
505 Filters resize events from widgets and resizes inside max/min size boundaries if needed. |
|
506 */ |
|
507 bool HsWidgetHost::eventFilter(QObject *obj, QEvent *event) |
|
508 { |
|
509 if (event->type() == QEvent::GraphicsSceneResize ) { |
|
510 QGraphicsSceneResizeEvent *resizeEvent = static_cast<QGraphicsSceneResizeEvent*>(event); |
|
511 setNewSize(resizeEvent->newSize()); |
|
512 return true; |
|
513 } else { |
|
514 // standard event processing |
|
515 return HbWidget::eventFilter(obj, event); |
|
516 } |
|
517 } |
|
518 |
|
519 /*! |
483 Checks if a property with the given \a name |
520 Checks if a property with the given \a name |
484 in the contained widget. If the property exists the \a |
521 in the contained widget. If the property exists the \a |
485 metaProperty is made to reference to it. Returns true if |
522 metaProperty is made to reference to it. Returns true if |
486 the property was found. Otherwise, returns false. |
523 the property was found. Otherwise, returns false. |
487 */ |
524 */ |
539 mWidget->setProperty(name.toLatin1(), |
576 mWidget->setProperty(name.toLatin1(), |
540 preferences.value(name)); |
577 preferences.value(name)); |
541 } |
578 } |
542 |
579 |
543 return true; |
580 return true; |
|
581 } |
|
582 |
|
583 /*! |
|
584 Resizes and sets preferred size for widget layouts |
|
585 */ |
|
586 void HsWidgetHost::setNewSize(const QSizeF &newSize) |
|
587 { |
|
588 resize(newSize); |
|
589 setPreferredSize(newSize); |
544 } |
590 } |
545 |
591 |
546 /*! |
592 /*! |
547 This slot is connected to the contained widget's |
593 This slot is connected to the contained widget's |
548 setPreferences() signal, if it was defined for |
594 setPreferences() signal, if it was defined for |