Let Item.layer.samplerName be a QByteArray instead of QString.
[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
250     QDeclarativeListProperty<QDeclarativeState> states();
251     QDeclarativeListProperty<QDeclarativeTransition> transitions();
252
253     QString state() const;
254     void setState(const QString &);
255
256     QQuickAnchorLine left() const;
257     QQuickAnchorLine right() const;
258     QQuickAnchorLine horizontalCenter() const;
259     QQuickAnchorLine top() const;
260     QQuickAnchorLine bottom() const;
261     QQuickAnchorLine verticalCenter() const;
262     QQuickAnchorLine baseline() const;
263
264     QQuickItemLayer *layer() const;
265
266     // data property
267     static void data_append(QDeclarativeListProperty<QObject> *, QObject *);
268     static int data_count(QDeclarativeListProperty<QObject> *);
269     static QObject *data_at(QDeclarativeListProperty<QObject> *, int);
270     static void data_clear(QDeclarativeListProperty<QObject> *);
271
272     // resources property
273     static QObject *resources_at(QDeclarativeListProperty<QObject> *, int);
274     static void resources_append(QDeclarativeListProperty<QObject> *, QObject *);
275     static int resources_count(QDeclarativeListProperty<QObject> *);
276     static void resources_clear(QDeclarativeListProperty<QObject> *);
277
278     // children property
279     static void children_append(QDeclarativeListProperty<QQuickItem> *, QQuickItem *);
280     static int children_count(QDeclarativeListProperty<QQuickItem> *);
281     static QQuickItem *children_at(QDeclarativeListProperty<QQuickItem> *, int);
282     static void children_clear(QDeclarativeListProperty<QQuickItem> *);
283
284     // transform property
285     static int transform_count(QDeclarativeListProperty<QQuickTransform> *list);
286     static void transform_append(QDeclarativeListProperty<QQuickTransform> *list, QQuickTransform *);
287     static QQuickTransform *transform_at(QDeclarativeListProperty<QQuickTransform> *list, int);
288     static void transform_clear(QDeclarativeListProperty<QQuickTransform> *list);
289
290     QQuickAnchors *anchors() const;
291     mutable QQuickAnchors *_anchors;
292     QQuickContents *_contents;
293
294     QDeclarativeNullableValue<qreal> baselineOffset;
295
296     struct AnchorLines {
297         AnchorLines(QQuickItem *);
298         QQuickAnchorLine left;
299         QQuickAnchorLine right;
300         QQuickAnchorLine hCenter;
301         QQuickAnchorLine top;
302         QQuickAnchorLine bottom;
303         QQuickAnchorLine vCenter;
304         QQuickAnchorLine baseline;
305     };
306     mutable AnchorLines *_anchorLines;
307     AnchorLines *anchorLines() const;
308
309     enum ChangeType {
310         Geometry = 0x01,
311         SiblingOrder = 0x02,
312         Visibility = 0x04,
313         Opacity = 0x08,
314         Destroyed = 0x10,
315         Parent = 0x20,
316         Children = 0x40,
317         Rotation = 0x80,
318     };
319
320     Q_DECLARE_FLAGS(ChangeTypes, ChangeType)
321
322     enum GeometryChangeType {
323         NoChange = 0,
324         XChange = 0x01,
325         YChange = 0x02,
326         WidthChange = 0x04,
327         HeightChange = 0x08,
328         SizeChange = WidthChange | HeightChange,
329         GeometryChange = XChange | YChange | SizeChange
330     };
331
332     Q_DECLARE_FLAGS(GeometryChangeTypes, GeometryChangeType)
333
334     struct ChangeListener {
335         ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::ChangeTypes t) : listener(l), types(t), gTypes(GeometryChange) {}
336         ChangeListener(QQuickItemChangeListener *l, QQuickItemPrivate::GeometryChangeTypes gt) : listener(l), types(Geometry), gTypes(gt) {}
337         QQuickItemChangeListener *listener;
338         QQuickItemPrivate::ChangeTypes types;
339         QQuickItemPrivate::GeometryChangeTypes gTypes;  //NOTE: not used for ==
340         bool operator==(const ChangeListener &other) const { return listener == other.listener && types == other.types; }
341     };
342
343     void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types) {
344         changeListeners.append(ChangeListener(listener, types));
345     }
346     void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types);
347     void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types);
348     void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, GeometryChangeTypes types);
349     QPODVector<ChangeListener,4> changeListeners;
350
351     QDeclarativeStateGroup *_states();
352     QDeclarativeStateGroup *_stateGroup;
353
354     QQuickItem::TransformOrigin origin:5;
355     quint32 flags:5;
356     bool widthValid:1;
357     bool heightValid:1;
358     bool componentComplete:1;
359     bool keepMouse:1;
360     bool keepTouch:1;
361     bool hoverEnabled:1;
362     bool smooth:1;
363     bool focus:1;
364     bool activeFocus:1;
365     bool notifiedFocus:1;
366     bool notifiedActiveFocus:1;
367     bool filtersChildMouseEvents:1;
368     bool explicitVisible:1;
369     bool effectiveVisible:1;
370     bool explicitEnable:1;
371     bool effectiveEnable:1;
372     bool polishScheduled:1;
373     bool inheritedLayoutMirror:1;
374     bool effectiveLayoutMirror:1;
375     bool isMirrorImplicit:1;
376     bool inheritMirrorFromParent:1;
377     bool inheritMirrorFromItem:1;
378     bool childrenDoNotOverlap:1;
379     bool staticSubtreeGeometry:1;
380     bool isAccessible:1;
381
382     QQuickCanvas *canvas;
383     QSGContext *sceneGraphContext() const { Q_ASSERT(canvas); return static_cast<QQuickCanvasPrivate *>(QObjectPrivate::get(canvas))->context; }
384
385     QQuickItem *parentItem;
386     QDeclarativeNotifier parentNotifier;
387
388     QList<QQuickItem *> childItems;
389     mutable QList<QQuickItem *> *sortedChildItems;
390     QList<QQuickItem *> paintOrderChildItems() const;
391     void addChild(QQuickItem *);
392     void removeChild(QQuickItem *);
393     void siblingOrderChanged();
394
395     inline void markSortedChildrenDirty(QQuickItem *child) {
396         // If sortedChildItems == &childItems then all in childItems have z == 0
397         // and we don't need to invalidate if the changed item also has z == 0.
398         if (child->z() != 0. || sortedChildItems != &childItems) {
399             if (sortedChildItems != &childItems)
400                 delete sortedChildItems;
401             sortedChildItems = 0;
402         }
403     }
404
405     class InitializationState {
406     public:
407         QQuickItem *getFocusScope(QQuickItem *item);
408         void clear();
409         void clear(QQuickItem *focusScope);
410     private:
411         QQuickItem *focusScope;
412     };
413     void initCanvas(InitializationState *, QQuickCanvas *);
414
415     QQuickItem *subFocusItem;
416
417     QTransform canvasToItemTransform() const;
418     QTransform itemToCanvasTransform() const;
419     void itemToParentTransform(QTransform &) const;
420
421     qreal x;
422     qreal y;
423     qreal width;
424     qreal height;
425     qreal implicitWidth;
426     qreal implicitHeight;
427
428     qreal z;
429     qreal scale;
430     qreal rotation;
431     qreal opacity;
432
433     QQuickLayoutMirroringAttached* attachedLayoutDirection;
434
435     Qt::MouseButtons acceptedMouseButtons;
436     Qt::InputMethodHints imHints;
437
438     void setAccessibleFlagAndListener();
439
440     QPointF transformOriginPoint;
441
442     virtual qreal getImplicitWidth() const;
443     virtual qreal getImplicitHeight() const;
444     virtual void implicitWidthChanged();
445     virtual void implicitHeightChanged();
446
447     void resolveLayoutMirror();
448     void setImplicitLayoutMirror(bool mirror, bool inherit);
449     void setLayoutMirror(bool mirror);
450     bool isMirrored() const {
451         return effectiveLayoutMirror;
452     }
453
454     void emitChildrenRectChanged(const QRectF &rect) {
455         Q_Q(QQuickItem);
456         emit q->childrenRectChanged(rect);
457     }
458
459     QPointF computeTransformOrigin() const;
460     QList<QQuickTransform *> transforms;
461     virtual void transformChanged();
462
463     QQuickItemKeyFilter *keyHandler;
464     void deliverKeyEvent(QKeyEvent *);
465     void deliverInputMethodEvent(QInputMethodEvent *);
466     void deliverFocusEvent(QFocusEvent *);
467     void deliverMouseEvent(QMouseEvent *);
468     void deliverWheelEvent(QWheelEvent *);
469     void deliverTouchEvent(QTouchEvent *);
470     void deliverHoverEvent(QHoverEvent *);
471     void deliverDragEvent(QEvent *);
472
473     bool calcEffectiveVisible() const;
474     void setEffectiveVisibleRecur(bool);
475     bool calcEffectiveEnable() const;
476     void setEffectiveEnableRecur(QQuickItem *scope, bool);
477
478     // XXX todo
479     enum DirtyType {
480         TransformOrigin         = 0x00000001,
481         Transform               = 0x00000002,
482         BasicTransform          = 0x00000004,
483         Position                = 0x00000008,
484         Size                    = 0x00000010,
485
486         ZValue                  = 0x00000020,
487         Content                 = 0x00000040,
488         Smooth                  = 0x00000080,
489         OpacityValue            = 0x00000100,
490         ChildrenChanged         = 0x00000200,
491         ChildrenStackingChanged = 0x00000400,
492         ParentChanged           = 0x00000800,
493
494         Clip                    = 0x00001000,
495         Canvas                  = 0x00002000,
496
497         EffectReference         = 0x00008000,
498         Visible                 = 0x00010000,
499         HideReference           = 0x00020000,
500         PerformanceHints        = 0x00040000,
501         // When you add an attribute here, don't forget to update
502         // dirtyToString()
503
504         TransformUpdateMask     = TransformOrigin | Transform | BasicTransform | Position | Size | Canvas,
505         ComplexTransformUpdateMask     = Transform | Canvas,
506         ContentUpdateMask       = Size | Content | Smooth | Canvas,
507         ChildrenUpdateMask      = ChildrenChanged | ChildrenStackingChanged | EffectReference | Canvas
508
509     };
510     quint32 dirtyAttributes;
511     QString dirtyToString() const;
512     void dirty(DirtyType);
513     void addToDirtyList();
514     void removeFromDirtyList();
515     QQuickItem *nextDirtyItem;
516     QQuickItem**prevDirtyItem;
517
518     inline QSGTransformNode *itemNode();
519     inline QSGNode *childContainerNode();
520
521     /*
522       QSGNode order is:
523          - itemNode
524          - (opacityNode)
525          - (clipNode)
526          - (effectNode)
527          - groupNode
528      */
529
530     QSGTransformNode *itemNodeInstance;
531     QSGOpacityNode *opacityNode;
532     QQuickDefaultClipNode *clipNode;
533     QSGRootNode *rootNode;
534     QSGNode *groupNode;
535     QSGNode *paintNode;
536     QSGNode *beforePaintNode;
537
538     virtual QSGTransformNode *createTransformNode();
539
540     // A reference from an effect item means that this item is used by the effect, so
541     // it should insert a root node.
542     void refFromEffectItem(bool hide);
543     void derefFromEffectItem(bool unhide);
544     int effectRefCount;
545     int hideRefCount;
546
547     void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &);
548
549     virtual void mirrorChange() {}
550
551     QQuickScreenAttached *screenAttached;
552
553     mutable QQuickItemLayer *_layer;
554
555     static qint64 consistentTime;
556     static void setConsistentTime(qint64 t);
557     static void start(QElapsedTimer &);
558     static qint64 elapsed(QElapsedTimer &);
559     static qint64 restart(QElapsedTimer &);
560 };
561
562 /*
563     Key filters can be installed on a QQuickItem, but not removed.  Currently they
564     are only used by attached objects (which are only destroyed on Item
565     destruction), so this isn't a problem.  If in future this becomes any form
566     of public API, they will have to support removal too.
567 */
568 class QQuickItemKeyFilter
569 {
570 public:
571     QQuickItemKeyFilter(QQuickItem * = 0);
572     virtual ~QQuickItemKeyFilter();
573
574     virtual void keyPressed(QKeyEvent *event, bool post);
575     virtual void keyReleased(QKeyEvent *event, bool post);
576     virtual void inputMethodEvent(QInputMethodEvent *event, bool post);
577     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
578     virtual void componentComplete();
579
580     bool m_processPost;
581
582 private:
583     QQuickItemKeyFilter *m_next;
584 };
585
586 class QQuickKeyNavigationAttachedPrivate : public QObjectPrivate
587 {
588 public:
589     QQuickKeyNavigationAttachedPrivate()
590         : QObjectPrivate(),
591           left(0), right(0), up(0), down(0), tab(0), backtab(0),
592           leftSet(false), rightSet(false), upSet(false), downSet(false),
593           tabSet(false), backtabSet(false) {}
594
595     QQuickItem *left;
596     QQuickItem *right;
597     QQuickItem *up;
598     QQuickItem *down;
599     QQuickItem *tab;
600     QQuickItem *backtab;
601     bool leftSet : 1;
602     bool rightSet : 1;
603     bool upSet : 1;
604     bool downSet : 1;
605     bool tabSet : 1;
606     bool backtabSet : 1;
607 };
608
609 class QQuickKeyNavigationAttached : public QObject, public QQuickItemKeyFilter
610 {
611     Q_OBJECT
612     Q_DECLARE_PRIVATE(QQuickKeyNavigationAttached)
613
614     Q_PROPERTY(QQuickItem *left READ left WRITE setLeft NOTIFY leftChanged)
615     Q_PROPERTY(QQuickItem *right READ right WRITE setRight NOTIFY rightChanged)
616     Q_PROPERTY(QQuickItem *up READ up WRITE setUp NOTIFY upChanged)
617     Q_PROPERTY(QQuickItem *down READ down WRITE setDown NOTIFY downChanged)
618     Q_PROPERTY(QQuickItem *tab READ tab WRITE setTab NOTIFY tabChanged)
619     Q_PROPERTY(QQuickItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged)
620     Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
621
622     Q_ENUMS(Priority)
623
624 public:
625     QQuickKeyNavigationAttached(QObject * = 0);
626
627     QQuickItem *left() const;
628     void setLeft(QQuickItem *);
629     QQuickItem *right() const;
630     void setRight(QQuickItem *);
631     QQuickItem *up() const;
632     void setUp(QQuickItem *);
633     QQuickItem *down() const;
634     void setDown(QQuickItem *);
635     QQuickItem *tab() const;
636     void setTab(QQuickItem *);
637     QQuickItem *backtab() const;
638     void setBacktab(QQuickItem *);
639
640     enum Priority { BeforeItem, AfterItem };
641     Priority priority() const;
642     void setPriority(Priority);
643
644     static QQuickKeyNavigationAttached *qmlAttachedProperties(QObject *);
645
646 Q_SIGNALS:
647     void leftChanged();
648     void rightChanged();
649     void upChanged();
650     void downChanged();
651     void tabChanged();
652     void backtabChanged();
653     void priorityChanged();
654
655 private:
656     virtual void keyPressed(QKeyEvent *event, bool post);
657     virtual void keyReleased(QKeyEvent *event, bool post);
658     void setFocusNavigation(QQuickItem *currentItem, const char *dir);
659 };
660
661 class QQuickLayoutMirroringAttached : public QObject
662 {
663     Q_OBJECT
664     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged)
665     Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged)
666
667 public:
668     explicit QQuickLayoutMirroringAttached(QObject *parent = 0);
669
670     bool enabled() const;
671     void setEnabled(bool);
672     void resetEnabled();
673
674     bool childrenInherit() const;
675     void setChildrenInherit(bool);
676
677     static QQuickLayoutMirroringAttached *qmlAttachedProperties(QObject *);
678 Q_SIGNALS:
679     void enabledChanged();
680     void childrenInheritChanged();
681 private:
682     friend class QQuickItemPrivate;
683     QQuickItemPrivate *itemPrivate;
684 };
685
686 class QQuickKeysAttachedPrivate : public QObjectPrivate
687 {
688 public:
689     QQuickKeysAttachedPrivate()
690         : QObjectPrivate(), inPress(false), inRelease(false)
691         , inIM(false), enabled(true), imeItem(0), item(0)
692     {}
693
694     bool isConnected(const char *signalName);
695
696     //loop detection
697     bool inPress:1;
698     bool inRelease:1;
699     bool inIM:1;
700
701     bool enabled : 1;
702
703     QQuickItem *imeItem;
704     QList<QQuickItem *> targets;
705     QQuickItem *item;
706 };
707
708 class QQuickKeysAttached : public QObject, public QQuickItemKeyFilter
709 {
710     Q_OBJECT
711     Q_DECLARE_PRIVATE(QQuickKeysAttached)
712
713     Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
714     Q_PROPERTY(QDeclarativeListProperty<QQuickItem> forwardTo READ forwardTo)
715     Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)
716
717     Q_ENUMS(Priority)
718
719 public:
720     QQuickKeysAttached(QObject *parent=0);
721     ~QQuickKeysAttached();
722
723     bool enabled() const { Q_D(const QQuickKeysAttached); return d->enabled; }
724     void setEnabled(bool enabled) {
725         Q_D(QQuickKeysAttached);
726         if (enabled != d->enabled) {
727             d->enabled = enabled;
728             emit enabledChanged();
729         }
730     }
731
732     enum Priority { BeforeItem, AfterItem};
733     Priority priority() const;
734     void setPriority(Priority);
735
736     QDeclarativeListProperty<QQuickItem> forwardTo() {
737         Q_D(QQuickKeysAttached);
738         return QDeclarativeListProperty<QQuickItem>(this, d->targets);
739     }
740
741     virtual void componentComplete();
742
743     static QQuickKeysAttached *qmlAttachedProperties(QObject *);
744
745 Q_SIGNALS:
746     void enabledChanged();
747     void priorityChanged();
748     void pressed(QQuickKeyEvent *event);
749     void released(QQuickKeyEvent *event);
750     void digit0Pressed(QQuickKeyEvent *event);
751     void digit1Pressed(QQuickKeyEvent *event);
752     void digit2Pressed(QQuickKeyEvent *event);
753     void digit3Pressed(QQuickKeyEvent *event);
754     void digit4Pressed(QQuickKeyEvent *event);
755     void digit5Pressed(QQuickKeyEvent *event);
756     void digit6Pressed(QQuickKeyEvent *event);
757     void digit7Pressed(QQuickKeyEvent *event);
758     void digit8Pressed(QQuickKeyEvent *event);
759     void digit9Pressed(QQuickKeyEvent *event);
760
761     void leftPressed(QQuickKeyEvent *event);
762     void rightPressed(QQuickKeyEvent *event);
763     void upPressed(QQuickKeyEvent *event);
764     void downPressed(QQuickKeyEvent *event);
765     void tabPressed(QQuickKeyEvent *event);
766     void backtabPressed(QQuickKeyEvent *event);
767
768     void asteriskPressed(QQuickKeyEvent *event);
769     void numberSignPressed(QQuickKeyEvent *event);
770     void escapePressed(QQuickKeyEvent *event);
771     void returnPressed(QQuickKeyEvent *event);
772     void enterPressed(QQuickKeyEvent *event);
773     void deletePressed(QQuickKeyEvent *event);
774     void spacePressed(QQuickKeyEvent *event);
775     void backPressed(QQuickKeyEvent *event);
776     void cancelPressed(QQuickKeyEvent *event);
777     void selectPressed(QQuickKeyEvent *event);
778     void yesPressed(QQuickKeyEvent *event);
779     void noPressed(QQuickKeyEvent *event);
780     void context1Pressed(QQuickKeyEvent *event);
781     void context2Pressed(QQuickKeyEvent *event);
782     void context3Pressed(QQuickKeyEvent *event);
783     void context4Pressed(QQuickKeyEvent *event);
784     void callPressed(QQuickKeyEvent *event);
785     void hangupPressed(QQuickKeyEvent *event);
786     void flipPressed(QQuickKeyEvent *event);
787     void menuPressed(QQuickKeyEvent *event);
788     void volumeUpPressed(QQuickKeyEvent *event);
789     void volumeDownPressed(QQuickKeyEvent *event);
790
791 private:
792     virtual void keyPressed(QKeyEvent *event, bool post);
793     virtual void keyReleased(QKeyEvent *event, bool post);
794     virtual void inputMethodEvent(QInputMethodEvent *, bool post);
795     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
796
797     const QByteArray keyToSignal(int key) {
798         QByteArray keySignal;
799         if (key >= Qt::Key_0 && key <= Qt::Key_9) {
800             keySignal = "digit0Pressed";
801             keySignal[5] = '0' + (key - Qt::Key_0);
802         } else {
803             int i = 0;
804             while (sigMap[i].key && sigMap[i].key != key)
805                 ++i;
806             keySignal = sigMap[i].sig;
807         }
808         return keySignal;
809     }
810
811     struct SigMap {
812         int key;
813         const char *sig;
814     };
815
816     static const SigMap sigMap[];
817 };
818
819 QSGTransformNode *QQuickItemPrivate::itemNode()
820 {
821     if (!itemNodeInstance) {
822         itemNodeInstance = createTransformNode();
823         itemNodeInstance->setFlag(QSGNode::OwnedByParent, false);
824 #ifdef QML_RUNTIME_TESTING
825         Q_Q(QQuickItem);
826         itemNodeInstance->description = QString::fromLatin1("QQuickItem(%1)").arg(QString::fromLatin1(q->metaObject()->className()));
827 #endif
828     }
829     return itemNodeInstance;
830 }
831
832 QSGNode *QQuickItemPrivate::childContainerNode()
833 {
834     if (!groupNode) {
835         groupNode = new QSGNode();
836         if (rootNode)
837             rootNode->appendChildNode(groupNode);
838         else if (clipNode)
839             clipNode->appendChildNode(groupNode);
840         else if (opacityNode)
841             opacityNode->appendChildNode(groupNode);
842         else
843             itemNode()->appendChildNode(groupNode);
844         groupNode->setFlag(QSGNode::ChildrenDoNotOverlap, childrenDoNotOverlap);
845         groupNode->setFlag(QSGNode::StaticSubtreeGeometry, staticSubtreeGeometry);
846 #ifdef QML_RUNTIME_TESTING
847         groupNode->description = QLatin1String("group");
848 #endif
849     }
850     return groupNode;
851 }
852
853 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ChangeTypes);
854
855 QT_END_NAMESPACE
856
857 QML_DECLARE_TYPE(QQuickItemLayer)
858 QML_DECLARE_TYPE(QQuickKeysAttached)
859 QML_DECLARE_TYPEINFO(QQuickKeysAttached, QML_HAS_ATTACHED_PROPERTIES)
860 QML_DECLARE_TYPE(QQuickKeyNavigationAttached)
861 QML_DECLARE_TYPEINFO(QQuickKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES)
862 QML_DECLARE_TYPE(QQuickLayoutMirroringAttached)
863 QML_DECLARE_TYPEINFO(QQuickLayoutMirroringAttached, QML_HAS_ATTACHED_PROPERTIES)
864
865 #endif // QQUICKITEM_P_H