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