Add accessibility to qml
[profile/ivi/qtdeclarative.git] / src / quick / items / qquickitem.h
1 // Commit: 6f78a6080b84cc3ef96b73a4ff58d1b5a72f08f4
2 /****************************************************************************
3 **
4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
5 ** All rights reserved.
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this
15 ** file. Please review the following information to ensure the GNU Lesser
16 ** General Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 **
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 **
23 ** GNU General Public License Usage
24 ** Alternatively, this file may be used under the terms of the GNU General
25 ** Public License version 3.0 as published by the Free Software Foundation
26 ** and appearing in the file LICENSE.GPL included in the packaging of this
27 ** file. Please review the following information to ensure the GNU General
28 ** Public License version 3.0 requirements will be met:
29 ** http://www.gnu.org/copyleft/gpl.html.
30 **
31 ** Other Usage
32 ** Alternatively, this file may be used in accordance with the terms and
33 ** conditions contained in a signed written agreement between you and Nokia.
34 **
35 **
36 **
37 **
38 **
39 ** $QT_END_LICENSE$
40 **
41 ****************************************************************************/
42
43 #ifndef QQUICKITEM_H
44 #define QQUICKITEM_H
45
46 #include <QtQuick/qtquickglobal.h>
47 #include <QtDeclarative/qdeclarative.h>
48 #include <QtDeclarative/qdeclarativecomponent.h>
49
50 #include <QtCore/QObject>
51 #include <QtCore/QList>
52 #include <QtGui/qevent.h>
53 #include <QtGui/qfont.h>
54 #include <QtGui/qaccessible.h>
55
56 QT_BEGIN_HEADER
57
58 QT_BEGIN_NAMESPACE
59
60 class QQuickItem;
61 class QQuickTransformPrivate;
62 class QQuickTransform : public QObject
63 {
64     Q_OBJECT
65 public:
66     QQuickTransform(QObject *parent = 0);
67     ~QQuickTransform();
68
69     void appendToItem(QQuickItem *);
70     void prependToItem(QQuickItem *);
71
72     virtual void applyTo(QMatrix4x4 *matrix) const = 0;
73
74 protected Q_SLOTS:
75     void update();
76
77 protected:
78     QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
79
80 private:
81     Q_DECLARE_PRIVATE(QQuickTransform)
82 };
83
84 class QDeclarativeV8Function;
85 class QDeclarativeState;
86 class QQuickAnchorLine;
87 class QDeclarativeTransition;
88 class QQuickKeyEvent;
89 class QQuickAnchors;
90 class QQuickItemPrivate;
91 class QQuickCanvas;
92 class QSGEngine;
93 class QTouchEvent;
94 class QSGNode;
95 class QSGTransformNode;
96 class QSGTextureProvider;
97
98 class Q_QUICK_EXPORT QQuickItem : public QObject, public QDeclarativeParserStatus
99 {
100     Q_OBJECT
101     Q_INTERFACES(QDeclarativeParserStatus)
102
103     Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
104     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
105     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
106     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
107
108     Q_PROPERTY(QPointF pos READ pos FINAL)
109     Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
110     Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
111     Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
112     Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
113     Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
114
115     Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
116     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
117     Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
118
119     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false)
120     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false)
121     Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
122     Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
123     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
124     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
125     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
126     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
127     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
128     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
129     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
130     Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
131     Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
132
133     Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
134
135     Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
136     Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
137
138     Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
139     Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
140     Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
141     Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint)  // XXX todo - notify?
142     Q_PROPERTY(QDeclarativeListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
143
144     Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
145     Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
146     Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
147
148     Q_ENUMS(TransformOrigin)
149     Q_CLASSINFO("DefaultProperty", "data")
150     Q_CLASSINFO("qt_HasQmlAccessors", "true")
151
152 public:
153     enum Flag {
154         ItemClipsChildrenToShape  = 0x01,
155         ItemAcceptsInputMethod    = 0x02,
156         ItemIsFocusScope          = 0x04,
157         ItemHasContents           = 0x08,
158         ItemAcceptsDrops          = 0x10
159         // Remember to increment the size of QQuickItemPrivate::flags
160     };
161     Q_DECLARE_FLAGS(Flags, Flag)
162
163     enum ItemChange {
164         ItemChildAddedChange,      // value.item
165         ItemChildRemovedChange,    // value.item
166         ItemSceneChange,           // value.canvas
167         ItemVisibleHasChanged,     // value.realValue
168         ItemParentHasChanged,      // value.item
169         ItemOpacityHasChanged,     // value.realValue
170         ItemActiveFocusHasChanged, // value.boolValue
171         ItemRotationHasChanged     // value.realValue
172     };
173
174     union ItemChangeData {
175         ItemChangeData(QQuickItem *v) : item(v) {}
176         ItemChangeData(QQuickCanvas *v) : canvas(v) {}
177         ItemChangeData(qreal v) : realValue(v) {}
178         ItemChangeData(bool v) : boolValue(v) {}
179
180         QQuickItem *item;
181         QQuickCanvas *canvas;
182         qreal realValue;
183         bool boolValue;
184     };
185
186     enum TransformOrigin {
187         TopLeft, Top, TopRight,
188         Left, Center, Right,
189         BottomLeft, Bottom, BottomRight
190     };
191
192     QQuickItem(QQuickItem *parent = 0);
193     virtual ~QQuickItem();
194
195     QSGEngine *sceneGraphEngine() const;
196
197     QQuickCanvas *canvas() const;
198     QQuickItem *parentItem() const;
199     void setParentItem(QQuickItem *parent);
200     void stackBefore(const QQuickItem *);
201     void stackAfter(const QQuickItem *);
202
203     QRectF childrenRect();
204     QList<QQuickItem *> childItems() const;
205
206     bool clip() const;
207     void setClip(bool);
208
209     QString state() const;
210     void setState(const QString &);
211
212     qreal baselineOffset() const;
213     void setBaselineOffset(qreal);
214
215     QDeclarativeListProperty<QQuickTransform> transform();
216
217     qreal x() const;
218     qreal y() const;
219     QPointF pos() const;
220     void setX(qreal);
221     void setY(qreal);
222     void setPos(const QPointF &);
223
224     qreal width() const;
225     void setWidth(qreal);
226     void resetWidth();
227     qreal implicitWidth() const;
228
229     qreal height() const;
230     void setHeight(qreal);
231     void resetHeight();
232     qreal implicitHeight() const;
233
234     void setSize(const QSizeF &size);
235
236     TransformOrigin transformOrigin() const;
237     void setTransformOrigin(TransformOrigin);
238     QPointF transformOriginPoint() const;
239     void setTransformOriginPoint(const QPointF &);
240
241     qreal z() const;
242     void setZ(qreal);
243
244     qreal rotation() const;
245     void setRotation(qreal);
246     qreal scale() const;
247     void setScale(qreal);
248
249     qreal opacity() const;
250     void setOpacity(qreal);
251
252     bool isVisible() const;
253     void setVisible(bool);
254
255     bool isEnabled() const;
256     void setEnabled(bool);
257
258     bool smooth() const;
259     void setSmooth(bool);
260
261     Flags flags() const;
262     void setFlag(Flag flag, bool enabled = true);
263     void setFlags(Flags flags);
264
265     virtual QRectF boundingRect() const;
266
267     bool hasActiveFocus() const;
268     bool hasFocus() const;
269     void setFocus(bool);
270     bool isFocusScope() const;
271     QQuickItem *scopedFocusItem() const;
272
273     Qt::MouseButtons acceptedMouseButtons() const;
274     void setAcceptedMouseButtons(Qt::MouseButtons buttons);
275     bool acceptHoverEvents() const;
276     void setAcceptHoverEvents(bool enabled);
277
278     bool isUnderMouse() const;
279     void grabMouse();
280     void ungrabMouse();
281     bool keepMouseGrab() const;
282     void setKeepMouseGrab(bool);
283     bool filtersChildMouseEvents() const;
284     void setFiltersChildMouseEvents(bool filter);
285
286     void grabTouchPoints(const QList<int> &ids);
287     void ungrabTouchPoints();
288     bool keepTouchGrab() const;
289     void setKeepTouchGrab(bool);
290
291     QTransform itemTransform(QQuickItem *, bool *) const;
292     QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
293     QPointF mapToScene(const QPointF &point) const;
294     QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
295     QRectF mapRectToScene(const QRectF &rect) const;
296     QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
297     QPointF mapFromScene(const QPointF &point) const;
298     QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
299     QRectF mapRectFromScene(const QRectF &rect) const;
300
301     void polish();
302
303     Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
304     Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
305     Q_INVOKABLE void forceActiveFocus();
306     Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
307
308     Qt::InputMethodHints inputMethodHints() const;
309     void setInputMethodHints(Qt::InputMethodHints hints);
310     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
311
312     struct UpdatePaintNodeData {
313        QSGTransformNode *transformNode;
314     private:
315        friend class QQuickCanvasPrivate;
316        UpdatePaintNodeData();
317     };
318
319     virtual bool isTextureProvider() const { return false; }
320     virtual QSGTextureProvider *textureProvider() const { return 0; }
321
322 public Q_SLOTS:
323     void update();
324     void updateMicroFocus();
325
326 Q_SIGNALS:
327     void childrenRectChanged(const QRectF &);
328     void baselineOffsetChanged(qreal);
329     void stateChanged(const QString &);
330     void focusChanged(bool);
331     void activeFocusChanged(bool);
332     void parentChanged(QQuickItem *);
333     void transformOriginChanged(TransformOrigin);
334     void smoothChanged(bool);
335     void clipChanged(bool);
336
337     // XXX todo
338     void childrenChanged();
339     void opacityChanged();
340     void enabledChanged();
341     void visibleChanged();
342     void rotationChanged();
343     void scaleChanged();
344
345     void xChanged();
346     void yChanged();
347     void widthChanged();
348     void heightChanged();
349     void zChanged();
350     void implicitWidthChanged();
351     void implicitHeightChanged();
352
353 protected:
354     virtual bool event(QEvent *);
355
356     bool isComponentComplete() const;
357     virtual void itemChange(ItemChange, const ItemChangeData &);
358
359     void setImplicitWidth(qreal);
360     bool widthValid() const; // ### better name?
361     void setImplicitHeight(qreal);
362     bool heightValid() const; // ### better name?
363     void setImplicitSize(qreal, qreal);
364
365     virtual void classBegin();
366     virtual void componentComplete();
367
368     virtual void keyPressEvent(QKeyEvent *event);
369     virtual void keyReleaseEvent(QKeyEvent *event);
370     virtual void inputMethodEvent(QInputMethodEvent *);
371     virtual void focusInEvent(QFocusEvent *);
372     virtual void focusOutEvent(QFocusEvent *);
373     virtual void mousePressEvent(QMouseEvent *event);
374     virtual void mouseMoveEvent(QMouseEvent *event);
375     virtual void mouseReleaseEvent(QMouseEvent *event);
376     virtual void mouseDoubleClickEvent(QMouseEvent *event);
377     virtual void mouseUngrabEvent(); // XXX todo - params?
378     virtual void touchUngrabEvent();
379     virtual void wheelEvent(QWheelEvent *event);
380     virtual void touchEvent(QTouchEvent *event);
381     virtual void hoverEnterEvent(QHoverEvent *event);
382     virtual void hoverMoveEvent(QHoverEvent *event);
383     virtual void hoverLeaveEvent(QHoverEvent *event);
384     virtual void dragEnterEvent(QDragEnterEvent *);
385     virtual void dragMoveEvent(QDragMoveEvent *);
386     virtual void dragLeaveEvent(QDragLeaveEvent *);
387     virtual void dropEvent(QDropEvent *);
388     virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
389     virtual void windowDeactivateEvent();
390
391     virtual void geometryChanged(const QRectF &newGeometry,
392                                  const QRectF &oldGeometry);
393
394     virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
395     virtual void updatePolish();
396
397 protected Q_SLOTS:
398     void sendAccessibilityUpdate();
399
400 protected:
401     QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = 0);
402
403 private:
404     friend class QQuickCanvas;
405     friend class QQuickCanvasPrivate;
406     friend class QSGRenderer;
407     friend class QAccessibleQuickItem;
408     friend class QQuickAccessibleAttached;
409     Q_DISABLE_COPY(QQuickItem)
410     Q_DECLARE_PRIVATE(QQuickItem)
411 };
412
413 // XXX todo
414 Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
415
416 #ifndef QT_NO_DEBUG_STREAM
417 QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
418 #endif
419
420 QT_END_NAMESPACE
421
422 QML_DECLARE_TYPE(QQuickItem)
423 QML_DECLARE_TYPE(QQuickTransform)
424
425 QT_END_HEADER
426
427 #endif // QQUICKITEM_H