QQuickCanvas renames
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitem_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKITEM_P_H
43 #define QQUICKITEM_P_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qquickitem.h"
57
58 #include "qquickanchors_p.h"
59 #include "qquickanchors_p_p.h"
60 #include "qquickitemchangelistener_p.h"
61
62 #include "qquickwindow_p.h"
63
64 #include <QtQuick/qsgnode.h>
65 #include "qquickclipnode_p.h"
66
67 #include <private/qpodvector_p.h>
68 #include <QtQuick/private/qquickstate_p.h>
69 #include <private/qqmlnullablevalue_p_p.h>
70 #include <private/qqmlnotifier_p.h>
71 #include <private/qqmlglobal_p.h>
72 #include <private/qlazilyallocated_p.h>
73
74 #include <qqml.h>
75 #include <qqmlcontext.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(QQmlComponent *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     QQmlComponent *effect() const { return m_effectComponent; }
185     void setEffect(QQmlComponent *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(QQmlComponent *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     QQmlComponent *m_effectComponent;
228     QQuickItem *m_effect;
229     QQuickShaderEffectSource *m_effectSource;
230 };
231
232 class Q_QUICK_PRIVATE_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     QQmlListProperty<QObject> data();
247     QQmlListProperty<QObject> resources();
248     QQmlListProperty<QQuickItem> children();
249     QQmlListProperty<QQuickItem> visibleChildren();
250
251     QQmlListProperty<QQuickState> states();
252     QQmlListProperty<QQuickTransition> 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(QQmlListProperty<QObject> *, QObject *);
269     static int data_count(QQmlListProperty<QObject> *);
270     static QObject *data_at(QQmlListProperty<QObject> *, int);
271     static void data_clear(QQmlListProperty<QObject> *);
272
273     // resources property
274     static QObject *resources_at(QQmlListProperty<QObject> *, int);
275     static void resources_append(QQmlListProperty<QObject> *, QObject *);
276     static int resources_count(QQmlListProperty<QObject> *);
277     static void resources_clear(QQmlListProperty<QObject> *);
278
279     // children property
280     static void children_append(QQmlListProperty<QQuickItem> *, QQuickItem *);
281     static int children_count(QQmlListProperty<QQuickItem> *);
282     static QQuickItem *children_at(QQmlListProperty<QQuickItem> *, int);
283     static void children_clear(QQmlListProperty<QQuickItem> *);
284
285     // visibleChildren property
286     static void visibleChildren_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o);
287     static int visibleChildren_count(QQmlListProperty<QQuickItem> *prop);
288     static QQuickItem *visibleChildren_at(QQmlListProperty<QQuickItem> *prop, int index);
289
290     // transform property
291     static int transform_count(QQmlListProperty<QQuickTransform> *list);
292     static void transform_append(QQmlListProperty<QQuickTransform> *list, QQuickTransform *);
293     static QQuickTransform *transform_at(QQmlListProperty<QQuickTransform> *list, int);
294     static void transform_clear(QQmlListProperty<QQuickTransform> *list);
295
296     enum ChangeType {
297         Geometry = 0x01,
298         SiblingOrder = 0x02,
299         Visibility = 0x04,
300         Opacity = 0x08,
301         Destroyed = 0x10,
302         Parent = 0x20,
303         Children = 0x40,
304         Rotation = 0x80,
305         ImplicitWidth = 0x100,
306         ImplicitHeight = 0x200
307     };
308
309     Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
310
311     enum GeometryChangeType {
312         NoChange = 0,
313         XChange = 0x01,
314         YChange = 0x02,
315         WidthChange = 0x04,
316         HeightChange = 0x08,
317         SizeChange = WidthChange | HeightChange,
318         GeometryChange = XChange | YChange | SizeChange
319     };
320
321     Q_DECLARE_FLAGS(GeometryChangeTypes, GeometryChangeType)
322
323     struct ChangeListener {
324         ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::ChangeTypes t) : listener(l), types(t), gTypes(GeometryChange) {}
325         ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::GeometryChangeTypes gt) : listener(l), types(Geometry), gTypes(gt) {}
326         QQuickItemChangeListener *listener;
327         QQuickItemPrivate::ChangeTypes types;
328         QQuickItemPrivate::GeometryChangeTypes gTypes;  //NOTE: not used for ==
329         bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
330     };
331
332     struct ExtraData {
333         ExtraData();
334
335         qreal z;
336         qreal scale;
337         qreal rotation;
338         qreal opacity;
339
340         QQuickContents *contents;
341         QQuickScreenAttached *screenAttached;
342         QQuickLayoutMirroringAttached* layoutDirectionAttached;
343         QQuickItemKeyFilter *keyHandler;
344         mutable QQuickItemLayer *layer;
345         QPointF userTransformOriginPoint;
346
347         int effectRefCount;
348         int hideRefCount;
349
350         QSGOpacityNode *opacityNode;
351         QQuickDefaultClipNode *clipNode;
352         QSGRootNode *rootNode;
353         QSGNode *beforePaintNode;
354
355         // Although acceptedMouseButtons is inside ExtraData, we actually store
356         // the LeftButton flag in the extra.flag() bit.  This is because it is
357         // extremely common to set acceptedMouseButtons to LeftButton, but very
358         // rare to use any of the other buttons.
359         Qt::MouseButtons acceptedMouseButtons;
360
361         QQuickItem::TransformOrigin origin:5;
362     };
363     QLazilyAllocated<ExtraData> extra;
364
365     QQuickAnchors *anchors() const;
366     mutable QQuickAnchors *_anchors;
367
368     inline Qt::MouseButtons acceptedMouseButtons() const;
369
370     QPODVector<QQuickItemPrivate::ChangeListener,4> changeListeners;
371
372     void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types);
373     void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types);
374     void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types);
375     void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types);
376
377     QQuickStateGroup *_states();
378     QQuickStateGroup *_stateGroup;
379
380     inline QQuickItem::TransformOrigin origin() const;
381
382     // Bit 0
383     quint32 flags:5;
384     bool widthValid:1;
385     bool heightValid:1;
386     bool baselineOffsetValid:1;
387     bool componentComplete:1;
388     bool keepMouse:1;
389     bool keepTouch:1;
390     bool hoverEnabled:1;
391     bool smooth:1;
392     bool antialiasing:1;
393     bool focus:1;
394     bool activeFocus:1;
395     bool notifiedFocus:1;
396     // Bit 16
397     bool notifiedActiveFocus:1;
398     bool filtersChildMouseEvents:1;
399     bool explicitVisible:1;
400     bool effectiveVisible:1;
401     bool explicitEnable:1;
402     bool effectiveEnable:1;
403     bool polishScheduled:1;
404     bool inheritedLayoutMirror:1;
405     bool effectiveLayoutMirror:1;
406     bool isMirrorImplicit:1;
407     bool inheritMirrorFromParent:1;
408     bool inheritMirrorFromItem:1;
409     bool isAccessible:1;
410     bool culled:1;
411     // bool dummy:2
412     // Bit 32
413
414     enum DirtyType {
415         TransformOrigin         = 0x00000001,
416         Transform               = 0x00000002,
417         BasicTransform          = 0x00000004,
418         Position                = 0x00000008,
419         Size                    = 0x00000010,
420
421         ZValue                  = 0x00000020,
422         Content                 = 0x00000040,
423         Smooth                  = 0x00000080,
424         OpacityValue            = 0x00000100,
425         ChildrenChanged         = 0x00000200,
426         ChildrenStackingChanged = 0x00000400,
427         ParentChanged           = 0x00000800,
428
429         Clip                    = 0x00001000,
430         Window                  = 0x00002000,
431
432         EffectReference         = 0x00008000,
433         Visible                 = 0x00010000,
434         HideReference           = 0x00020000,
435         Antialiasing             = 0x00040000,
436         // When you add an attribute here, don't forget to update
437         // dirtyToString()
438
439         TransformUpdateMask     = TransformOrigin | Transform | BasicTransform | Position |
440                                   Size | Window,
441         ComplexTransformUpdateMask     = Transform | Window,
442         ContentUpdateMask       = Size | Content | Smooth | Window | Antialiasing,
443         ChildrenUpdateMask      = ChildrenChanged | ChildrenStackingChanged | EffectReference | Window
444     };
445
446     quint32 dirtyAttributes;
447     QString dirtyToString() const;
448     void dirty(DirtyType);
449     void addToDirtyList();
450     void removeFromDirtyList();
451     QQuickItem *nextDirtyItem;
452     QQuickItem**prevDirtyItem;
453
454     void setCulled(bool);
455
456     QQuickWindow *window;
457     int windowRefCount;
458     inline QSGContext *sceneGraphContext() const;
459
460     QQuickItem *parentItem;
461     QQmlNotifier parentNotifier;
462
463     QList<QQuickItem *> childItems;
464     mutable QList<QQuickItem *> *sortedChildItems;
465     QList<QQuickItem *> paintOrderChildItems() const;
466     void addChild(QQuickItem *);
467     void removeChild(QQuickItem *);
468     void siblingOrderChanged();
469
470     inline void markSortedChildrenDirty(QQuickItem *child);
471
472     void refWindow(QQuickWindow *);
473     void derefWindow();
474
475     QQuickItem *subFocusItem;
476     void updateSubFocusItem(QQuickItem *scope, bool focus);
477
478     QTransform windowToItemTransform() const;
479     QTransform itemToWindowTransform() const;
480     void itemToParentTransform(QTransform &) const;
481
482     qreal x;
483     qreal y;
484     qreal width;
485     qreal height;
486     qreal implicitWidth;
487     qreal implicitHeight;
488
489     qreal baselineOffset;
490
491     QList<QQuickTransform *> transforms;
492
493     inline qreal z() const { return extra.isAllocated()?extra->z:0; }
494     inline qreal scale() const { return extra.isAllocated()?extra->scale:1; }
495     inline qreal rotation() const { return extra.isAllocated()?extra->rotation:0; }
496     inline qreal opacity() const { return extra.isAllocated()?extra->opacity:1; }
497
498     void setAccessibleFlagAndListener();
499
500     virtual qreal getImplicitWidth() const;
501     virtual qreal getImplicitHeight() const;
502     virtual void implicitWidthChanged();
503     virtual void implicitHeightChanged();
504
505     void resolveLayoutMirror();
506     void setImplicitLayoutMirror(bool mirror, bool inherit);
507     void setLayoutMirror(bool mirror);
508     bool isMirrored() const {
509         return effectiveLayoutMirror;
510     }
511
512     void emitChildrenRectChanged(const QRectF &rect) {
513         Q_Q(QQuickItem);
514         emit q->childrenRectChanged(rect);
515     }
516
517     QPointF computeTransformOrigin() const;
518     virtual void transformChanged();
519
520     void deliverKeyEvent(QKeyEvent *);
521     void deliverInputMethodEvent(QInputMethodEvent *);
522     void deliverFocusEvent(QFocusEvent *);
523     void deliverMouseEvent(QMouseEvent *);
524     void deliverWheelEvent(QWheelEvent *);
525     void deliverTouchEvent(QTouchEvent *);
526     void deliverHoverEvent(QHoverEvent *);
527 #ifndef QT_NO_DRAGANDDROP
528     void deliverDragEvent(QEvent *);
529 #endif
530
531     bool calcEffectiveVisible() const;
532     bool setEffectiveVisibleRecur(bool);
533     bool calcEffectiveEnable() const;
534     void setEffectiveEnableRecur(QQuickItem *scope, bool);
535
536
537     inline QSGTransformNode *itemNode();
538     inline QSGNode *childContainerNode();
539
540     /*
541       QSGNode order is:
542          - itemNode
543          - (opacityNode)
544          - (clipNode)
545          - (effectNode)
546          - groupNode
547      */
548
549     QSGOpacityNode *opacityNode() const { return extra.isAllocated()?extra->opacityNode:0; }
550     QQuickDefaultClipNode *clipNode() const { return extra.isAllocated()?extra->clipNode:0; }
551     QSGRootNode *rootNode() const { return extra.isAllocated()?extra->rootNode:0; }
552
553     QSGTransformNode *itemNodeInstance;
554     QSGNode *groupNode;
555     QSGNode *paintNode;
556
557     virtual QSGTransformNode *createTransformNode();
558
559     // A reference from an effect item means that this item is used by the effect, so
560     // it should insert a root node.
561     void refFromEffectItem(bool hide);
562     void derefFromEffectItem(bool unhide);
563
564     void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &);
565
566     virtual void mirrorChange() {}
567
568     static qint64 consistentTime;
569     static void setConsistentTime(qint64 t);
570     static void start(QElapsedTimer &);
571     static qint64 elapsed(QElapsedTimer &);
572     static qint64 restart(QElapsedTimer &);
573 };
574
575 /*
576     Key filters can be installed on a QQuickItem, but not removed.  Currently they
577     are only used by attached objects (which are only destroyed on Item
578     destruction), so this isn't a problem.  If in future this becomes any form
579     of public API, they will have to support removal too.
580 */
581 class QQuickItemKeyFilter
582 {
583 public:
584     QQuickItemKeyFilter(QQuickItem * = 0);
585     virtual ~QQuickItemKeyFilter();
586
587     virtual void keyPressed(QKeyEvent *event, bool post);
588     virtual void keyReleased(QKeyEvent *event, bool post);
589     virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
590     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
591     virtual void componentComplete();
592
593     bool m_processPost;
594
595 private:
596     QQuickItemKeyFilter *m_next;
597 };
598
599 class QQuickKeyNavigationAttachedPrivate : public QObjectPrivate
600 {
601 public:
602     QQuickKeyNavigationAttachedPrivate()
603         : QObjectPrivate(),
604           left(0), right(0), up(0), down(0), tab(0), backtab(0),
605           leftSet(false), rightSet(false), upSet(false), downSet(false),
606           tabSet(false), backtabSet(false) {}
607
608     QQuickItem *left;
609     QQuickItem *right;
610     QQuickItem *up;
611     QQuickItem *down;
612     QQuickItem *tab;
613     QQuickItem *backtab;
614     bool leftSet : 1;
615     bool rightSet : 1;
616     bool upSet : 1;
617     bool downSet : 1;
618     bool tabSet : 1;
619     bool backtabSet : 1;
620 };
621
622 class QQuickKeyNavigationAttached : public QObject, public QQuickItemKeyFilter
623 {
624     Q_OBJECT
625     Q_DECLARE_PRIVATE(QQuickKeyNavigationAttached)
626
627     Q_PROPERTY(QQuickItem *left READ left WRITE setLeft NOTIFY leftChanged)
628     Q_PROPERTY(QQuickItem *right READ right WRITE setRight NOTIFY rightChanged)
629     Q_PROPERTY(QQuickItem *up READ up WRITE setUp NOTIFY upChanged)
630     Q_PROPERTY(QQuickItem *down READ down WRITE setDown NOTIFY downChanged)
631     Q_PROPERTY(QQuickItem *tab READ tab WRITE setTab NOTIFY tabChanged)
632     Q_PROPERTY(QQuickItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged)
633     Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
634
635     Q_ENUMS(Priority)
636
637 public:
638     QQuickKeyNavigationAttached(QObject * = 0);
639
640     QQuickItem *left() const;
641     void setLeft(QQuickItem *);
642     QQuickItem *right() const;
643     void setRight(QQuickItem *);
644     QQuickItem *up() const;
645     void setUp(QQuickItem *);
646     QQuickItem *down() const;
647     void setDown(QQuickItem *);
648     QQuickItem *tab() const;
649     void setTab(QQuickItem *);
650     QQuickItem *backtab() const;
651     void setBacktab(QQuickItem *);
652
653     enum Priority { BeforeItem, AfterItem };
654     Priority priority() const;
655     void setPriority(Priority);
656
657     static QQuickKeyNavigationAttached *qmlAttachedProperties(QObject *);
658
659 Q_SIGNALS:
660     void leftChanged();
661     void rightChanged();
662     void upChanged();
663     void downChanged();
664     void tabChanged();
665     void backtabChanged();
666     void priorityChanged();
667
668 private:
669     virtual void keyPressed(QKeyEvent *event, bool post);
670     virtual void keyReleased(QKeyEvent *event, bool post);
671     void setFocusNavigation(QQuickItem *currentItem, const char *dir);
672 };
673
674 class QQuickLayoutMirroringAttached : public QObject
675 {
676     Q_OBJECT
677     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged)
678     Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged)
679
680 public:
681     explicit QQuickLayoutMirroringAttached(QObject *parent = 0);
682
683     bool enabled() const;
684     void setEnabled(bool);
685     void resetEnabled();
686
687     bool childrenInherit() const;
688     void setChildrenInherit(bool);
689
690     static QQuickLayoutMirroringAttached *qmlAttachedProperties(QObject *);
691 Q_SIGNALS:
692     void enabledChanged();
693     void childrenInheritChanged();
694 private:
695     friend class QQuickItemPrivate;
696     QQuickItemPrivate *itemPrivate;
697 };
698
699 class QQuickKeysAttachedPrivate : public QObjectPrivate
700 {
701 public:
702     QQuickKeysAttachedPrivate()
703         : QObjectPrivate(), inPress(false), inRelease(false)
704         , inIM(false), enabled(true), imeItem(0), item(0)
705     {}
706
707     //loop detection
708     bool inPress:1;
709     bool inRelease:1;
710     bool inIM:1;
711
712     bool enabled : 1;
713
714     QQuickItem *imeItem;
715     QList<QQuickItem *> targets;
716     QQuickItem *item;
717 };
718
719 class QQuickKeysAttached : public QObject, public QQuickItemKeyFilter
720 {
721     Q_OBJECT
722     Q_DECLARE_PRIVATE(QQuickKeysAttached)
723
724     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
725     Q_PROPERTY(QQmlListProperty<QQuickItem> forwardTo READ forwardTo)
726     Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
727
728     Q_ENUMS(Priority)
729
730 public:
731     QQuickKeysAttached(QObject *parent=0);
732     ~QQuickKeysAttached();
733
734     bool enabled() const { Q_D(const QQuickKeysAttached); return d->enabled; }
735     void setEnabled(bool enabled) {
736         Q_D(QQuickKeysAttached);
737         if (enabled != d->enabled) {
738             d->enabled = enabled;
739             emit enabledChanged();
740         }
741     }
742
743     enum Priority { BeforeItem, AfterItem};
744     Priority priority() const;
745     void setPriority(Priority);
746
747     QQmlListProperty<QQuickItem> forwardTo() {
748         Q_D(QQuickKeysAttached);
749         return QQmlListProperty<QQuickItem>(this, d->targets);
750     }
751
752     virtual void componentComplete();
753
754     static QQuickKeysAttached *qmlAttachedProperties(QObject *);
755
756 Q_SIGNALS:
757     void enabledChanged();
758     void priorityChanged();
759     void pressed(QQuickKeyEvent *event);
760     void released(QQuickKeyEvent *event);
761     void digit0Pressed(QQuickKeyEvent *event);
762     void digit1Pressed(QQuickKeyEvent *event);
763     void digit2Pressed(QQuickKeyEvent *event);
764     void digit3Pressed(QQuickKeyEvent *event);
765     void digit4Pressed(QQuickKeyEvent *event);
766     void digit5Pressed(QQuickKeyEvent *event);
767     void digit6Pressed(QQuickKeyEvent *event);
768     void digit7Pressed(QQuickKeyEvent *event);
769     void digit8Pressed(QQuickKeyEvent *event);
770     void digit9Pressed(QQuickKeyEvent *event);
771
772     void leftPressed(QQuickKeyEvent *event);
773     void rightPressed(QQuickKeyEvent *event);
774     void upPressed(QQuickKeyEvent *event);
775     void downPressed(QQuickKeyEvent *event);
776     void tabPressed(QQuickKeyEvent *event);
777     void backtabPressed(QQuickKeyEvent *event);
778
779     void asteriskPressed(QQuickKeyEvent *event);
780     void numberSignPressed(QQuickKeyEvent *event);
781     void escapePressed(QQuickKeyEvent *event);
782     void returnPressed(QQuickKeyEvent *event);
783     void enterPressed(QQuickKeyEvent *event);
784     void deletePressed(QQuickKeyEvent *event);
785     void spacePressed(QQuickKeyEvent *event);
786     void backPressed(QQuickKeyEvent *event);
787     void cancelPressed(QQuickKeyEvent *event);
788     void selectPressed(QQuickKeyEvent *event);
789     void yesPressed(QQuickKeyEvent *event);
790     void noPressed(QQuickKeyEvent *event);
791     void context1Pressed(QQuickKeyEvent *event);
792     void context2Pressed(QQuickKeyEvent *event);
793     void context3Pressed(QQuickKeyEvent *event);
794     void context4Pressed(QQuickKeyEvent *event);
795     void callPressed(QQuickKeyEvent *event);
796     void hangupPressed(QQuickKeyEvent *event);
797     void flipPressed(QQuickKeyEvent *event);
798     void menuPressed(QQuickKeyEvent *event);
799     void volumeUpPressed(QQuickKeyEvent *event);
800     void volumeDownPressed(QQuickKeyEvent *event);
801
802 private:
803     virtual void keyPressed(QKeyEvent *event, bool post);
804     virtual void keyReleased(QKeyEvent *event, bool post);
805     virtual void inputMethodEvent(QInputMethodEvent *, bool post);
806     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
807
808     const QByteArray keyToSignal(int key) {
809         QByteArray keySignal;
810         if (key >= Qt::Key_0 && key <= Qt::Key_9) {
811             keySignal = "digit0Pressed";
812             keySignal[5] = '0' + (key - Qt::Key_0);
813         } else {
814             int i = 0;
815             while (sigMap[i].key && sigMap[i].key != key)
816                 ++i;
817             keySignal = sigMap[i].sig;
818         }
819         return keySignal;
820     }
821
822     bool isConnected(const char *signalName);
823
824     struct SigMap {
825         int key;
826         const char *sig;
827     };
828
829     static const SigMap sigMap[];
830 };
831
832 Qt::MouseButtons QQuickItemPrivate::acceptedMouseButtons() const
833 {
834     return ((extra.flag() ? Qt::LeftButton : Qt::MouseButton(0)) |
835             (extra.isAllocated() ? extra->acceptedMouseButtons : Qt::MouseButtons(0)));
836 }
837
838 QSGContext *QQuickItemPrivate::sceneGraphContext() const
839 {
840     Q_ASSERT(window);
841     return static_cast<QQuickWindowPrivate *>(QObjectPrivate::get(window))->context;
842 }
843
844 void QQuickItemPrivate::markSortedChildrenDirty(QQuickItem *child)
845 {
846     // If sortedChildItems == &childItems then all in childItems have z == 0
847     // and we don't need to invalidate if the changed item also has z == 0.
848     if (child->z() != 0. || sortedChildItems != &childItems) {
849         if (sortedChildItems != &childItems)
850             delete sortedChildItems;
851         sortedChildItems = 0;
852     }
853 }
854
855 QQuickItem::TransformOrigin QQuickItemPrivate::origin() const
856 {
857     return extra.isAllocated()?extra->origin:QQuickItem::Center;
858 }
859
860 QSGTransformNode *QQuickItemPrivate::itemNode()
861 {
862     if (!itemNodeInstance) {
863         itemNodeInstance = createTransformNode();
864         itemNodeInstance->setFlag(QSGNode::OwnedByParent, false);
865 #ifdef QML_RUNTIME_TESTING
866         Q_Q(QQuickItem);
867         itemNodeInstance->description = QString::fromLatin1("QQuickItem(%1)").arg(QString::fromLatin1(q->metaObject()->className()));
868 #endif
869     }
870     return itemNodeInstance;
871 }
872
873 QSGNode *QQuickItemPrivate::childContainerNode()
874 {
875     if (!groupNode) {
876         groupNode = new QSGNode();
877         if (rootNode())
878             rootNode()->appendChildNode(groupNode);
879         else if (clipNode())
880             clipNode()->appendChildNode(groupNode);
881         else if (opacityNode())
882             opacityNode()->appendChildNode(groupNode);
883         else
884             itemNode()->appendChildNode(groupNode);
885 #ifdef QML_RUNTIME_TESTING
886         groupNode->description = QLatin1String("group");
887 #endif
888     }
889     return groupNode;
890 }
891
892 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ChangeTypes);
893
894 QT_END_NAMESPACE
895
896 QML_DECLARE_TYPE(QQuickItemLayer)
897 QML_DECLARE_TYPE(QQuickKeysAttached)
898 QML_DECLARE_TYPEINFO(QQuickKeysAttached, QML_HAS_ATTACHED_PROPERTIES)
899 QML_DECLARE_TYPE(QQuickKeyNavigationAttached)
900 QML_DECLARE_TYPEINFO(QQuickKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES)
901 QML_DECLARE_TYPE(QQuickLayoutMirroringAttached)
902 QML_DECLARE_TYPEINFO(QQuickLayoutMirroringAttached, QML_HAS_ATTACHED_PROPERTIES)
903
904 #endif // QQUICKITEM_P_H