Added new convenience readonly visibleChildren property to Item
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitem_p.h
1 // Commit: 5c783d0a9a912816813945387903857a314040b5
2 /****************************************************************************
3 **
4 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
5 ** Contact: http://www.qt-project.org/
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
33 **
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKITEM_P_H
44 #define QQUICKITEM_P_H
45
46 //
47 //  W A R N I N G
48 //  -------------
49 //
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.
53 //
54 // We mean it.
55 //
56
57 #include "qquickitem.h"
58
59 #include "qquickanchors_p.h"
60 #include "qquickanchors_p_p.h"
61 #include "qquickitemchangelistener_p.h"
62
63 #include "qquickcanvas_p.h"
64
65 #include <QtQuick/qsgnode.h>
66 #include "qquickclipnode_p.h"
67
68 #include <private/qpodvector_p.h>
69 #include <QtQuick/private/qdeclarativestate_p.h>
70 #include <private/qdeclarativenullablevalue_p_p.h>
71 #include <private/qdeclarativenotifier_p.h>
72 #include <private/qdeclarativeglobal_p.h>
73
74 #include <qdeclarative.h>
75 #include <qdeclarativecontext.h>
76
77 #include <QtCore/qlist.h>
78 #include <QtCore/qdebug.h>
79 #include <QtCore/qelapsedtimer.h>
80
81 #include <QtQuick/private/qquickshadereffectsource_p.h>
82 #include <QtQuick/private/qquickshadereffect_p.h>
83
84 QT_BEGIN_NAMESPACE
85
86 class QNetworkReply;
87 class QQuickItemKeyFilter;
88 class QQuickLayoutMirroringAttached;
89 class QQuickScreenAttached;
90
91 class QQuickContents : public QQuickItemChangeListener
92 {
93 public:
94     QQuickContents(QQuickItem *item);
95     ~QQuickContents();
96
97     QRectF rectF() const { return QRectF(m_x, m_y, m_width, m_height); }
98
99     inline void calcGeometry(QQuickItem *changed = 0);
100     void complete();
101
102 protected:
103     void itemGeometryChanged(QQuickItem *item, const QRectF &newGeometry, const QRectF &oldGeometry);
104     void itemDestroyed(QQuickItem *item);
105     void itemChildAdded(QQuickItem *, QQuickItem *);
106     void itemChildRemoved(QQuickItem *, QQuickItem *);
107     //void itemVisibilityChanged(QQuickItem *item)
108
109 private:
110     bool calcHeight(QQuickItem *changed = 0);
111     bool calcWidth(QQuickItem *changed = 0);
112     void updateRect();
113
114     QQuickItem *m_item;
115     qreal m_x;
116     qreal m_y;
117     qreal m_width;
118     qreal m_height;
119 };
120
121 void QQuickContents::calcGeometry(QQuickItem *changed)
122 {
123     bool wChanged = calcWidth(changed);
124     bool hChanged = calcHeight(changed);
125     if (wChanged || hChanged)
126         updateRect();
127 }
128
129 class QQuickTransformPrivate : public QObjectPrivate
130 {
131     Q_DECLARE_PUBLIC(QQuickTransform);
132 public:
133     static QQuickTransformPrivate* get(QQuickTransform *transform) { return transform->d_func(); }
134
135     QQuickTransformPrivate();
136
137     QList<QQuickItem *> items;
138 };
139
140
141 class QQuickItemLayer : public QObject, public QQuickItemChangeListener
142 {
143     Q_OBJECT
144     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
145     Q_PROPERTY(QSize textureSize READ size WRITE setSize NOTIFY sizeChanged)
146     Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
147     Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
148     Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
149     Q_PROPERTY(QQuickShaderEffectSource::WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
150     Q_PROPERTY(QQuickShaderEffectSource::Format format READ format WRITE setFormat NOTIFY formatChanged)
151     Q_PROPERTY(QByteArray samplerName READ name WRITE setName NOTIFY nameChanged)
152     Q_PROPERTY(QDeclarativeComponent *effect READ effect WRITE setEffect NOTIFY effectChanged)
153 public:
154     QQuickItemLayer(QQuickItem *item);
155     ~QQuickItemLayer();
156
157     void classBegin();
158     void componentComplete();
159
160     bool enabled() const { return m_enabled; }
161     void setEnabled(bool enabled);
162
163     bool mipmap() const { return m_mipmap; }
164     void setMipmap(bool mipmap);
165
166     bool smooth() const { return m_smooth; }
167     void setSmooth(bool s);
168
169     QSize size() const { return m_size; }
170     void setSize(const QSize &size);
171
172     QQuickShaderEffectSource::Format format() const { return m_format; }
173     void setFormat(QQuickShaderEffectSource::Format f);
174
175     QRectF sourceRect() const { return m_sourceRect; }
176     void setSourceRect(const QRectF &sourceRect);
177
178     QQuickShaderEffectSource::WrapMode wrapMode() const { return m_wrapMode; }
179     void setWrapMode(QQuickShaderEffectSource::WrapMode mode);
180
181     QByteArray name() const { return m_name; }
182     void setName(const QByteArray &name);
183
184     QDeclarativeComponent *effect() const { return m_effectComponent; }
185     void setEffect(QDeclarativeComponent *effect);
186
187     QQuickShaderEffectSource *effectSource() const { return m_effectSource; }
188
189     void itemGeometryChanged(QQuickItem *, const QRectF &, const QRectF &);
190     void itemOpacityChanged(QQuickItem *);
191     void itemParentChanged(QQuickItem *, QQuickItem *);
192     void itemSiblingOrderChanged(QQuickItem *);
193     void itemVisibilityChanged(QQuickItem *);
194
195     void updateMatrix();
196     void updateGeometry();
197     void updateOpacity();
198     void updateZ();
199
200 signals:
201     void enabledChanged(bool enabled);
202     void sizeChanged(const QSize &size);
203     void mipmapChanged(bool mipmap);
204     void wrapModeChanged(QQuickShaderEffectSource::WrapMode mode);
205     void nameChanged(const QByteArray &name);
206     void effectChanged(QDeclarativeComponent *component);
207     void smoothChanged(bool smooth);
208     void formatChanged(QQuickShaderEffectSource::Format format);
209     void sourceRectChanged(const QRectF &sourceRect);
210
211 private:
212     void activate();
213     void deactivate();
214     void activateEffect();
215     void deactivateEffect();
216
217     QQuickItem *m_item;
218     bool m_enabled;
219     bool m_mipmap;
220     bool m_smooth;
221     bool m_componentComplete;
222     QQuickShaderEffectSource::WrapMode m_wrapMode;
223     QQuickShaderEffectSource::Format m_format;
224     QSize m_size;
225     QRectF m_sourceRect;
226     QByteArray m_name;
227     QDeclarativeComponent *m_effectComponent;
228     QQuickItem *m_effect;
229     QQuickShaderEffectSource *m_effectSource;
230 };
231
232 class Q_QUICK_EXPORT QQuickItemPrivate : public QObjectPrivate
233 {
234     Q_DECLARE_PUBLIC(QQuickItem)
235
236 public:
237     static QQuickItemPrivate* get(QQuickItem *item) { return item->d_func(); }
238     static const QQuickItemPrivate* get(const QQuickItem *item) { return item->d_func(); }
239
240     static void registerAccessorProperties();
241
242     QQuickItemPrivate();
243     ~QQuickItemPrivate();
244     void init(QQuickItem *parent);
245
246     QDeclarativeListProperty<QObject> data();
247     QDeclarativeListProperty<QObject> resources();
248     QDeclarativeListProperty<QQuickItem> children();
249     QDeclarativeListProperty<QQuickItem> visibleChildren();
250
251     QDeclarativeListProperty<QDeclarativeState> states();
252     QDeclarativeListProperty<QDeclarativeTransition> transitions();
253
254     QString state() const;
255     void setState(const QString &);
256
257     QQuickAnchorLine left() const;
258     QQuickAnchorLine right() const;
259     QQuickAnchorLine horizontalCenter() const;
260     QQuickAnchorLine top() const;
261     QQuickAnchorLine bottom() const;
262     QQuickAnchorLine verticalCenter() const;
263     QQuickAnchorLine baseline() const;
264
265     QQuickItemLayer *layer() const;
266
267     // data property
268     static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
269     static int data_count(QDeclarativeListProperty<QObject> *);
270     static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
271     static void data_clear(QDeclarativeListProperty<QObject> *);
272
273     // resources property
274     static QObject *resources_at(QDeclarativeListProperty<QObject> *, int);
275     static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
276     static int resources_count(QDeclarativeListProperty<QObject> *);
277     static void resources_clear(QDeclarativeListProperty<QObject> *);
278
279     // children property
280     static void children_append(QDeclarativeListProperty<QQuickItem> *, QQuickItem *);
281     static int children_count(QDeclarativeListProperty<QQuickItem> *);
282     static QQuickItem *children_at(QDeclarativeListProperty<QQuickItem> *, int);
283     static void children_clear(QDeclarativeListProperty<QQuickItem> *);
284
285     // visibleChildren property
286     static void visibleChildren_append(QDeclarativeListProperty<QQuickItem> *prop, QQuickItem *o);
287     static int visibleChildren_count(QDeclarativeListProperty<QQuickItem> *prop);
288     static QQuickItem *visibleChildren_at(QDeclarativeListProperty<QQuickItem> *prop, int index);
289
290     // transform property
291     static int transform_count(QDeclarativeListProperty<QQuickTransform> *list);
292     static void transform_append(QDeclarativeListProperty<QQuickTransform> *list, QQuickTransform *);
293     static QQuickTransform *transform_at(QDeclarativeListProperty<QQuickTransform> *list, int);
294     static void transform_clear(QDeclarativeListProperty<QQuickTransform> *list);
295
296     QQuickAnchors *anchors() const;
297     mutable QQuickAnchors *_anchors;
298     QQuickContents *_contents;
299
300     QDeclarativeNullableValue<qreal> baselineOffset;
301
302     struct AnchorLines {
303         AnchorLines(QQuickItem *);
304         QQuickAnchorLine left;
305         QQuickAnchorLine right;
306         QQuickAnchorLine hCenter;
307         QQuickAnchorLine top;
308         QQuickAnchorLine bottom;
309         QQuickAnchorLine vCenter;
310         QQuickAnchorLine baseline;
311     };
312     mutable AnchorLines *_anchorLines;
313     AnchorLines *anchorLines() const;
314
315     enum ChangeType {
316         Geometry = 0x01,
317         SiblingOrder = 0x02,
318         Visibility = 0x04,
319         Opacity = 0x08,
320         Destroyed = 0x10,
321         Parent = 0x20,
322         Children = 0x40,
323         Rotation = 0x80,
324     };
325
326     Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
327
328     enum GeometryChangeType {
329         NoChange = 0,
330         XChange = 0x01,
331         YChange = 0x02,
332         WidthChange = 0x04,
333         HeightChange = 0x08,
334         SizeChange = WidthChange | HeightChange,
335         GeometryChange = XChange | YChange | SizeChange
336     };
337
338     Q_DECLARE_FLAGS(GeometryChangeTypes, GeometryChangeType)
339
340     struct ChangeListener {
341         ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::ChangeTypes t) : listener(l), types(t), gTypes(GeometryChange) {}
342         ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::GeometryChangeTypes gt) : listener(l), types(Geometry), gTypes(gt) {}
343         QQuickItemChangeListener *listener;
344         QQuickItemPrivate::ChangeTypes types;
345         QQuickItemPrivate::GeometryChangeTypes gTypes;  //NOTE: not used for ==
346         bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
347     };
348
349     void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types) {
350         changeListeners.append(ChangeListener(listener, types));
351     }
352     void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types);
353     void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types);
354     void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types);
355     QPODVector<ChangeListener,4> changeListeners;
356
357     QDeclarativeStateGroup *_states();
358     QDeclarativeStateGroup *_stateGroup;
359
360     QQuickItem::TransformOrigin origin:5;
361     quint32 flags:5;
362     bool widthValid:1;
363     bool heightValid:1;
364     bool componentComplete:1;
365     bool keepMouse:1;
366     bool keepTouch:1;
367     bool hoverEnabled:1;
368     bool smooth:1;
369     bool focus:1;
370     bool activeFocus:1;
371     bool notifiedFocus:1;
372     bool notifiedActiveFocus:1;
373     bool filtersChildMouseEvents:1;
374     bool explicitVisible:1;
375     bool effectiveVisible:1;
376     bool explicitEnable:1;
377     bool effectiveEnable:1;
378     bool polishScheduled:1;
379     bool inheritedLayoutMirror:1;
380     bool effectiveLayoutMirror:1;
381     bool isMirrorImplicit:1;
382     bool inheritMirrorFromParent:1;
383     bool inheritMirrorFromItem:1;
384     bool childrenDoNotOverlap:1;
385     bool staticSubtreeGeometry:1;
386     bool isAccessible:1;
387
388     QQuickCanvas *canvas;
389     QSGContext *sceneGraphContext() const { Q_ASSERT(canvas); return static_cast<QQuickCanvasPrivate *>(QObjectPrivate::get(canvas))->context; }
390
391     QQuickItem *parentItem;
392     QDeclarativeNotifier parentNotifier;
393
394     QList<QQuickItem *> childItems;
395     mutable QList<QQuickItem *> *sortedChildItems;
396     QList<QQuickItem *> paintOrderChildItems() const;
397     void addChild(QQuickItem *);
398     void removeChild(QQuickItem *);
399     void siblingOrderChanged();
400
401     inline void markSortedChildrenDirty(QQuickItem *child) {
402         // If sortedChildItems == &childItems then all in childItems have z == 0
403         // and we don't need to invalidate if the changed item also has z == 0.
404         if (child->z() != 0. || sortedChildItems != &childItems) {
405             if (sortedChildItems != &childItems)
406                 delete sortedChildItems;
407             sortedChildItems = 0;
408         }
409     }
410
411     class InitializationState {
412     public:
413         QQuickItem *getFocusScope(QQuickItem *item);
414         void clear();
415         void clear(QQuickItem *focusScope);
416     private:
417         QQuickItem *focusScope;
418     };
419     void initCanvas(InitializationState *, QQuickCanvas *);
420
421     QQuickItem *subFocusItem;
422
423     QTransform canvasToItemTransform() const;
424     QTransform itemToCanvasTransform() const;
425     void itemToParentTransform(QTransform &) const;
426
427     qreal x;
428     qreal y;
429     qreal width;
430     qreal height;
431     qreal implicitWidth;
432     qreal implicitHeight;
433
434     qreal z;
435     qreal scale;
436     qreal rotation;
437     qreal opacity;
438
439     QQuickLayoutMirroringAttached* attachedLayoutDirection;
440
441     Qt::MouseButtons acceptedMouseButtons;
442     Qt::InputMethodHints imHints;
443
444     void setAccessibleFlagAndListener();
445
446     QPointF transformOriginPoint;
447
448     virtual qreal getImplicitWidth() const;
449     virtual qreal getImplicitHeight() const;
450     virtual void implicitWidthChanged();
451     virtual void implicitHeightChanged();
452
453     void resolveLayoutMirror();
454     void setImplicitLayoutMirror(bool mirror, bool inherit);
455     void setLayoutMirror(bool mirror);
456     bool isMirrored() const {
457         return effectiveLayoutMirror;
458     }
459
460     void emitChildrenRectChanged(const QRectF &rect) {
461         Q_Q(QQuickItem);
462         emit q->childrenRectChanged(rect);
463     }
464
465     QPointF computeTransformOrigin() const;
466     QList<QQuickTransform *> transforms;
467     virtual void transformChanged();
468
469     QQuickItemKeyFilter *keyHandler;
470     void deliverKeyEvent(QKeyEvent *);
471     void deliverInputMethodEvent(QInputMethodEvent *);
472     void deliverFocusEvent(QFocusEvent *);
473     void deliverMouseEvent(QMouseEvent *);
474     void deliverWheelEvent(QWheelEvent *);
475     void deliverTouchEvent(QTouchEvent *);
476     void deliverHoverEvent(QHoverEvent *);
477     void deliverDragEvent(QEvent *);
478
479     bool calcEffectiveVisible() const;
480     bool setEffectiveVisibleRecur(bool);
481     bool calcEffectiveEnable() const;
482     void setEffectiveEnableRecur(QQuickItem *scope, bool);
483
484     // XXX todo
485     enum DirtyType {
486         TransformOrigin         = 0x00000001,
487         Transform               = 0x00000002,
488         BasicTransform          = 0x00000004,
489         Position                = 0x00000008,
490         Size                    = 0x00000010,
491
492         ZValue                  = 0x00000020,
493         Content                 = 0x00000040,
494         Smooth                  = 0x00000080,
495         OpacityValue            = 0x00000100,
496         ChildrenChanged         = 0x00000200,
497         ChildrenStackingChanged = 0x00000400,
498         ParentChanged           = 0x00000800,
499
500         Clip                    = 0x00001000,
501         Canvas                  = 0x00002000,
502
503         EffectReference         = 0x00008000,
504         Visible                 = 0x00010000,
505         HideReference           = 0x00020000,
506         PerformanceHints        = 0x00040000,
507         // When you add an attribute here, don't forget to update
508         // dirtyToString()
509
510         TransformUpdateMask     = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas,
511         ComplexTransformUpdateMask     = Transform | Canvas,
512         ContentUpdateMask       = Size | Content | Smooth | Canvas,
513         ChildrenUpdateMask      = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas
514
515     };
516     quint32 dirtyAttributes;
517     QString dirtyToString() const;
518     void dirty(DirtyType);
519     void addToDirtyList();
520     void removeFromDirtyList();
521     QQuickItem *nextDirtyItem;
522     QQuickItem**prevDirtyItem;
523
524     inline QSGTransformNode *itemNode();
525     inline QSGNode *childContainerNode();
526
527     /*
528       QSGNode order is:
529          - itemNode
530          - (opacityNode)
531          - (clipNode)
532          - (effectNode)
533          - groupNode
534      */
535
536     QSGTransformNode *itemNodeInstance;
537     QSGOpacityNode *opacityNode;
538     QQuickDefaultClipNode *clipNode;
539     QSGRootNode *rootNode;
540     QSGNode *groupNode;
541     QSGNode *paintNode;
542     QSGNode *beforePaintNode;
543
544     virtual QSGTransformNode *createTransformNode();
545
546     // A reference from an effect item means that this item is used by the effect, so
547     // it should insert a root node.
548     void refFromEffectItem(bool hide);
549     void derefFromEffectItem(bool unhide);
550     int effectRefCount;
551     int hideRefCount;
552
553     void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &);
554
555     virtual void mirrorChange() {}
556
557     QQuickScreenAttached *screenAttached;
558
559     mutable QQuickItemLayer *_layer;
560
561     static qint64 consistentTime;
562     static void setConsistentTime(qint64 t);
563     static void start(QElapsedTimer &);
564     static qint64 elapsed(QElapsedTimer &);
565     static qint64 restart(QElapsedTimer &);
566 };
567
568 /*
569     Key filters can be installed on a QQuickItem, but not removed.  Currently they
570     are only used by attached objects (which are only destroyed on Item
571     destruction), so this isn't a problem.  If in future this becomes any form
572     of public API, they will have to support removal too.
573 */
574 class QQuickItemKeyFilter
575 {
576 public:
577     QQuickItemKeyFilter(QQuickItem * = 0);
578     virtual ~QQuickItemKeyFilter();
579
580     virtual void keyPressed(QKeyEvent *event, bool post);
581     virtual void keyReleased(QKeyEvent *event, bool post);
582     virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
583     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
584     virtual void componentComplete();
585
586     bool m_processPost;
587
588 private:
589     QQuickItemKeyFilter *m_next;
590 };
591
592 class QQuickKeyNavigationAttachedPrivate : public QObjectPrivate
593 {
594 public:
595     QQuickKeyNavigationAttachedPrivate()
596         : QObjectPrivate(),
597           left(0), right(0), up(0), down(0), tab(0), backtab(0),
598           leftSet(false), rightSet(false), upSet(false), downSet(false),
599           tabSet(false), backtabSet(false) {}
600
601     QQuickItem *left;
602     QQuickItem *right;
603     QQuickItem *up;
604     QQuickItem *down;
605     QQuickItem *tab;
606     QQuickItem *backtab;
607     bool leftSet : 1;
608     bool rightSet : 1;
609     bool upSet : 1;
610     bool downSet : 1;
611     bool tabSet : 1;
612     bool backtabSet : 1;
613 };
614
615 class QQuickKeyNavigationAttached : public QObject, public QQuickItemKeyFilter
616 {
617     Q_OBJECT
618     Q_DECLARE_PRIVATE(QQuickKeyNavigationAttached)
619
620     Q_PROPERTY(QQuickItem *left READ left WRITE setLeft NOTIFY leftChanged)
621     Q_PROPERTY(QQuickItem *right READ right WRITE setRight NOTIFY rightChanged)
622     Q_PROPERTY(QQuickItem *up READ up WRITE setUp NOTIFY upChanged)
623     Q_PROPERTY(QQuickItem *down READ down WRITE setDown NOTIFY downChanged)
624     Q_PROPERTY(QQuickItem *tab READ tab WRITE setTab NOTIFY tabChanged)
625     Q_PROPERTY(QQuickItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged)
626     Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
627
628     Q_ENUMS(Priority)
629
630 public:
631     QQuickKeyNavigationAttached(QObject * = 0);
632
633     QQuickItem *left() const;
634     void setLeft(QQuickItem *);
635     QQuickItem *right() const;
636     void setRight(QQuickItem *);
637     QQuickItem *up() const;
638     void setUp(QQuickItem *);
639     QQuickItem *down() const;
640     void setDown(QQuickItem *);
641     QQuickItem *tab() const;
642     void setTab(QQuickItem *);
643     QQuickItem *backtab() const;
644     void setBacktab(QQuickItem *);
645
646     enum Priority { BeforeItem, AfterItem };
647     Priority priority() const;
648     void setPriority(Priority);
649
650     static QQuickKeyNavigationAttached *qmlAttachedProperties(QObject *);
651
652 Q_SIGNALS:
653     void leftChanged();
654     void rightChanged();
655     void upChanged();
656     void downChanged();
657     void tabChanged();
658     void backtabChanged();
659     void priorityChanged();
660
661 private:
662     virtual void keyPressed(QKeyEvent *event, bool post);
663     virtual void keyReleased(QKeyEvent *event, bool post);
664     void setFocusNavigation(QQuickItem *currentItem, const char *dir);
665 };
666
667 class QQuickLayoutMirroringAttached : public QObject
668 {
669     Q_OBJECT
670     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged)
671     Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged)
672
673 public:
674     explicit QQuickLayoutMirroringAttached(QObject *parent = 0);
675
676     bool enabled() const;
677     void setEnabled(bool);
678     void resetEnabled();
679
680     bool childrenInherit() const;
681     void setChildrenInherit(bool);
682
683     static QQuickLayoutMirroringAttached *qmlAttachedProperties(QObject *);
684 Q_SIGNALS:
685     void enabledChanged();
686     void childrenInheritChanged();
687 private:
688     friend class QQuickItemPrivate;
689     QQuickItemPrivate *itemPrivate;
690 };
691
692 class QQuickKeysAttachedPrivate : public QObjectPrivate
693 {
694 public:
695     QQuickKeysAttachedPrivate()
696         : QObjectPrivate(), inPress(false), inRelease(false)
697         , inIM(false), enabled(true), imeItem(0), item(0)
698     {}
699
700     bool isConnected(const char *signalName);
701
702     //loop detection
703     bool inPress:1;
704     bool inRelease:1;
705     bool inIM:1;
706
707     bool enabled : 1;
708
709     QQuickItem *imeItem;
710     QList<QQuickItem *> targets;
711     QQuickItem *item;
712 };
713
714 class QQuickKeysAttached : public QObject, public QQuickItemKeyFilter
715 {
716     Q_OBJECT
717     Q_DECLARE_PRIVATE(QQuickKeysAttached)
718
719     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
720     Q_PROPERTY(QDeclarativeListProperty<QQuickItem> forwardTo READ forwardTo)
721     Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
722
723     Q_ENUMS(Priority)
724
725 public:
726     QQuickKeysAttached(QObject *parent=0);
727     ~QQuickKeysAttached();
728
729     bool enabled() const { Q_D(const QQuickKeysAttached); return d->enabled; }
730     void setEnabled(bool enabled) {
731         Q_D(QQuickKeysAttached);
732         if (enabled != d->enabled) {
733             d->enabled = enabled;
734             emit enabledChanged();
735         }
736     }
737
738     enum Priority { BeforeItem, AfterItem};
739     Priority priority() const;
740     void setPriority(Priority);
741
742     QDeclarativeListProperty<QQuickItem> forwardTo() {
743         Q_D(QQuickKeysAttached);
744         return QDeclarativeListProperty<QQuickItem>(this, d->targets);
745     }
746
747     virtual void componentComplete();
748
749     static QQuickKeysAttached *qmlAttachedProperties(QObject *);
750
751 Q_SIGNALS:
752     void enabledChanged();
753     void priorityChanged();
754     void pressed(QQuickKeyEvent *event);
755     void released(QQuickKeyEvent *event);
756     void digit0Pressed(QQuickKeyEvent *event);
757     void digit1Pressed(QQuickKeyEvent *event);
758     void digit2Pressed(QQuickKeyEvent *event);
759     void digit3Pressed(QQuickKeyEvent *event);
760     void digit4Pressed(QQuickKeyEvent *event);
761     void digit5Pressed(QQuickKeyEvent *event);
762     void digit6Pressed(QQuickKeyEvent *event);
763     void digit7Pressed(QQuickKeyEvent *event);
764     void digit8Pressed(QQuickKeyEvent *event);
765     void digit9Pressed(QQuickKeyEvent *event);
766
767     void leftPressed(QQuickKeyEvent *event);
768     void rightPressed(QQuickKeyEvent *event);
769     void upPressed(QQuickKeyEvent *event);
770     void downPressed(QQuickKeyEvent *event);
771     void tabPressed(QQuickKeyEvent *event);
772     void backtabPressed(QQuickKeyEvent *event);
773
774     void asteriskPressed(QQuickKeyEvent *event);
775     void numberSignPressed(QQuickKeyEvent *event);
776     void escapePressed(QQuickKeyEvent *event);
777     void returnPressed(QQuickKeyEvent *event);
778     void enterPressed(QQuickKeyEvent *event);
779     void deletePressed(QQuickKeyEvent *event);
780     void spacePressed(QQuickKeyEvent *event);
781     void backPressed(QQuickKeyEvent *event);
782     void cancelPressed(QQuickKeyEvent *event);
783     void selectPressed(QQuickKeyEvent *event);
784     void yesPressed(QQuickKeyEvent *event);
785     void noPressed(QQuickKeyEvent *event);
786     void context1Pressed(QQuickKeyEvent *event);
787     void context2Pressed(QQuickKeyEvent *event);
788     void context3Pressed(QQuickKeyEvent *event);
789     void context4Pressed(QQuickKeyEvent *event);
790     void callPressed(QQuickKeyEvent *event);
791     void hangupPressed(QQuickKeyEvent *event);
792     void flipPressed(QQuickKeyEvent *event);
793     void menuPressed(QQuickKeyEvent *event);
794     void volumeUpPressed(QQuickKeyEvent *event);
795     void volumeDownPressed(QQuickKeyEvent *event);
796
797 private:
798     virtual void keyPressed(QKeyEvent *event, bool post);
799     virtual void keyReleased(QKeyEvent *event, bool post);
800     virtual void inputMethodEvent(QInputMethodEvent *, bool post);
801     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
802
803     const QByteArray keyToSignal(int key) {
804         QByteArray keySignal;
805         if (key >= Qt::Key_0 && key <= Qt::Key_9) {
806             keySignal = "digit0Pressed";
807             keySignal[5] = '0' + (key - Qt::Key_0);
808         } else {
809             int i = 0;
810             while (sigMap[i].key && sigMap[i].key != key)
811                 ++i;
812             keySignal = sigMap[i].sig;
813         }
814         return keySignal;
815     }
816
817     struct SigMap {
818         int key;
819         const char *sig;
820     };
821
822     static const SigMap sigMap[];
823 };
824
825 QSGTransformNode *QQuickItemPrivate::itemNode()
826 {
827     if (!itemNodeInstance) {
828         itemNodeInstance = createTransformNode();
829         itemNodeInstance->setFlag(QSGNode::OwnedByParent, false);
830 #ifdef QML_RUNTIME_TESTING
831         Q_Q(QQuickItem);
832         itemNodeInstance->description = QString::fromLatin1("QQuickItem(%1)").arg(QString::fromLatin1(q->metaObject()->className()));
833 #endif
834     }
835     return itemNodeInstance;
836 }
837
838 QSGNode *QQuickItemPrivate::childContainerNode()
839 {
840     if (!groupNode) {
841         groupNode = new QSGNode();
842         if (rootNode)
843             rootNode->appendChildNode(groupNode);
844         else if (clipNode)
845             clipNode->appendChildNode(groupNode);
846         else if (opacityNode)
847             opacityNode->appendChildNode(groupNode);
848         else
849             itemNode()->appendChildNode(groupNode);
850         groupNode->setFlag(QSGNode::ChildrenDoNotOverlap, childrenDoNotOverlap);
851         groupNode->setFlag(QSGNode::StaticSubtreeGeometry, staticSubtreeGeometry);
852 #ifdef QML_RUNTIME_TESTING
853         groupNode->description = QLatin1String("group");
854 #endif
855     }
856     return groupNode;
857 }
858
859 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ChangeTypes);
860
861 QT_END_NAMESPACE
862
863 QML_DECLARE_TYPE(QQuickItemLayer)
864 QML_DECLARE_TYPE(QQuickKeysAttached)
865 QML_DECLARE_TYPEINFO(QQuickKeysAttached, QML_HAS_ATTACHED_PROPERTIES)
866 QML_DECLARE_TYPE(QQuickKeyNavigationAttached)
867 QML_DECLARE_TYPEINFO(QQuickKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES)
868 QML_DECLARE_TYPE(QQuickLayoutMirroringAttached)
869 QML_DECLARE_TYPEINFO(QQuickLayoutMirroringAttached, QML_HAS_ATTACHED_PROPERTIES)
870
871 #endif // QQUICKITEM_P_H