Qt 4.8
qdeclarativeitem.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
56 
58 
59 QT_MODULE(Declarative)
60 
61 class QDeclarativeState;
68 {
69  Q_OBJECT
71 
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  QRectF childrenRect;
79  Q_PRIVATE_PROPERTY(QDeclarativeItem::d_func(), QDeclarativeAnchors * anchors READ anchors DESIGNABLE false 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  qreal baselineOffset;
88  bool clip; // ### move to QGI/QGO, NOTIFY
89  bool focus;
90  bool activeFocus;
92  TransformOrigin transformOrigin;
93  QPointF transformOriginPoint; // transformOriginPoint is read-only for Item
94  bool smooth;
95  qreal implicitWidth;
96  qreal implicitHeight;
97 
99  Q_CLASSINFO("DefaultProperty", "data")
100 
101 public:
103  TopLeft, Top, TopRight,
105  BottomLeft, Bottom, BottomRight
106  };
107 
108  QDeclarativeItem(QDeclarativeItem *parent = 0);
109  virtual ~QDeclarativeItem();
110 
111  QDeclarativeItem *parentItem() const;
112  void setParentItem(QDeclarativeItem *parent);
113 
114  QRectF childrenRect();
115 
116  bool clip() const;
117  void setClip(bool);
118 
119  qreal baselineOffset() const;
120  void setBaselineOffset(qreal);
121 
123 
124  qreal width() const;
125  void setWidth(qreal);
126  void resetWidth();
127  qreal implicitWidth() const;
128 
129  qreal height() const;
130  void setHeight(qreal);
131  void resetHeight();
132  qreal implicitHeight() const;
133 
134  void setSize(const QSizeF &size);
135 
136  TransformOrigin transformOrigin() const;
137  void setTransformOrigin(TransformOrigin);
138 
139  bool smooth() const;
140  void setSmooth(bool);
141 
142  QRectF boundingRect() const;
143  virtual void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *);
144 
145  bool hasActiveFocus() const;
146  bool hasFocus() const;
147  void setFocus(bool);
148 
149  bool keepMouseGrab() const;
150  void setKeepMouseGrab(bool);
151 
152  Q_INVOKABLE QScriptValue mapFromItem(const QScriptValue &item, qreal x, qreal y) const;
153  Q_INVOKABLE QScriptValue mapToItem(const QScriptValue &item, qreal x, qreal y) const;
154  Q_INVOKABLE void forceActiveFocus();
155  Q_INVOKABLE QDeclarativeItem *childAt(qreal x, qreal y) const;
156 
157 Q_SIGNALS:
158  void childrenRectChanged(const QRectF &);
159  void baselineOffsetChanged(qreal);
160  void stateChanged(const QString &);
161  void focusChanged(bool);
162  void activeFocusChanged(bool);
164  void transformOriginChanged(TransformOrigin);
165  void smoothChanged(bool);
166  void clipChanged(bool);
167  Q_REVISION(1) void implicitWidthChanged();
168  Q_REVISION(1) void implicitHeightChanged();
169 
170 protected:
171  bool isComponentComplete() const;
172  virtual bool sceneEvent(QEvent *);
173  virtual bool event(QEvent *);
174  virtual QVariant itemChange(GraphicsItemChange, const QVariant &);
175 
176  void setImplicitWidth(qreal);
177  bool widthValid() const; // ### better name?
178  void setImplicitHeight(qreal);
179  bool heightValid() const; // ### better name?
180 
181  virtual void classBegin();
182  virtual void componentComplete();
183  virtual void keyPressEvent(QKeyEvent *event);
184  virtual void keyReleaseEvent(QKeyEvent *event);
185  virtual void inputMethodEvent(QInputMethodEvent *);
186  virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
187  void keyPressPreHandler(QKeyEvent *);
188  void keyReleasePreHandler(QKeyEvent *);
189  void inputMethodPreHandler(QInputMethodEvent *);
190 
191  virtual void geometryChanged(const QRectF &newGeometry,
192  const QRectF &oldGeometry);
193 
194 protected:
196 
197 private:
200 };
201 
202 template<typename T>
204 {
205  QObject *obj = o;
206  return qobject_cast<T>(obj);
207 }
208 
209 // ### move to QGO
210 template<typename T>
212 {
213  if (!item) return 0;
214  QObject *o = item->toGraphicsObject();
215  return qobject_cast<T>(o);
216 }
217 
218 #ifndef QT_NO_DEBUG_STREAM
220 #endif
221 
223 
231 
233 
234 #endif // QDECLARATIVEITEM_H
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:62
bool hasFocus() const
Returns true if this item is active, and it or its focus proxy has keyboard input focus; otherwise...
The QKeyEvent class describes a key event.
Definition: qevent.h:224
#define Q_CLASSINFO(name, value)
This macro associates extra information to the class, which is available using QObject::metaObject()...
Definition: qobjectdefs.h:78
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
#define QT_MODULE(x)
Definition: qglobal.h:2783
#define Q_PRIVATE_PROPERTY(d, define Q_REVISION(v)
#define QML_DECLARE_TYPE(TYPE)
Definition: qdeclarative.h:56
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
QPointF mapFromItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in item&#39;s coordinate system, to this item&#39;s coordinate system...
QTransform transform() const
Returns this item&#39;s transformation matrix.
void setParentItem(QGraphicsItem *parent)
Sets this item&#39;s parent item to newParent.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
#define Q_INVOKABLE
Definition: qobjectdefs.h:90
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
T qobject_cast(QGraphicsObject *o)
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define Q_SIGNALS
Definition: qobjectdefs.h:72
QDebug Q_DECLARATIVE_EXPORT operator<<(QDebug debug, QDeclarativeItem *item)
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
The QGraphicsScale class provides a scale transformation.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
static void setClip(QPainter *painter, QGraphicsItem *item)
static const QRectF boundingRect(const QPointF *points, int pointCount)
QGraphicsObject * toGraphicsObject()
Return the graphics item cast to a QGraphicsObject, if the class is actually a graphics object...
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
The QDeclarativeItem class provides the most basic of all visual items in QML.
void parentChanged()
This signal gets emitted whenever the parent of the item changes.
The QDeclarativeParserStatus class provides updates on the QML parser state.
static const char * data(const QByteArray &arr)
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PRIVATE_D(Dptr, Class)
Definition: qglobal.h:2472
InputMethodQuery
Definition: qnamespace.h:1541
The QInputMethodEvent class provides parameters for input method events.
Definition: qevent.h:431
#define Q_DECLARATIVE_EXPORT
Definition: qglobal.h:1454
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item&#39;s coordinate system, to item&#39;s coordinate system...
QGraphicsItem * parentItem() const
Returns a pointer to this item&#39;s parent item.
TransformOrigin
Controls the point about which simple transforms like scale apply.
#define Q_INTERFACES(x)
This macro tells Qt which interfaces the class implements.
Definition: qobjectdefs.h:79
Definition: qnamespace.h:54
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
The QGraphicsRotation class provides a rotation transformation around a given axis.
The QGraphicsObject class provides a base class for all graphics items that require signals...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:137
The QScriptValue class acts as a container for the Qt Script data types.
Definition: qscriptvalue.h:57
#define private
Definition: qregion_qws.cpp:43
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
The QDeclarativeListProperty class allows applications to expose list-like properties to QML...
The QGraphicsTransform class is an abstract base class for building advanced transformations on QGrap...
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
void setFocus(Qt::FocusReason focusReason=Qt::OtherFocusReason)
Gives keyboard input focus to this item.