qquickitem.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtQuick 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 The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QQUICKITEM_H
  40. #define QQUICKITEM_H
  41. #include <QtQuick/qtquickglobal.h>
  42. #include <QtQml/qqml.h>
  43. #include <QtQml/qqmlcomponent.h>
  44. #include <QtCore/QObject>
  45. #include <QtCore/QList>
  46. #include <QtGui/qevent.h>
  47. #include <QtGui/qfont.h>
  48. #include <QtGui/qaccessible.h>
  49. QT_BEGIN_NAMESPACE
  50. class QQuickItem;
  51. class QQuickTransformPrivate;
  52. class Q_QUICK_EXPORT QQuickTransform : public QObject
  53. {
  54. Q_OBJECT
  55. public:
  56. explicit QQuickTransform(QObject *parent = Q_NULLPTR);
  57. ~QQuickTransform();
  58. void appendToItem(QQuickItem *);
  59. void prependToItem(QQuickItem *);
  60. virtual void applyTo(QMatrix4x4 *matrix) const = 0;
  61. protected Q_SLOTS:
  62. void update();
  63. protected:
  64. QQuickTransform(QQuickTransformPrivate &dd, QObject *parent);
  65. private:
  66. Q_DECLARE_PRIVATE(QQuickTransform)
  67. };
  68. class QCursor;
  69. class QQuickItemLayer;
  70. class QQmlV4Function;
  71. class QQuickState;
  72. class QQuickAnchorLine;
  73. class QQuickTransition;
  74. class QQuickKeyEvent;
  75. class QQuickAnchors;
  76. class QQuickItemPrivate;
  77. class QQuickWindow;
  78. class QTouchEvent;
  79. class QSGNode;
  80. class QSGTransformNode;
  81. class QSGTextureProvider;
  82. class QQuickItemGrabResult;
  83. class Q_QUICK_EXPORT QQuickItem : public QObject, public QQmlParserStatus
  84. {
  85. Q_OBJECT
  86. Q_INTERFACES(QQmlParserStatus)
  87. Q_PROPERTY(QQuickItem *parent READ parentItem WRITE setParentItem NOTIFY parentChanged DESIGNABLE false FINAL)
  88. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> data READ data DESIGNABLE false)
  89. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QObject> resources READ resources DESIGNABLE false)
  90. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> children READ children NOTIFY childrenChanged DESIGNABLE false)
  91. Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged FINAL)
  92. Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged FINAL)
  93. Q_PROPERTY(qreal z READ z WRITE setZ NOTIFY zChanged FINAL)
  94. Q_PROPERTY(qreal width READ width WRITE setWidth NOTIFY widthChanged RESET resetWidth FINAL)
  95. Q_PROPERTY(qreal height READ height WRITE setHeight NOTIFY heightChanged RESET resetHeight FINAL)
  96. Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged FINAL)
  97. Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
  98. Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged FINAL)
  99. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickItem> visibleChildren READ visibleChildren NOTIFY visibleChildrenChanged DESIGNABLE false)
  100. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickState> states READ states DESIGNABLE false)
  101. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQmlListProperty<QQuickTransition> transitions READ transitions DESIGNABLE false)
  102. Q_PROPERTY(QString state READ state WRITE setState NOTIFY stateChanged)
  103. Q_PROPERTY(QRectF childrenRect READ childrenRect NOTIFY childrenRectChanged DESIGNABLE false FINAL)
  104. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchors * anchors READ anchors DESIGNABLE false CONSTANT FINAL)
  105. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine left READ left CONSTANT FINAL)
  106. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine right READ right CONSTANT FINAL)
  107. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine horizontalCenter READ horizontalCenter CONSTANT FINAL)
  108. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine top READ top CONSTANT FINAL)
  109. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine bottom READ bottom CONSTANT FINAL)
  110. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine verticalCenter READ verticalCenter CONSTANT FINAL)
  111. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickAnchorLine baseline READ baseline CONSTANT FINAL)
  112. Q_PROPERTY(qreal baselineOffset READ baselineOffset WRITE setBaselineOffset NOTIFY baselineOffsetChanged)
  113. Q_PROPERTY(bool clip READ clip WRITE setClip NOTIFY clipChanged)
  114. Q_PROPERTY(bool focus READ hasFocus WRITE setFocus NOTIFY focusChanged FINAL)
  115. Q_PROPERTY(bool activeFocus READ hasActiveFocus NOTIFY activeFocusChanged FINAL)
  116. Q_PROPERTY(bool activeFocusOnTab READ activeFocusOnTab WRITE setActiveFocusOnTab NOTIFY activeFocusOnTabChanged FINAL REVISION 1)
  117. Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
  118. Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
  119. Q_PROPERTY(TransformOrigin transformOrigin READ transformOrigin WRITE setTransformOrigin NOTIFY transformOriginChanged)
  120. Q_PROPERTY(QPointF transformOriginPoint READ transformOriginPoint) // deprecated - see QTBUG-26423
  121. Q_PROPERTY(QQmlListProperty<QQuickTransform> transform READ transform DESIGNABLE false FINAL)
  122. Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged)
  123. Q_PROPERTY(bool antialiasing READ antialiasing WRITE setAntialiasing NOTIFY antialiasingChanged RESET resetAntialiasing)
  124. Q_PROPERTY(qreal implicitWidth READ implicitWidth WRITE setImplicitWidth NOTIFY implicitWidthChanged)
  125. Q_PROPERTY(qreal implicitHeight READ implicitHeight WRITE setImplicitHeight NOTIFY implicitHeightChanged)
  126. Q_PRIVATE_PROPERTY(QQuickItem::d_func(), QQuickItemLayer *layer READ layer DESIGNABLE false CONSTANT FINAL)
  127. Q_CLASSINFO("DefaultProperty", "data")
  128. Q_CLASSINFO("qt_HasQmlAccessors", "true")
  129. Q_CLASSINFO("qt_QmlJSWrapperFactoryMethod", "_q_createJSWrapper(QV4::ExecutionEngine*)")
  130. public:
  131. enum Flag {
  132. ItemClipsChildrenToShape = 0x01,
  133. #ifndef QT_NO_IM
  134. ItemAcceptsInputMethod = 0x02,
  135. #endif
  136. ItemIsFocusScope = 0x04,
  137. ItemHasContents = 0x08,
  138. ItemAcceptsDrops = 0x10
  139. // Remember to increment the size of QQuickItemPrivate::flags
  140. };
  141. Q_DECLARE_FLAGS(Flags, Flag)
  142. enum ItemChange {
  143. ItemChildAddedChange, // value.item
  144. ItemChildRemovedChange, // value.item
  145. ItemSceneChange, // value.window
  146. ItemVisibleHasChanged, // value.boolValue
  147. ItemParentHasChanged, // value.item
  148. ItemOpacityHasChanged, // value.realValue
  149. ItemActiveFocusHasChanged, // value.boolValue
  150. ItemRotationHasChanged, // value.realValue
  151. ItemAntialiasingHasChanged, // value.boolValue
  152. ItemDevicePixelRatioHasChanged // value.realValue
  153. };
  154. union ItemChangeData {
  155. ItemChangeData(QQuickItem *v) : item(v) {}
  156. ItemChangeData(QQuickWindow *v) : window(v) {}
  157. ItemChangeData(qreal v) : realValue(v) {}
  158. ItemChangeData(bool v) : boolValue(v) {}
  159. QQuickItem *item;
  160. QQuickWindow *window;
  161. qreal realValue;
  162. bool boolValue;
  163. };
  164. enum TransformOrigin {
  165. TopLeft, Top, TopRight,
  166. Left, Center, Right,
  167. BottomLeft, Bottom, BottomRight
  168. };
  169. Q_ENUM(TransformOrigin)
  170. explicit QQuickItem(QQuickItem *parent = Q_NULLPTR);
  171. virtual ~QQuickItem();
  172. QQuickWindow *window() const;
  173. QQuickItem *parentItem() const;
  174. void setParentItem(QQuickItem *parent);
  175. void stackBefore(const QQuickItem *);
  176. void stackAfter(const QQuickItem *);
  177. QRectF childrenRect();
  178. QList<QQuickItem *> childItems() const;
  179. bool clip() const;
  180. void setClip(bool);
  181. QString state() const;
  182. void setState(const QString &);
  183. qreal baselineOffset() const;
  184. void setBaselineOffset(qreal);
  185. QQmlListProperty<QQuickTransform> transform();
  186. qreal x() const;
  187. qreal y() const;
  188. QPointF position() const;
  189. void setX(qreal);
  190. void setY(qreal);
  191. void setPosition(const QPointF &);
  192. qreal width() const;
  193. void setWidth(qreal);
  194. void resetWidth();
  195. void setImplicitWidth(qreal);
  196. qreal implicitWidth() const;
  197. qreal height() const;
  198. void setHeight(qreal);
  199. void resetHeight();
  200. void setImplicitHeight(qreal);
  201. qreal implicitHeight() const;
  202. void setSize(const QSizeF &size);
  203. TransformOrigin transformOrigin() const;
  204. void setTransformOrigin(TransformOrigin);
  205. QPointF transformOriginPoint() const;
  206. void setTransformOriginPoint(const QPointF &);
  207. qreal z() const;
  208. void setZ(qreal);
  209. qreal rotation() const;
  210. void setRotation(qreal);
  211. qreal scale() const;
  212. void setScale(qreal);
  213. qreal opacity() const;
  214. void setOpacity(qreal);
  215. bool isVisible() const;
  216. void setVisible(bool);
  217. bool isEnabled() const;
  218. void setEnabled(bool);
  219. bool smooth() const;
  220. void setSmooth(bool);
  221. bool activeFocusOnTab() const;
  222. void setActiveFocusOnTab(bool);
  223. bool antialiasing() const;
  224. void setAntialiasing(bool);
  225. void resetAntialiasing();
  226. Flags flags() const;
  227. void setFlag(Flag flag, bool enabled = true);
  228. void setFlags(Flags flags);
  229. virtual QRectF boundingRect() const;
  230. virtual QRectF clipRect() const;
  231. bool hasActiveFocus() const;
  232. bool hasFocus() const;
  233. void setFocus(bool);
  234. void setFocus(bool focus, Qt::FocusReason reason);
  235. bool isFocusScope() const;
  236. QQuickItem *scopedFocusItem() const;
  237. bool isAncestorOf(const QQuickItem *child) const;
  238. Qt::MouseButtons acceptedMouseButtons() const;
  239. void setAcceptedMouseButtons(Qt::MouseButtons buttons);
  240. bool acceptHoverEvents() const;
  241. void setAcceptHoverEvents(bool enabled);
  242. #ifndef QT_NO_CURSOR
  243. QCursor cursor() const;
  244. void setCursor(const QCursor &cursor);
  245. void unsetCursor();
  246. #endif
  247. bool isUnderMouse() const;
  248. void grabMouse();
  249. void ungrabMouse();
  250. bool keepMouseGrab() const;
  251. void setKeepMouseGrab(bool);
  252. bool filtersChildMouseEvents() const;
  253. void setFiltersChildMouseEvents(bool filter);
  254. void grabTouchPoints(const QVector<int> &ids);
  255. void ungrabTouchPoints();
  256. bool keepTouchGrab() const;
  257. void setKeepTouchGrab(bool);
  258. // implemented in qquickitemgrabresult.cpp
  259. Q_REVISION(2) Q_INVOKABLE bool grabToImage(const QJSValue &callback, const QSize &targetSize = QSize());
  260. QSharedPointer<QQuickItemGrabResult> grabToImage(const QSize &targetSize = QSize());
  261. Q_INVOKABLE virtual bool contains(const QPointF &point) const;
  262. QTransform itemTransform(QQuickItem *, bool *) const;
  263. QPointF mapToItem(const QQuickItem *item, const QPointF &point) const;
  264. QPointF mapToScene(const QPointF &point) const;
  265. Q_REVISION(7) Q_INVOKABLE QPointF mapToGlobal(const QPointF &point) const;
  266. QRectF mapRectToItem(const QQuickItem *item, const QRectF &rect) const;
  267. QRectF mapRectToScene(const QRectF &rect) const;
  268. QPointF mapFromItem(const QQuickItem *item, const QPointF &point) const;
  269. QPointF mapFromScene(const QPointF &point) const;
  270. Q_REVISION(7) Q_INVOKABLE QPointF mapFromGlobal(const QPointF &point) const;
  271. QRectF mapRectFromItem(const QQuickItem *item, const QRectF &rect) const;
  272. QRectF mapRectFromScene(const QRectF &rect) const;
  273. void polish();
  274. Q_INVOKABLE void mapFromItem(QQmlV4Function*) const;
  275. Q_INVOKABLE void mapToItem(QQmlV4Function*) const;
  276. Q_INVOKABLE void forceActiveFocus();
  277. Q_INVOKABLE void forceActiveFocus(Qt::FocusReason reason);
  278. Q_REVISION(1) Q_INVOKABLE QQuickItem *nextItemInFocusChain(bool forward = true);
  279. Q_INVOKABLE QQuickItem *childAt(qreal x, qreal y) const;
  280. #ifndef QT_NO_IM
  281. virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
  282. #endif
  283. struct UpdatePaintNodeData {
  284. QSGTransformNode *transformNode;
  285. private:
  286. friend class QQuickWindowPrivate;
  287. UpdatePaintNodeData();
  288. };
  289. virtual bool isTextureProvider() const;
  290. virtual QSGTextureProvider *textureProvider() const;
  291. public Q_SLOTS:
  292. void update();
  293. Q_SIGNALS:
  294. void childrenRectChanged(const QRectF &);
  295. void baselineOffsetChanged(qreal);
  296. void stateChanged(const QString &);
  297. void focusChanged(bool);
  298. void activeFocusChanged(bool);
  299. Q_REVISION(1) void activeFocusOnTabChanged(bool);
  300. void parentChanged(QQuickItem *);
  301. void transformOriginChanged(TransformOrigin);
  302. void smoothChanged(bool);
  303. void antialiasingChanged(bool);
  304. void clipChanged(bool);
  305. Q_REVISION(1) void windowChanged(QQuickWindow* window);
  306. // XXX todo
  307. void childrenChanged();
  308. void opacityChanged();
  309. void enabledChanged();
  310. void visibleChanged();
  311. void visibleChildrenChanged();
  312. void rotationChanged();
  313. void scaleChanged();
  314. void xChanged();
  315. void yChanged();
  316. void widthChanged();
  317. void heightChanged();
  318. void zChanged();
  319. void implicitWidthChanged();
  320. void implicitHeightChanged();
  321. protected:
  322. bool event(QEvent *) Q_DECL_OVERRIDE;
  323. bool isComponentComplete() const;
  324. virtual void itemChange(ItemChange, const ItemChangeData &);
  325. #ifndef QT_NO_IM
  326. void updateInputMethod(Qt::InputMethodQueries queries = Qt::ImQueryInput);
  327. #endif
  328. bool widthValid() const; // ### better name?
  329. bool heightValid() const; // ### better name?
  330. void setImplicitSize(qreal, qreal);
  331. void classBegin() Q_DECL_OVERRIDE;
  332. void componentComplete() Q_DECL_OVERRIDE;
  333. virtual void keyPressEvent(QKeyEvent *event);
  334. virtual void keyReleaseEvent(QKeyEvent *event);
  335. #ifndef QT_NO_IM
  336. virtual void inputMethodEvent(QInputMethodEvent *);
  337. #endif
  338. virtual void focusInEvent(QFocusEvent *);
  339. virtual void focusOutEvent(QFocusEvent *);
  340. virtual void mousePressEvent(QMouseEvent *event);
  341. virtual void mouseMoveEvent(QMouseEvent *event);
  342. virtual void mouseReleaseEvent(QMouseEvent *event);
  343. virtual void mouseDoubleClickEvent(QMouseEvent *event);
  344. virtual void mouseUngrabEvent(); // XXX todo - params?
  345. virtual void touchUngrabEvent();
  346. #ifndef QT_NO_WHEELEVENT
  347. virtual void wheelEvent(QWheelEvent *event);
  348. #endif
  349. virtual void touchEvent(QTouchEvent *event);
  350. virtual void hoverEnterEvent(QHoverEvent *event);
  351. virtual void hoverMoveEvent(QHoverEvent *event);
  352. virtual void hoverLeaveEvent(QHoverEvent *event);
  353. #ifndef QT_NO_DRAGANDDROP
  354. virtual void dragEnterEvent(QDragEnterEvent *);
  355. virtual void dragMoveEvent(QDragMoveEvent *);
  356. virtual void dragLeaveEvent(QDragLeaveEvent *);
  357. virtual void dropEvent(QDropEvent *);
  358. #endif
  359. virtual bool childMouseEventFilter(QQuickItem *, QEvent *);
  360. virtual void windowDeactivateEvent();
  361. virtual void geometryChanged(const QRectF &newGeometry,
  362. const QRectF &oldGeometry);
  363. virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
  364. virtual void releaseResources();
  365. virtual void updatePolish();
  366. protected:
  367. QQuickItem(QQuickItemPrivate &dd, QQuickItem *parent = Q_NULLPTR);
  368. private:
  369. Q_PRIVATE_SLOT(d_func(), void _q_resourceObjectDeleted(QObject *))
  370. Q_PRIVATE_SLOT(d_func(), quint64 _q_createJSWrapper(QV4::ExecutionEngine *))
  371. friend class QQuickWindow;
  372. friend class QQuickWindowPrivate;
  373. friend class QSGRenderer;
  374. friend class QAccessibleQuickItem;
  375. friend class QQuickAccessibleAttached;
  376. Q_DISABLE_COPY(QQuickItem)
  377. Q_DECLARE_PRIVATE(QQuickItem)
  378. };
  379. // XXX todo
  380. Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItem::Flags)
  381. #ifndef QT_NO_DEBUG_STREAM
  382. QDebug Q_QUICK_EXPORT operator<<(QDebug debug, QQuickItem *item);
  383. #endif
  384. QT_END_NAMESPACE
  385. QML_DECLARE_TYPE(QQuickItem)
  386. QML_DECLARE_TYPE(QQuickTransform)
  387. #endif // QQUICKITEM_H