|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtDeclarative module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
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/qgraphicsitem.h> |
|
51 #include <QtGui/qgraphicstransform.h> |
|
52 #include <QtGui/qfont.h> |
|
53 #include <QtGui/qaction.h> |
|
54 |
|
55 QT_BEGIN_HEADER |
|
56 |
|
57 QT_BEGIN_NAMESPACE |
|
58 |
|
59 QT_MODULE(Declarative) |
|
60 |
|
61 class QDeclarativeState; |
|
62 class QDeclarativeAnchorLine; |
|
63 class QDeclarativeTransition; |
|
64 class QDeclarativeKeyEvent; |
|
65 class QDeclarativeAnchors; |
|
66 class QDeclarativeItemPrivate; |
|
67 class Q_DECLARATIVE_EXPORT QDeclarativeItem : public QGraphicsObject, public QDeclarativeParserStatus |
|
68 { |
|
69 Q_OBJECT |
|
70 Q_INTERFACES(QDeclarativeParserStatus) |
|
71 |
|
72 Q_PROPERTY(QDeclarativeItem * parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL) |
|
73 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QObject> data READ data DESIGNABLE false) |
|
74 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QObject> resources READ resources DESIGNABLE false) |
|
75 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QDeclarativeState> states READ states DESIGNABLE false) |
|
76 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeListProperty<QDeclarativeTransition> transitions READ transitions DESIGNABLE false) |
|
77 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QString state READ state WRITE setState NOTIFY stateChanged) |
|
78 Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL) |
|
79 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL) |
|
80 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine left READ left CONSTANT FINAL) |
|
81 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine right READ right CONSTANT FINAL) |
|
82 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL) |
|
83 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine top READ top CONSTANT FINAL) |
|
84 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine bottom READ bottom CONSTANT FINAL) |
|
85 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL) |
|
86 Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchorLine baseline READ baseline CONSTANT FINAL) |
|
87 Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged) |
|
88 Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged) // ### move to QGI/QGO, NOTIFY |
|
89 Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL) |
|
90 Q_PROPERTY(bool wantsFocus READ wantsFocus NOTIFY wantsFocusChanged) |
|
91 Q_PROPERTY(QDeclarativeListProperty<QGraphicsTransform> transform READ transform DESIGNABLE false FINAL) |
|
92 Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged) |
|
93 Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) |
|
94 Q_ENUMS(TransformOrigin) |
|
95 Q_CLASSINFO("DefaultProperty", "data") |
|
96 |
|
97 public: |
|
98 enum TransformOrigin { |
|
99 TopLeft, Top, TopRight, |
|
100 Left, Center, Right, |
|
101 BottomLeft, Bottom, BottomRight |
|
102 }; |
|
103 |
|
104 QDeclarativeItem(QDeclarativeItem *parent = 0); |
|
105 virtual ~QDeclarativeItem(); |
|
106 |
|
107 QDeclarativeItem *parentItem() const; |
|
108 void setParentItem(QDeclarativeItem *parent); |
|
109 |
|
110 QRectF childrenRect(); |
|
111 |
|
112 bool clip() const; |
|
113 void setClip(bool); |
|
114 |
|
115 qreal baselineOffset() const; |
|
116 void setBaselineOffset(qreal); |
|
117 |
|
118 QDeclarativeListProperty<QGraphicsTransform> transform(); |
|
119 |
|
120 qreal width() const; |
|
121 void setWidth(qreal); |
|
122 void resetWidth(); |
|
123 qreal implicitWidth() const; |
|
124 |
|
125 qreal height() const; |
|
126 void setHeight(qreal); |
|
127 void resetHeight(); |
|
128 qreal implicitHeight() const; |
|
129 |
|
130 void setSize(const QSizeF &size); |
|
131 |
|
132 TransformOrigin transformOrigin() const; |
|
133 void setTransformOrigin(TransformOrigin); |
|
134 |
|
135 bool smooth() const; |
|
136 void setSmooth(bool); |
|
137 |
|
138 QRectF boundingRect() const; |
|
139 virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); |
|
140 |
|
141 bool wantsFocus() const; |
|
142 bool hasFocus() const; |
|
143 void setFocus(bool); |
|
144 |
|
145 bool keepMouseGrab() const; |
|
146 void setKeepMouseGrab(bool); |
|
147 |
|
148 Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const; |
|
149 Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; |
|
150 Q_INVOKABLE void forceFocus(); |
|
151 |
|
152 Q_SIGNALS: |
|
153 void childrenChanged(); |
|
154 void childrenRectChanged(const QRectF &); |
|
155 void baselineOffsetChanged(qreal); |
|
156 void stateChanged(const QString &); |
|
157 void focusChanged(bool); |
|
158 void wantsFocusChanged(bool); |
|
159 void parentChanged(QDeclarativeItem *); |
|
160 void transformOriginChanged(TransformOrigin); |
|
161 void smoothChanged(bool); |
|
162 void clipChanged(bool); |
|
163 |
|
164 protected: |
|
165 bool isComponentComplete() const; |
|
166 virtual bool sceneEvent(QEvent *); |
|
167 virtual bool event(QEvent *); |
|
168 virtual QVariant itemChange(GraphicsItemChange, const QVariant &); |
|
169 |
|
170 void setImplicitWidth(qreal); |
|
171 bool widthValid() const; // ### better name? |
|
172 void setImplicitHeight(qreal); |
|
173 bool heightValid() const; // ### better name? |
|
174 |
|
175 virtual void classBegin(); |
|
176 virtual void componentComplete(); |
|
177 virtual void keyPressEvent(QKeyEvent *event); |
|
178 virtual void keyReleaseEvent(QKeyEvent *event); |
|
179 virtual void inputMethodEvent(QInputMethodEvent *); |
|
180 virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; |
|
181 void keyPressPreHandler(QKeyEvent *); |
|
182 void keyReleasePreHandler(QKeyEvent *); |
|
183 void inputMethodPreHandler(QInputMethodEvent *); |
|
184 |
|
185 virtual void geometryChanged(const QRectF &newGeometry, |
|
186 const QRectF &oldGeometry); |
|
187 |
|
188 protected: |
|
189 QDeclarativeItem(QDeclarativeItemPrivate &dd, QDeclarativeItem *parent = 0); |
|
190 |
|
191 private: |
|
192 Q_DISABLE_COPY(QDeclarativeItem) |
|
193 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) |
|
194 }; |
|
195 |
|
196 template<typename T> |
|
197 T qobject_cast(QGraphicsObject *o) |
|
198 { |
|
199 QObject *obj = o; |
|
200 return qobject_cast<T>(obj); |
|
201 } |
|
202 |
|
203 // ### move to QGO |
|
204 template<typename T> |
|
205 T qobject_cast(QGraphicsItem *item) |
|
206 { |
|
207 if (!item) return 0; |
|
208 QObject *o = item->toGraphicsObject(); |
|
209 return qobject_cast<T>(o); |
|
210 } |
|
211 |
|
212 QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QDeclarativeItem *item); |
|
213 |
|
214 QT_END_NAMESPACE |
|
215 |
|
216 QML_DECLARE_TYPE(QDeclarativeItem) |
|
217 QML_DECLARE_TYPE(QGraphicsObject) |
|
218 QML_DECLARE_TYPE(QGraphicsTransform) |
|
219 QML_DECLARE_TYPE(QGraphicsScale) |
|
220 QML_DECLARE_TYPE(QGraphicsRotation) |
|
221 QML_DECLARE_TYPE(QGraphicsWidget) |
|
222 QML_DECLARE_TYPE(QAction) |
|
223 |
|
224 QT_END_HEADER |
|
225 |
|
226 #endif // QDECLARATIVEITEM_H |