e94f675c55b2750275493a34dee4ba4551dbe2a1
[profile/ivi/qtdeclarative.git] / src / qtquick1 / graphicsitems / qdeclarativeitem.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
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 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QDECLARATIVEITEM_H
43 #define QDECLARATIVEITEM_H
44
45 #include <QtDeclarative/qdeclarative.h>
46 #include <QtDeclarative/qdeclarativecomponent.h>
47
48 #include <QtCore/QObject>
49 #include <QtCore/QList>
50 #include <QtGui/qfont.h>
51 #include <QtWidgets/qgraphicsitem.h>
52 #include <QtWidgets/qgraphicswidget.h>
53 #include <QtWidgets/qgraphicstransform.h>
54 #include <QtGui/qaccessible.h>
55 #include <QtWidgets/qaction.h>
56
57 QT_BEGIN_HEADER
58
59 QT_BEGIN_NAMESPACE
60
61
62 class QDeclarative1State;
63 class QDeclarative1AnchorLine;
64 class QDeclarative1Transition;
65 class QDeclarative1KeyEvent;
66 class QDeclarative1Anchors;
67 class QDeclarativeItemPrivate;
68 class QDeclarativeV8Function;
69 class Q_QTQUICK1_EXPORT QDeclarativeItem : public QGraphicsObject, public QDeclarativeParserStatus
70 {
71     Q_OBJECT
72     Q_INTERFACES(QDeclarativeParserStatus)
73
74     Q_PROPERTY(QDeclarativeItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
75     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false)
76     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false)
77     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QDeclarative1State> states READ states DESIGNABLE false)
78     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QDeclarative1Transition> transitions READ transitions DESIGNABLE false)
79     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QString state READ state WRITE setState NOTIFY stateChanged)
80     Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
81     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1Anchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
82     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine left READ left CONSTANT FINAL)
83     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine right READ right CONSTANT FINAL)
84     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
85     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine top READ top CONSTANT FINAL)
86     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine bottom READ bottom CONSTANT FINAL)
87     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
88     Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarative1AnchorLine baseline READ baseline CONSTANT FINAL)
89     Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
90     Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) // ### move to QGI/QGO, NOTIFY
91     Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
92     Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged)
93     Q_PROPERTY(QDeclarativeListProperty<QGraphicsTransform> transform READ transform DESIGNABLE false FINAL)
94     Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
95     Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // transformOriginPoint is read-only for Item
96     Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
97     Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged REVISION 1)
98     Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged REVISION 1)
99
100     Q_ENUMS(TransformOrigin)
101     Q_CLASSINFO("DefaultProperty", "data")
102
103 public:
104     enum TransformOrigin {
105         TopLeft, Top, TopRight,
106         Left, Center, Right,
107         BottomLeft, Bottom, BottomRight
108     };
109
110     QDeclarativeItem(QDeclarativeItem *parent = 0);
111     virtual ~QDeclarativeItem();
112
113     QDeclarativeItem *parentItem() const;
114     void setParentItem(QDeclarativeItem *parent);
115
116     QRectF childrenRect();
117
118     bool clip() const;
119     void setClip(bool);
120
121     qreal baselineOffset() const;
122     void setBaselineOffset(qreal);
123
124     QDeclarativeListProperty<QGraphicsTransform> transform();
125
126     qreal width() const;
127     void setWidth(qreal);
128     void resetWidth();
129     qreal implicitWidth() const;
130
131     qreal height() const;
132     void setHeight(qreal);
133     void resetHeight();
134     qreal implicitHeight() const;
135
136     void setSize(const QSizeF &size);
137
138     TransformOrigin transformOrigin() const;
139     void setTransformOrigin(TransformOrigin);
140
141     bool smooth() const;
142     void setSmooth(bool);
143
144     QRectF boundingRect() const;
145     virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
146
147     bool hasActiveFocus() const;
148     bool hasFocus() const;
149     void setFocus(bool);
150
151     bool keepMouseGrab() const;
152     void setKeepMouseGrab(bool);
153
154     Q_INVOKABLE void mapFromItem(QDeclarativeV8Function*) const;
155     Q_INVOKABLE void mapToItem(QDeclarativeV8Function*) const;
156     Q_INVOKABLE void forceActiveFocus();
157     Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const;
158
159 Q_SIGNALS:
160     void childrenRectChanged(const QRectF &);
161     void baselineOffsetChanged(qreal);
162     void stateChanged(const QString &);
163     void focusChanged(bool);
164     void activeFocusChanged(bool);
165     void parentChanged(QDeclarativeItem *);
166     void transformOriginChanged(TransformOrigin);
167     void smoothChanged(bool);
168     void clipChanged(bool);
169     Q_REVISION(1) void implicitWidthChanged();
170     Q_REVISION(1) void implicitHeightChanged();
171
172 protected:
173     bool isComponentComplete() const;
174     virtual bool sceneEvent(QEvent *);
175     virtual bool event(QEvent *);
176     virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
177
178     void setImplicitWidth(qreal);
179     bool widthValid() const; // ### better name?
180     void setImplicitHeight(qreal);
181     bool heightValid() const; // ### better name?
182
183     virtual void classBegin();
184     virtual void componentComplete();
185     virtual void keyPressEvent(QKeyEvent *event);
186     virtual void keyReleaseEvent(QKeyEvent *event);
187     virtual void inputMethodEvent(QInputMethodEvent *);
188     virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
189     void keyPressPreHandler(QKeyEvent *);
190     void keyReleasePreHandler(QKeyEvent *);
191     void inputMethodPreHandler(QInputMethodEvent *);
192
193     virtual void geometryChanged(const QRectF &newGeometry,
194                                  const QRectF &oldGeometry);
195
196 protected:
197     QDeclarativeItem(QDeclarativeItemPrivate &dd, QDeclarativeItem *parent = 0);
198
199 private:
200     Q_DISABLE_COPY(QDeclarativeItem)
201     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem)
202
203     friend class QDeclarativeAccessibleAttached;
204 };
205
206 template<typename T>
207         T qobject_cast(QGraphicsObject *o)
208 {
209     QObject *obj = o;
210     return qobject_cast<T>(obj);
211 }
212
213 // ### move to QGO
214 template<typename T>
215 T qobject_cast(QGraphicsItem *item)
216 {
217     if (!item) return 0;
218     QObject *o = item->toGraphicsObject();
219     return qobject_cast<T>(o);
220 }
221
222 #ifndef QT_NO_DEBUG_STREAM
223 QDebug Q_QTQUICK1_EXPORT operator<<(QDebug debug, QDeclarativeItem *item);
224 #endif
225
226 QT_END_NAMESPACE
227
228 QML_DECLARE_TYPE(QDeclarativeItem)
229 QML_DECLARE_TYPE(QGraphicsObject)
230 QML_DECLARE_TYPE(QGraphicsTransform)
231 QML_DECLARE_TYPE(QGraphicsScale)
232 QML_DECLARE_TYPE(QGraphicsRotation)
233 QML_DECLARE_TYPE(QGraphicsWidget)
234 QML_DECLARE_TYPE(QAction)
235
236 QT_END_HEADER
237
238 #endif // QDECLARATIVEITEM_H