| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 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 | ** Commercial Usage | 
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 14 | ** a written agreement between you and Nokia. | 
|---|
| 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 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you have questions regarding the use of this file, please contact | 
|---|
| 37 | ** Nokia at qt-info@nokia.com. | 
|---|
| 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 activeFocus READ hasActiveFocus NOTIFY activeFocusChanged) | 
|---|
| 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(QPointF transformOriginPoint READ transformOriginPoint) // transformOriginPoint is read-only for Item | 
|---|
| 94 | Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) | 
|---|
| 95 | Q_ENUMS(TransformOrigin) | 
|---|
| 96 | Q_CLASSINFO("DefaultProperty", "data") | 
|---|
| 97 |  | 
|---|
| 98 | public: | 
|---|
| 99 | enum TransformOrigin { | 
|---|
| 100 | TopLeft, Top, TopRight, | 
|---|
| 101 | Left, Center, Right, | 
|---|
| 102 | BottomLeft, Bottom, BottomRight | 
|---|
| 103 | }; | 
|---|
| 104 |  | 
|---|
| 105 | QDeclarativeItem(QDeclarativeItem *parent = 0); | 
|---|
| 106 | virtual ~QDeclarativeItem(); | 
|---|
| 107 |  | 
|---|
| 108 | QDeclarativeItem *parentItem() const; | 
|---|
| 109 | void setParentItem(QDeclarativeItem *parent); | 
|---|
| 110 |  | 
|---|
| 111 | QRectF childrenRect(); | 
|---|
| 112 |  | 
|---|
| 113 | bool clip() const; | 
|---|
| 114 | void setClip(bool); | 
|---|
| 115 |  | 
|---|
| 116 | qreal baselineOffset() const; | 
|---|
| 117 | void setBaselineOffset(qreal); | 
|---|
| 118 |  | 
|---|
| 119 | QDeclarativeListProperty<QGraphicsTransform> transform(); | 
|---|
| 120 |  | 
|---|
| 121 | qreal width() const; | 
|---|
| 122 | void setWidth(qreal); | 
|---|
| 123 | void resetWidth(); | 
|---|
| 124 | qreal implicitWidth() const; | 
|---|
| 125 |  | 
|---|
| 126 | qreal height() const; | 
|---|
| 127 | void setHeight(qreal); | 
|---|
| 128 | void resetHeight(); | 
|---|
| 129 | qreal implicitHeight() const; | 
|---|
| 130 |  | 
|---|
| 131 | void setSize(const QSizeF &size); | 
|---|
| 132 |  | 
|---|
| 133 | TransformOrigin transformOrigin() const; | 
|---|
| 134 | void setTransformOrigin(TransformOrigin); | 
|---|
| 135 |  | 
|---|
| 136 | bool smooth() const; | 
|---|
| 137 | void setSmooth(bool); | 
|---|
| 138 |  | 
|---|
| 139 | QRectF boundingRect() const; | 
|---|
| 140 | virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *); | 
|---|
| 141 |  | 
|---|
| 142 | bool hasActiveFocus() const; | 
|---|
| 143 | bool hasFocus() const; | 
|---|
| 144 | void setFocus(bool); | 
|---|
| 145 |  | 
|---|
| 146 | bool keepMouseGrab() const; | 
|---|
| 147 | void setKeepMouseGrab(bool); | 
|---|
| 148 |  | 
|---|
| 149 | Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const; | 
|---|
| 150 | Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const; | 
|---|
| 151 | Q_INVOKABLE void forceActiveFocus(); | 
|---|
| 152 | Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const; | 
|---|
| 153 |  | 
|---|
| 154 | Q_SIGNALS: | 
|---|
| 155 | void childrenRectChanged(const QRectF &); | 
|---|
| 156 | void baselineOffsetChanged(qreal); | 
|---|
| 157 | void stateChanged(const QString &); | 
|---|
| 158 | void focusChanged(bool); | 
|---|
| 159 | void activeFocusChanged(bool); | 
|---|
| 160 | void parentChanged(QDeclarativeItem *); | 
|---|
| 161 | void transformOriginChanged(TransformOrigin); | 
|---|
| 162 | void smoothChanged(bool); | 
|---|
| 163 | void clipChanged(bool); | 
|---|
| 164 |  | 
|---|
| 165 | protected: | 
|---|
| 166 | bool isComponentComplete() const; | 
|---|
| 167 | virtual bool sceneEvent(QEvent *); | 
|---|
| 168 | virtual bool event(QEvent *); | 
|---|
| 169 | virtual QVariant itemChange(GraphicsItemChange, const QVariant &); | 
|---|
| 170 |  | 
|---|
| 171 | void setImplicitWidth(qreal); | 
|---|
| 172 | bool widthValid() const; // ### better name? | 
|---|
| 173 | void setImplicitHeight(qreal); | 
|---|
| 174 | bool heightValid() const; // ### better name? | 
|---|
| 175 |  | 
|---|
| 176 | virtual void classBegin(); | 
|---|
| 177 | virtual void componentComplete(); | 
|---|
| 178 | virtual void keyPressEvent(QKeyEvent *event); | 
|---|
| 179 | virtual void keyReleaseEvent(QKeyEvent *event); | 
|---|
| 180 | virtual void inputMethodEvent(QInputMethodEvent *); | 
|---|
| 181 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; | 
|---|
| 182 | void keyPressPreHandler(QKeyEvent *); | 
|---|
| 183 | void keyReleasePreHandler(QKeyEvent *); | 
|---|
| 184 | void inputMethodPreHandler(QInputMethodEvent *); | 
|---|
| 185 |  | 
|---|
| 186 | virtual void geometryChanged(const QRectF &newGeometry, | 
|---|
| 187 | const QRectF &oldGeometry); | 
|---|
| 188 |  | 
|---|
| 189 | protected: | 
|---|
| 190 | QDeclarativeItem(QDeclarativeItemPrivate &dd, QDeclarativeItem *parent = 0); | 
|---|
| 191 |  | 
|---|
| 192 | private: | 
|---|
| 193 | Q_DISABLE_COPY(QDeclarativeItem) | 
|---|
| 194 | Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QDeclarativeItem) | 
|---|
| 195 | }; | 
|---|
| 196 |  | 
|---|
| 197 | template<typename T> | 
|---|
| 198 | T qobject_cast(QGraphicsObject *o) | 
|---|
| 199 | { | 
|---|
| 200 | QObject *obj = o; | 
|---|
| 201 | return qobject_cast<T>(obj); | 
|---|
| 202 | } | 
|---|
| 203 |  | 
|---|
| 204 | // ### move to QGO | 
|---|
| 205 | template<typename T> | 
|---|
| 206 | T qobject_cast(QGraphicsItem *item) | 
|---|
| 207 | { | 
|---|
| 208 | if (!item) return 0; | 
|---|
| 209 | QObject *o = item->toGraphicsObject(); | 
|---|
| 210 | return qobject_cast<T>(o); | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 | #ifndef QT_NO_DEBUG_STREAM | 
|---|
| 214 | QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QDeclarativeItem *item); | 
|---|
| 215 | #endif | 
|---|
| 216 |  | 
|---|
| 217 | QT_END_NAMESPACE | 
|---|
| 218 |  | 
|---|
| 219 | QML_DECLARE_TYPE(QDeclarativeItem) | 
|---|
| 220 | QML_DECLARE_TYPE(QGraphicsObject) | 
|---|
| 221 | QML_DECLARE_TYPE(QGraphicsTransform) | 
|---|
| 222 | QML_DECLARE_TYPE(QGraphicsScale) | 
|---|
| 223 | QML_DECLARE_TYPE(QGraphicsRotation) | 
|---|
| 224 | QML_DECLARE_TYPE(QGraphicsWidget) | 
|---|
| 225 | QML_DECLARE_TYPE(QAction) | 
|---|
| 226 |  | 
|---|
| 227 | QT_END_HEADER | 
|---|
| 228 |  | 
|---|
| 229 | #endif // QDECLARATIVEITEM_H | 
|---|