1 // Commit: 5c783d0a9a912816813945387903857a314040b5
2 /****************************************************************************
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** No Commercial Usage
12 ** This file contains pre-release code and may not be distributed.
13 ** You may use this file in accordance with the terms and conditions
14 ** contained in the Technology Preview License Agreement accompanying
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
41 ****************************************************************************/
50 // This file is not part of the Qt API. It exists purely as an
51 // implementation detail. This header file may change from version to
52 // version without notice, or even be removed.
59 #include "qsganchors_p.h"
60 #include "qsganchors_p_p.h"
61 #include "qsgitemchangelistener_p.h"
63 #include "qsgcanvas_p.h"
66 #include "qsgclipnode_p.h"
68 #include <private/qpodvector_p.h>
69 #include <private/qdeclarativestate_p.h>
70 #include <private/qdeclarativenullablevalue_p_p.h>
71 #include <private/qdeclarativenotifier_p.h>
72 #include <private/qdeclarativeglobal_p.h>
74 #include <qdeclarative.h>
75 #include <qdeclarativecontext.h>
77 #include <QtCore/qlist.h>
78 #include <QtCore/qdebug.h>
79 #include <QtCore/qelapsedtimer.h>
84 class QSGItemKeyFilter;
85 class QSGLayoutMirroringAttached;
87 //### merge into private?
88 class QSGContents : public QObject, public QSGItemChangeListener
92 QSGContents(QSGItem *item);
97 void childRemoved(QSGItem *item);
98 void childAdded(QSGItem *item);
100 void calcGeometry() { calcWidth(); calcHeight(); }
104 void rectChanged(QRectF);
107 void itemGeometryChanged(QSGItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
108 void itemDestroyed(QSGItem *item);
109 //void itemVisibilityChanged(QSGItem *item)
112 void calcHeight(QSGItem *changed = 0);
113 void calcWidth(QSGItem *changed = 0);
122 class QSGTransformPrivate : public QObjectPrivate
124 Q_DECLARE_PUBLIC(QSGTransform);
126 static QSGTransformPrivate* get(QSGTransform *transform) { return transform->d_func(); }
128 QSGTransformPrivate();
130 QList<QSGItem *> items;
133 class Q_DECLARATIVE_EXPORT QSGItemPrivate : public QObjectPrivate
135 Q_DECLARE_PUBLIC(QSGItem)
138 static QSGItemPrivate* get(QSGItem *item) { return item->d_func(); }
139 static const QSGItemPrivate* get(const QSGItem *item) { return item->d_func(); }
142 void init(QSGItem *parent);
144 QDeclarativeListProperty<QObject> data();
145 QDeclarativeListProperty<QObject> resources();
146 QDeclarativeListProperty<QSGItem> children();
148 QDeclarativeListProperty<QDeclarativeState> states();
149 QDeclarativeListProperty<QDeclarativeTransition> transitions();
151 QString state() const;
152 void setState(const QString &);
154 QSGAnchorLine left() const;
155 QSGAnchorLine right() const;
156 QSGAnchorLine horizontalCenter() const;
157 QSGAnchorLine top() const;
158 QSGAnchorLine bottom() const;
159 QSGAnchorLine verticalCenter() const;
160 QSGAnchorLine baseline() const;
163 static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
164 static int data_count(QDeclarativeListProperty<QObject> *);
165 static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
166 static void data_clear(QDeclarativeListProperty<QObject> *);
168 // resources property
169 static QObject *resources_at(QDeclarativeListProperty<QObject> *, int);
170 static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
171 static int resources_count(QDeclarativeListProperty<QObject> *);
172 static void resources_clear(QDeclarativeListProperty<QObject> *);
175 static void children_append(QDeclarativeListProperty<QSGItem> *, QSGItem *);
176 static int children_count(QDeclarativeListProperty<QSGItem> *);
177 static QSGItem *children_at(QDeclarativeListProperty<QSGItem> *, int);
178 static void children_clear(QDeclarativeListProperty<QSGItem> *);
180 // transform property
181 static int transform_count(QDeclarativeListProperty<QSGTransform> *list);
182 static void transform_append(QDeclarativeListProperty<QSGTransform> *list, QSGTransform *);
183 static QSGTransform *transform_at(QDeclarativeListProperty<QSGTransform> *list, int);
184 static void transform_clear(QDeclarativeListProperty<QSGTransform> *list);
186 QSGAnchors *anchors() const;
187 mutable QSGAnchors *_anchors;
188 QSGContents *_contents;
190 QDeclarativeNullableValue<qreal> baselineOffset;
193 AnchorLines(QSGItem *);
196 QSGAnchorLine hCenter;
198 QSGAnchorLine bottom;
199 QSGAnchorLine vCenter;
200 QSGAnchorLine baseline;
202 mutable AnchorLines *_anchorLines;
203 AnchorLines *anchorLines() const;
216 Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
218 struct ChangeListener {
219 ChangeListener(QSGItemChangeListener *l, QSGItemPrivate::ChangeTypes t) : listener(l), types(t) {}
220 QSGItemChangeListener *listener;
221 QSGItemPrivate::ChangeTypes types;
222 bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
225 void addItemChangeListener(QSGItemChangeListener *listener, ChangeTypes types) {
226 changeListeners.append(ChangeListener(listener, types));
228 void removeItemChangeListener(QSGItemChangeListener *, ChangeTypes types);
229 QPODVector<ChangeListener,4> changeListeners;
231 QDeclarativeStateGroup *_states();
232 QDeclarativeStateGroup *_stateGroup;
234 QSGItem::TransformOrigin origin:5;
238 bool componentComplete:1;
244 bool notifiedFocus:1;
245 bool notifiedActiveFocus:1;
246 bool filtersChildMouseEvents:1;
247 bool explicitVisible:1;
248 bool effectiveVisible:1;
249 bool explicitEnable:1;
250 bool effectiveEnable:1;
251 bool polishScheduled:1;
252 bool inheritedLayoutMirror:1;
253 bool effectiveLayoutMirror:1;
254 bool isMirrorImplicit:1;
255 bool inheritMirrorFromParent:1;
256 bool inheritMirrorFromItem:1;
260 QSGContext *sceneGraphContext() const { return static_cast<QSGCanvasPrivate *>(QObjectPrivate::get(canvas))->context; }
263 QList<QSGItem *> childItems;
264 QList<QSGItem *> paintOrderChildItems() const;
265 void addChild(QSGItem *);
266 void removeChild(QSGItem *);
267 void siblingOrderChanged();
269 class InitializationState {
271 QSGItem *getFocusScope(QSGItem *item);
273 void clear(QSGItem *focusScope);
277 void initCanvas(InitializationState *, QSGCanvas *);
279 QSGItem *subFocusItem;
281 QTransform canvasToItemTransform() const;
282 QTransform itemToCanvasTransform() const;
283 void itemToParentTransform(QTransform &) const;
290 qreal implicitHeight;
297 QSGLayoutMirroringAttached* attachedLayoutDirection;
299 Qt::MouseButtons acceptedMouseButtons;
300 Qt::InputMethodHints imHints;
302 virtual qreal getImplicitWidth() const;
303 virtual qreal getImplicitHeight() const;
304 virtual void implicitWidthChanged();
305 virtual void implicitHeightChanged();
307 void resolveLayoutMirror();
308 void setImplicitLayoutMirror(bool mirror, bool inherit);
309 void setLayoutMirror(bool mirror);
310 bool isMirrored() const {
311 return effectiveLayoutMirror;
314 QPointF computeTransformOrigin() const;
315 QList<QSGTransform *> transforms;
316 virtual void transformChanged();
318 QSGItemKeyFilter *keyHandler;
319 void deliverKeyEvent(QKeyEvent *);
320 void deliverInputMethodEvent(QInputMethodEvent *);
321 void deliverFocusEvent(QFocusEvent *);
322 void deliverMouseEvent(QGraphicsSceneMouseEvent *);
323 void deliverWheelEvent(QGraphicsSceneWheelEvent *);
324 void deliverTouchEvent(QTouchEvent *);
325 void deliverHoverEvent(QGraphicsSceneHoverEvent *);
327 bool calcEffectiveVisible() const;
328 void setEffectiveVisibleRecur(bool);
329 bool calcEffectiveEnable() const;
330 void setEffectiveEnableRecur(bool);
334 TransformOrigin = 0x00000001,
335 Transform = 0x00000002,
336 BasicTransform = 0x00000004,
337 Position = 0x00000008,
341 Content = 0x00000040,
343 OpacityValue = 0x00000100,
344 ChildrenChanged = 0x00000200,
345 ChildrenStackingChanged = 0x00000400,
346 ParentChanged = 0x00000800,
351 EffectReference = 0x00008000,
352 Visible = 0x00010000,
353 HideReference = 0x00020000,
354 // When you add an attribute here, don't forget to update
357 TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas,
358 ComplexTransformUpdateMask = Transform | Canvas,
359 ContentUpdateMask = Size | Content | Smooth | Canvas,
360 ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas,
363 quint32 dirtyAttributes;
364 QString dirtyToString() const;
365 void dirty(DirtyType);
366 void addToDirtyList();
367 void removeFromDirtyList();
368 QSGItem *nextDirtyItem;
369 QSGItem**prevDirtyItem;
371 inline QSGTransformNode *itemNode();
372 inline QSGNode *childContainerNode();
383 QSGTransformNode *itemNodeInstance;
384 QSGOpacityNode *opacityNode;
385 QSGDefaultClipNode *clipNode;
386 QSGRootNode *rootNode;
391 virtual QSGTransformNode *createTransformNode();
393 // A reference from an effect item means that this item is used by the effect, so
394 // it should insert a root node.
395 void refFromEffectItem(bool hide);
396 void derefFromEffectItem(bool unhide);
400 void itemChange(QSGItem::ItemChange, const QSGItem::ItemChangeData &);
402 virtual void mirrorChange() {}
404 static qint64 consistentTime;
405 static void setConsistentTime(qint64 t);
406 static void start(QElapsedTimer &);
407 static qint64 elapsed(QElapsedTimer &);
408 static qint64 restart(QElapsedTimer &);
412 Key filters can be installed on a QSGItem, but not removed. Currently they
413 are only used by attached objects (which are only destroyed on Item
414 destruction), so this isn't a problem. If in future this becomes any form
415 of public API, they will have to support removal too.
417 class QSGItemKeyFilter
420 QSGItemKeyFilter(QSGItem * = 0);
421 virtual ~QSGItemKeyFilter();
423 virtual void keyPressed(QKeyEvent *event, bool post);
424 virtual void keyReleased(QKeyEvent *event, bool post);
425 virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
426 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
427 virtual void componentComplete();
432 QSGItemKeyFilter *m_next;
435 class QSGKeyNavigationAttachedPrivate : public QObjectPrivate
438 QSGKeyNavigationAttachedPrivate()
440 left(0), right(0), up(0), down(0), tab(0), backtab(0),
441 leftSet(false), rightSet(false), upSet(false), downSet(false),
442 tabSet(false), backtabSet(false) {}
458 class QSGKeyNavigationAttached : public QObject, public QSGItemKeyFilter
461 Q_DECLARE_PRIVATE(QSGKeyNavigationAttached)
463 Q_PROPERTY(QSGItem *left READ left WRITE setLeft NOTIFY leftChanged)
464 Q_PROPERTY(QSGItem *right READ right WRITE setRight NOTIFY rightChanged)
465 Q_PROPERTY(QSGItem *up READ up WRITE setUp NOTIFY upChanged)
466 Q_PROPERTY(QSGItem *down READ down WRITE setDown NOTIFY downChanged)
467 Q_PROPERTY(QSGItem *tab READ tab WRITE setTab NOTIFY tabChanged)
468 Q_PROPERTY(QSGItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged)
469 Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
474 QSGKeyNavigationAttached(QObject * = 0);
476 QSGItem *left() const;
477 void setLeft(QSGItem *);
478 QSGItem *right() const;
479 void setRight(QSGItem *);
481 void setUp(QSGItem *);
482 QSGItem *down() const;
483 void setDown(QSGItem *);
484 QSGItem *tab() const;
485 void setTab(QSGItem *);
486 QSGItem *backtab() const;
487 void setBacktab(QSGItem *);
489 enum Priority { BeforeItem, AfterItem };
490 Priority priority() const;
491 void setPriority(Priority);
493 static QSGKeyNavigationAttached *qmlAttachedProperties(QObject *);
501 void backtabChanged();
502 void priorityChanged();
505 virtual void keyPressed(QKeyEvent *event, bool post);
506 virtual void keyReleased(QKeyEvent *event, bool post);
507 void setFocusNavigation(QSGItem *currentItem, const char *dir);
510 class QSGLayoutMirroringAttached : public QObject
513 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged)
514 Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged)
517 explicit QSGLayoutMirroringAttached(QObject *parent = 0);
519 bool enabled() const;
520 void setEnabled(bool);
523 bool childrenInherit() const;
524 void setChildrenInherit(bool);
526 static QSGLayoutMirroringAttached *qmlAttachedProperties(QObject *);
528 void enabledChanged();
529 void childrenInheritChanged();
531 friend class QSGItemPrivate;
532 QSGItemPrivate *itemPrivate;
535 class QSGKeysAttachedPrivate : public QObjectPrivate
538 QSGKeysAttachedPrivate()
539 : QObjectPrivate(), inPress(false), inRelease(false)
540 , inIM(false), enabled(true), imeItem(0), item(0)
543 bool isConnected(const char *signalName);
553 QList<QSGItem *> targets;
557 class QSGKeysAttached : public QObject, public QSGItemKeyFilter
560 Q_DECLARE_PRIVATE(QSGKeysAttached)
562 Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
563 Q_PROPERTY(QDeclarativeListProperty<QSGItem> forwardTo READ forwardTo)
564 Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
569 QSGKeysAttached(QObject *parent=0);
572 bool enabled() const { Q_D(const QSGKeysAttached); return d->enabled; }
573 void setEnabled(bool enabled) {
574 Q_D(QSGKeysAttached);
575 if (enabled != d->enabled) {
576 d->enabled = enabled;
577 emit enabledChanged();
581 enum Priority { BeforeItem, AfterItem};
582 Priority priority() const;
583 void setPriority(Priority);
585 QDeclarativeListProperty<QSGItem> forwardTo() {
586 Q_D(QSGKeysAttached);
587 return QDeclarativeListProperty<QSGItem>(this, d->targets);
590 virtual void componentComplete();
592 static QSGKeysAttached *qmlAttachedProperties(QObject *);
595 void enabledChanged();
596 void priorityChanged();
597 void pressed(QSGKeyEvent *event);
598 void released(QSGKeyEvent *event);
599 void digit0Pressed(QSGKeyEvent *event);
600 void digit1Pressed(QSGKeyEvent *event);
601 void digit2Pressed(QSGKeyEvent *event);
602 void digit3Pressed(QSGKeyEvent *event);
603 void digit4Pressed(QSGKeyEvent *event);
604 void digit5Pressed(QSGKeyEvent *event);
605 void digit6Pressed(QSGKeyEvent *event);
606 void digit7Pressed(QSGKeyEvent *event);
607 void digit8Pressed(QSGKeyEvent *event);
608 void digit9Pressed(QSGKeyEvent *event);
610 void leftPressed(QSGKeyEvent *event);
611 void rightPressed(QSGKeyEvent *event);
612 void upPressed(QSGKeyEvent *event);
613 void downPressed(QSGKeyEvent *event);
614 void tabPressed(QSGKeyEvent *event);
615 void backtabPressed(QSGKeyEvent *event);
617 void asteriskPressed(QSGKeyEvent *event);
618 void numberSignPressed(QSGKeyEvent *event);
619 void escapePressed(QSGKeyEvent *event);
620 void returnPressed(QSGKeyEvent *event);
621 void enterPressed(QSGKeyEvent *event);
622 void deletePressed(QSGKeyEvent *event);
623 void spacePressed(QSGKeyEvent *event);
624 void backPressed(QSGKeyEvent *event);
625 void cancelPressed(QSGKeyEvent *event);
626 void selectPressed(QSGKeyEvent *event);
627 void yesPressed(QSGKeyEvent *event);
628 void noPressed(QSGKeyEvent *event);
629 void context1Pressed(QSGKeyEvent *event);
630 void context2Pressed(QSGKeyEvent *event);
631 void context3Pressed(QSGKeyEvent *event);
632 void context4Pressed(QSGKeyEvent *event);
633 void callPressed(QSGKeyEvent *event);
634 void hangupPressed(QSGKeyEvent *event);
635 void flipPressed(QSGKeyEvent *event);
636 void menuPressed(QSGKeyEvent *event);
637 void volumeUpPressed(QSGKeyEvent *event);
638 void volumeDownPressed(QSGKeyEvent *event);
641 virtual void keyPressed(QKeyEvent *event, bool post);
642 virtual void keyReleased(QKeyEvent *event, bool post);
643 virtual void inputMethodEvent(QInputMethodEvent *, bool post);
644 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
646 const QByteArray keyToSignal(int key) {
647 QByteArray keySignal;
648 if (key >= Qt::Key_0 && key <= Qt::Key_9) {
649 keySignal = "digit0Pressed";
650 keySignal[5] = '0' + (key - Qt::Key_0);
653 while (sigMap[i].key && sigMap[i].key != key)
655 keySignal = sigMap[i].sig;
665 static const SigMap sigMap[];
668 QSGTransformNode *QSGItemPrivate::itemNode()
670 if (!itemNodeInstance) {
671 itemNodeInstance = createTransformNode();
672 #ifdef QML_RUNTIME_TESTING
674 itemNodeInstance->description = QString::fromLatin1("QSGItem(%1)").arg(QString::fromLatin1(q->metaObject()->className()));
677 return itemNodeInstance;
680 QSGNode *QSGItemPrivate::childContainerNode()
683 groupNode = new QSGNode();
685 rootNode->appendChildNode(groupNode);
687 clipNode->appendChildNode(groupNode);
688 else if (opacityNode)
689 opacityNode->appendChildNode(groupNode);
691 itemNode()->appendChildNode(groupNode);
692 #ifdef QML_RUNTIME_TESTING
693 groupNode->description = QLatin1String("group");
699 Q_DECLARE_OPERATORS_FOR_FLAGS(QSGItemPrivate::ChangeTypes);
703 QML_DECLARE_TYPE(QSGKeysAttached)
704 QML_DECLARE_TYPEINFO(QSGKeysAttached, QML_HAS_ATTACHED_PROPERTIES)
705 QML_DECLARE_TYPE(QSGKeyNavigationAttached)
706 QML_DECLARE_TYPEINFO(QSGKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES)
707 QML_DECLARE_TYPE(QSGLayoutMirroringAttached)
708 QML_DECLARE_TYPEINFO(QSGLayoutMirroringAttached, QML_HAS_ATTACHED_PROPERTIES)
710 #endif // QSGITEM_P_H