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 | |
40 | #ifndef QQUICKITEM_P_H |
41 | #define QQUICKITEM_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include "qquickitem.h" |
55 | |
56 | #include "qquickanchors_p.h" |
57 | #include "qquickanchors_p_p.h" |
58 | #include "qquickitemchangelistener_p.h" |
59 | #include "qquickevents_p_p.h" |
60 | |
61 | #include "qquickwindow_p.h" |
62 | |
63 | #include <QtQuick/qsgnode.h> |
64 | #include "qquickclipnode_p.h" |
65 | |
66 | #include <QtQuick/private/qquickstate_p.h> |
67 | #include <private/qqmlnullablevalue_p.h> |
68 | #include <private/qqmlnotifier_p.h> |
69 | #include <private/qqmlglobal_p.h> |
70 | #include <private/qlazilyallocated_p.h> |
71 | |
72 | #include <qqml.h> |
73 | #include <qqmlcontext.h> |
74 | |
75 | #include <QtCore/qlist.h> |
76 | #include <QtCore/qdebug.h> |
77 | #include <QtCore/qelapsedtimer.h> |
78 | #include <QtCore/qpointer.h> |
79 | |
80 | #if QT_CONFIG(quick_shadereffect) |
81 | #include <QtQuick/private/qquickshadereffectsource_p.h> |
82 | #endif |
83 | |
84 | QT_BEGIN_NAMESPACE |
85 | |
86 | class QNetworkReply; |
87 | class QQuickItemKeyFilter; |
88 | class QQuickLayoutMirroringAttached; |
89 | class QQuickEnterKeyAttached; |
90 | class QQuickScreenAttached; |
91 | class QQuickPointerHandler; |
92 | |
93 | class QQuickContents : public QQuickItemChangeListener |
94 | { |
95 | public: |
96 | QQuickContents(QQuickItem *item); |
97 | ~QQuickContents() override; |
98 | |
99 | QRectF rectF() const { return m_contents; } |
100 | |
101 | inline void calcGeometry(QQuickItem *changed = nullptr); |
102 | void complete(); |
103 | |
104 | protected: |
105 | void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override; |
106 | void itemDestroyed(QQuickItem *item) override; |
107 | void itemChildAdded(QQuickItem *, QQuickItem *) override; |
108 | void itemChildRemoved(QQuickItem *, QQuickItem *) override; |
109 | //void itemVisibilityChanged(QQuickItem *item) |
110 | |
111 | private: |
112 | bool calcHeight(QQuickItem *changed = nullptr); |
113 | bool calcWidth(QQuickItem *changed = nullptr); |
114 | void updateRect(); |
115 | |
116 | QQuickItem *m_item; |
117 | QRectF m_contents; |
118 | }; |
119 | |
120 | void QQuickContents::calcGeometry(QQuickItem *changed) |
121 | { |
122 | bool wChanged = calcWidth(changed); |
123 | bool hChanged = calcHeight(changed); |
124 | if (wChanged || hChanged) |
125 | updateRect(); |
126 | } |
127 | |
128 | class QQuickTransformPrivate : public QObjectPrivate |
129 | { |
130 | Q_DECLARE_PUBLIC(QQuickTransform) |
131 | public: |
132 | static QQuickTransformPrivate* get(QQuickTransform *transform) { return transform->d_func(); } |
133 | |
134 | QQuickTransformPrivate(); |
135 | |
136 | QList<QQuickItem *> items; |
137 | }; |
138 | |
139 | #if QT_CONFIG(quick_shadereffect) |
140 | |
141 | class QQuickItemLayer : public QObject, public QQuickItemChangeListener |
142 | { |
143 | Q_OBJECT |
144 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) |
145 | Q_PROPERTY(QSize textureSize READ size WRITE setSize NOTIFY sizeChanged) |
146 | Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged) |
147 | Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged) |
148 | Q_PROPERTY(bool smooth READ smooth WRITE setSmooth NOTIFY smoothChanged) |
149 | Q_PROPERTY(QQuickShaderEffectSource::WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) |
150 | Q_PROPERTY(QQuickShaderEffectSource::Format format READ format WRITE setFormat NOTIFY formatChanged) |
151 | Q_PROPERTY(QByteArray samplerName READ name WRITE setName NOTIFY nameChanged) |
152 | Q_PROPERTY(QQmlComponent *effect READ effect WRITE setEffect NOTIFY effectChanged) |
153 | Q_PROPERTY(QQuickShaderEffectSource::TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged) |
154 | Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged) |
155 | |
156 | public: |
157 | QQuickItemLayer(QQuickItem *item); |
158 | ~QQuickItemLayer() override; |
159 | |
160 | void classBegin(); |
161 | void componentComplete(); |
162 | |
163 | bool enabled() const { return m_enabled; } |
164 | void setEnabled(bool enabled); |
165 | |
166 | bool mipmap() const { return m_mipmap; } |
167 | void setMipmap(bool mipmap); |
168 | |
169 | bool smooth() const { return m_smooth; } |
170 | void setSmooth(bool s); |
171 | |
172 | QSize size() const { return m_size; } |
173 | void setSize(const QSize &size); |
174 | |
175 | QQuickShaderEffectSource::Format format() const { return m_format; } |
176 | void setFormat(QQuickShaderEffectSource::Format f); |
177 | |
178 | QRectF sourceRect() const { return m_sourceRect; } |
179 | void setSourceRect(const QRectF &sourceRect); |
180 | |
181 | QQuickShaderEffectSource::WrapMode wrapMode() const { return m_wrapMode; } |
182 | void setWrapMode(QQuickShaderEffectSource::WrapMode mode); |
183 | |
184 | QByteArray name() const { return m_name; } |
185 | void setName(const QByteArray &name); |
186 | |
187 | QQmlComponent *effect() const { return m_effectComponent; } |
188 | void setEffect(QQmlComponent *effect); |
189 | |
190 | QQuickShaderEffectSource::TextureMirroring textureMirroring() const { return m_textureMirroring; } |
191 | void setTextureMirroring(QQuickShaderEffectSource::TextureMirroring mirroring); |
192 | |
193 | int samples() const { return m_samples; } |
194 | void setSamples(int count); |
195 | |
196 | QQuickShaderEffectSource *effectSource() const { return m_effectSource; } |
197 | |
198 | void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override; |
199 | void itemOpacityChanged(QQuickItem *) override; |
200 | void itemParentChanged(QQuickItem *, QQuickItem *) override; |
201 | void itemSiblingOrderChanged(QQuickItem *) override; |
202 | void itemVisibilityChanged(QQuickItem *) override; |
203 | |
204 | void updateMatrix(); |
205 | void updateGeometry(); |
206 | void updateOpacity(); |
207 | void updateZ(); |
208 | |
209 | Q_SIGNALS: |
210 | void enabledChanged(bool enabled); |
211 | void sizeChanged(const QSize &size); |
212 | void mipmapChanged(bool mipmap); |
213 | void wrapModeChanged(QQuickShaderEffectSource::WrapMode mode); |
214 | void nameChanged(const QByteArray &name); |
215 | void effectChanged(QQmlComponent *component); |
216 | void smoothChanged(bool smooth); |
217 | void formatChanged(QQuickShaderEffectSource::Format format); |
218 | void sourceRectChanged(const QRectF &sourceRect); |
219 | void textureMirroringChanged(QQuickShaderEffectSource::TextureMirroring mirroring); |
220 | void samplesChanged(int count); |
221 | |
222 | private: |
223 | friend class QQuickTransformAnimatorJob; |
224 | friend class QQuickOpacityAnimatorJob; |
225 | |
226 | void activate(); |
227 | void deactivate(); |
228 | void activateEffect(); |
229 | void deactivateEffect(); |
230 | |
231 | QQuickItem *m_item; |
232 | bool m_enabled; |
233 | bool m_mipmap; |
234 | bool m_smooth; |
235 | bool m_componentComplete; |
236 | QQuickShaderEffectSource::WrapMode m_wrapMode; |
237 | QQuickShaderEffectSource::Format m_format; |
238 | QSize m_size; |
239 | QRectF m_sourceRect; |
240 | QByteArray m_name; |
241 | QQmlComponent *m_effectComponent; |
242 | QQuickItem *m_effect; |
243 | QQuickShaderEffectSource *m_effectSource; |
244 | QQuickShaderEffectSource::TextureMirroring m_textureMirroring; |
245 | int m_samples; |
246 | }; |
247 | |
248 | #endif |
249 | |
250 | class Q_QUICK_PRIVATE_EXPORT QQuickItemPrivate : public QObjectPrivate |
251 | { |
252 | Q_DECLARE_PUBLIC(QQuickItem) |
253 | |
254 | public: |
255 | static QQuickItemPrivate* get(QQuickItem *item) { return item->d_func(); } |
256 | static const QQuickItemPrivate* get(const QQuickItem *item) { return item->d_func(); } |
257 | |
258 | QQuickItemPrivate(); |
259 | ~QQuickItemPrivate() override; |
260 | void init(QQuickItem *parent); |
261 | |
262 | QQmlListProperty<QObject> data(); |
263 | QQmlListProperty<QObject> resources(); |
264 | QQmlListProperty<QQuickItem> children(); |
265 | QQmlListProperty<QQuickItem> visibleChildren(); |
266 | |
267 | QQmlListProperty<QQuickState> states(); |
268 | QQmlListProperty<QQuickTransition> transitions(); |
269 | |
270 | QString state() const; |
271 | void setState(const QString &); |
272 | |
273 | QQuickAnchorLine left() const; |
274 | QQuickAnchorLine right() const; |
275 | QQuickAnchorLine horizontalCenter() const; |
276 | QQuickAnchorLine top() const; |
277 | QQuickAnchorLine bottom() const; |
278 | QQuickAnchorLine verticalCenter() const; |
279 | QQuickAnchorLine baseline() const; |
280 | |
281 | QQuickItemLayer *layer() const; |
282 | |
283 | bool hasPointerHandlers() const; |
284 | bool hasHoverHandlers() const; |
285 | virtual void addPointerHandler(QQuickPointerHandler *h); |
286 | |
287 | // data property |
288 | static void data_append(QQmlListProperty<QObject> *, QObject *); |
289 | static int data_count(QQmlListProperty<QObject> *); |
290 | static QObject *data_at(QQmlListProperty<QObject> *, int); |
291 | static void data_clear(QQmlListProperty<QObject> *); |
292 | |
293 | // resources property |
294 | static QObject *resources_at(QQmlListProperty<QObject> *, int); |
295 | static void resources_append(QQmlListProperty<QObject> *, QObject *); |
296 | static int resources_count(QQmlListProperty<QObject> *); |
297 | static void resources_clear(QQmlListProperty<QObject> *); |
298 | |
299 | // children property |
300 | static void children_append(QQmlListProperty<QQuickItem> *, QQuickItem *); |
301 | static int children_count(QQmlListProperty<QQuickItem> *); |
302 | static QQuickItem *children_at(QQmlListProperty<QQuickItem> *, int); |
303 | static void children_clear(QQmlListProperty<QQuickItem> *); |
304 | |
305 | // visibleChildren property |
306 | static void visibleChildren_append(QQmlListProperty<QQuickItem> *prop, QQuickItem *o); |
307 | static int visibleChildren_count(QQmlListProperty<QQuickItem> *prop); |
308 | static QQuickItem *visibleChildren_at(QQmlListProperty<QQuickItem> *prop, int index); |
309 | |
310 | // transform property |
311 | static int transform_count(QQmlListProperty<QQuickTransform> *list); |
312 | static void transform_append(QQmlListProperty<QQuickTransform> *list, QQuickTransform *); |
313 | static QQuickTransform *transform_at(QQmlListProperty<QQuickTransform> *list, int); |
314 | static void transform_clear(QQmlListProperty<QQuickTransform> *list); |
315 | |
316 | void _q_resourceObjectDeleted(QObject *); |
317 | quint64 _q_createJSWrapper(QV4::ExecutionEngine *engine); |
318 | |
319 | enum ChangeType { |
320 | Geometry = 0x01, |
321 | SiblingOrder = 0x02, |
322 | Visibility = 0x04, |
323 | Opacity = 0x08, |
324 | Destroyed = 0x10, |
325 | Parent = 0x20, |
326 | Children = 0x40, |
327 | Rotation = 0x80, |
328 | ImplicitWidth = 0x100, |
329 | ImplicitHeight = 0x200, |
330 | Enabled = 0x400, |
331 | }; |
332 | |
333 | Q_DECLARE_FLAGS(ChangeTypes, ChangeType) |
334 | |
335 | struct ChangeListener { |
336 | using ChangeTypes = QQuickItemPrivate::ChangeTypes; |
337 | |
338 | ChangeListener(QQuickItemChangeListener *l = nullptr, ChangeTypes t = nullptr) |
339 | : listener(l) |
340 | , types(t) |
341 | , gTypes(QQuickGeometryChange::All) |
342 | {} |
343 | |
344 | ChangeListener(QQuickItemChangeListener *l, QQuickGeometryChange gt) |
345 | : listener(l) |
346 | , types(Geometry) |
347 | , gTypes(gt) |
348 | {} |
349 | |
350 | bool operator==(const ChangeListener &other) const |
351 | { return listener == other.listener && types == other.types; } |
352 | |
353 | QQuickItemChangeListener *listener; |
354 | ChangeTypes types; |
355 | QQuickGeometryChange gTypes; //NOTE: not used for == |
356 | }; |
357 | |
358 | struct { |
359 | (); |
360 | |
361 | qreal ; |
362 | qreal ; |
363 | qreal ; |
364 | qreal ; |
365 | |
366 | QQuickContents *; |
367 | QQuickScreenAttached *; |
368 | QQuickLayoutMirroringAttached* ; |
369 | QQuickEnterKeyAttached *; |
370 | QQuickItemKeyFilter *keyHandler; |
371 | QVector<QQuickPointerHandler *> pointerHandlers; |
372 | #if QT_CONFIG(quick_shadereffect) |
373 | mutable QQuickItemLayer *; |
374 | #endif |
375 | #if QT_CONFIG(cursor) |
376 | QCursor ; |
377 | #endif |
378 | QPointF ; |
379 | |
380 | // these do not include child items |
381 | int ; |
382 | int ; |
383 | // updated recursively for child items as well |
384 | int ; |
385 | |
386 | QSGOpacityNode *; |
387 | QQuickDefaultClipNode *; |
388 | QSGRootNode *; |
389 | |
390 | // Mask contains() method |
391 | QMetaMethod ; |
392 | |
393 | QObjectList ; |
394 | |
395 | // Although acceptedMouseButtons is inside ExtraData, we actually store |
396 | // the LeftButton flag in the extra.flag() bit. This is because it is |
397 | // extremely common to set acceptedMouseButtons to LeftButton, but very |
398 | // rare to use any of the other buttons. |
399 | Qt::MouseButtons ; |
400 | |
401 | QQuickItem::TransformOrigin :5; |
402 | uint : 1; |
403 | |
404 | // 26 bits padding |
405 | }; |
406 | QLazilyAllocated<ExtraData> ; |
407 | // Contains mask |
408 | QPointer<QObject> mask; |
409 | // If the mask is an Item, inform it that it's being used as a mask (true) or is no longer being used (false) |
410 | virtual void registerAsContainmentMask(QQuickItem * /* maskedItem */, bool /* set */) { } |
411 | |
412 | QQuickAnchors *anchors() const; |
413 | mutable QQuickAnchors *_anchors; |
414 | |
415 | inline Qt::MouseButtons acceptedMouseButtons() const; |
416 | |
417 | QVector<QQuickItemPrivate::ChangeListener> changeListeners; |
418 | |
419 | void addItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types); |
420 | void updateOrAddItemChangeListener(QQuickItemChangeListener *listener, ChangeTypes types); |
421 | void removeItemChangeListener(QQuickItemChangeListener *, ChangeTypes types); |
422 | void updateOrAddGeometryChangeListener(QQuickItemChangeListener *listener, QQuickGeometryChange types); |
423 | void updateOrRemoveGeometryChangeListener(QQuickItemChangeListener *listener, QQuickGeometryChange types); |
424 | |
425 | QQuickStateGroup *_states(); |
426 | QQuickStateGroup *_stateGroup; |
427 | |
428 | inline QQuickItem::TransformOrigin origin() const; |
429 | |
430 | // Bit 0 |
431 | quint32 flags:5; |
432 | bool widthValid:1; |
433 | bool heightValid:1; |
434 | bool componentComplete:1; |
435 | bool keepMouse:1; |
436 | bool keepTouch:1; |
437 | bool hoverEnabled:1; |
438 | bool smooth:1; |
439 | bool antialiasing:1; |
440 | bool focus:1; |
441 | bool activeFocus:1; |
442 | bool notifiedFocus:1; |
443 | // Bit 16 |
444 | bool notifiedActiveFocus:1; |
445 | bool filtersChildMouseEvents:1; |
446 | bool explicitVisible:1; |
447 | bool effectiveVisible:1; |
448 | bool explicitEnable:1; |
449 | bool effectiveEnable:1; |
450 | bool polishScheduled:1; |
451 | bool inheritedLayoutMirror:1; |
452 | bool effectiveLayoutMirror:1; |
453 | bool isMirrorImplicit:1; |
454 | bool inheritMirrorFromParent:1; |
455 | bool inheritMirrorFromItem:1; |
456 | bool isAccessible:1; |
457 | bool culled:1; |
458 | bool hasCursor:1; |
459 | bool subtreeCursorEnabled:1; |
460 | // Bit 32 |
461 | bool subtreeHoverEnabled:1; |
462 | bool activeFocusOnTab:1; |
463 | bool implicitAntialiasing:1; |
464 | bool antialiasingValid:1; |
465 | // isTabFence: When true, the item acts as a fence within the tab focus chain. |
466 | // This means that the item and its children will be skipped from the tab focus |
467 | // chain when navigating from its parent or any of its siblings. Similarly, |
468 | // when any of the item's descendants gets focus, the item constrains the tab |
469 | // focus chain and prevents tabbing outside. |
470 | bool isTabFence:1; |
471 | bool replayingPressEvent:1; |
472 | bool touchEnabled:1; |
473 | |
474 | enum DirtyType { |
475 | TransformOrigin = 0x00000001, |
476 | Transform = 0x00000002, |
477 | BasicTransform = 0x00000004, |
478 | Position = 0x00000008, |
479 | Size = 0x00000010, |
480 | |
481 | ZValue = 0x00000020, |
482 | Content = 0x00000040, |
483 | Smooth = 0x00000080, |
484 | OpacityValue = 0x00000100, |
485 | ChildrenChanged = 0x00000200, |
486 | ChildrenStackingChanged = 0x00000400, |
487 | ParentChanged = 0x00000800, |
488 | |
489 | Clip = 0x00001000, |
490 | Window = 0x00002000, |
491 | |
492 | EffectReference = 0x00008000, |
493 | Visible = 0x00010000, |
494 | HideReference = 0x00020000, |
495 | Antialiasing = 0x00040000, |
496 | // When you add an attribute here, don't forget to update |
497 | // dirtyToString() |
498 | |
499 | TransformUpdateMask = TransformOrigin | Transform | BasicTransform | Position | |
500 | Window, |
501 | = Transform | Window, |
502 | ContentUpdateMask = Size | Content | Smooth | Window | Antialiasing, |
503 | ChildrenUpdateMask = ChildrenChanged | ChildrenStackingChanged | EffectReference | Window |
504 | }; |
505 | |
506 | quint32 dirtyAttributes; |
507 | QString dirtyToString() const; |
508 | void dirty(DirtyType); |
509 | void addToDirtyList(); |
510 | void removeFromDirtyList(); |
511 | QQuickItem *nextDirtyItem; |
512 | QQuickItem**prevDirtyItem; |
513 | |
514 | void setCulled(bool); |
515 | |
516 | QQuickWindow *window; |
517 | int windowRefCount; |
518 | inline QSGContext *sceneGraphContext() const; |
519 | inline QSGRenderContext *sceneGraphRenderContext() const; |
520 | |
521 | QQuickItem *parentItem; |
522 | |
523 | QList<QQuickItem *> childItems; |
524 | mutable QList<QQuickItem *> *sortedChildItems; |
525 | QList<QQuickItem *> paintOrderChildItems() const; |
526 | void addChild(QQuickItem *); |
527 | void removeChild(QQuickItem *); |
528 | void siblingOrderChanged(); |
529 | |
530 | inline void markSortedChildrenDirty(QQuickItem *child); |
531 | |
532 | void refWindow(QQuickWindow *); |
533 | void derefWindow(); |
534 | |
535 | QQuickItem *subFocusItem; |
536 | void updateSubFocusItem(QQuickItem *scope, bool focus); |
537 | |
538 | QTransform windowToItemTransform() const; |
539 | QTransform itemToWindowTransform() const; |
540 | void itemToParentTransform(QTransform &) const; |
541 | QTransform globalToWindowTransform() const; |
542 | QTransform windowToGlobalTransform() const; |
543 | |
544 | static bool focusNextPrev(QQuickItem *item, bool forward); |
545 | static QQuickItem *nextTabChildItem(const QQuickItem *item, int start); |
546 | static QQuickItem *prevTabChildItem(const QQuickItem *item, int start); |
547 | static QQuickItem *nextPrevItemInTabFocusChain(QQuickItem *item, bool forward); |
548 | |
549 | static bool canAcceptTabFocus(QQuickItem *item); |
550 | |
551 | qreal x; |
552 | qreal y; |
553 | qreal width; |
554 | qreal height; |
555 | qreal implicitWidth; |
556 | qreal implicitHeight; |
557 | |
558 | qreal baselineOffset; |
559 | |
560 | QList<QQuickTransform *> transforms; |
561 | |
562 | inline qreal z() const { return extra.isAllocated()?extra->z:0; } |
563 | inline qreal scale() const { return extra.isAllocated()?extra->scale:1; } |
564 | inline qreal rotation() const { return extra.isAllocated()?extra->rotation:0; } |
565 | inline qreal opacity() const { return extra.isAllocated()?extra->opacity:1; } |
566 | |
567 | void setAccessible(); |
568 | |
569 | virtual qreal getImplicitWidth() const; |
570 | virtual qreal getImplicitHeight() const; |
571 | virtual void implicitWidthChanged(); |
572 | virtual void implicitHeightChanged(); |
573 | |
574 | #if QT_CONFIG(accessibility) |
575 | virtual QAccessible::Role accessibleRole() const; |
576 | #endif |
577 | |
578 | void setImplicitAntialiasing(bool antialiasing); |
579 | |
580 | void resolveLayoutMirror(); |
581 | void setImplicitLayoutMirror(bool mirror, bool inherit); |
582 | void setLayoutMirror(bool mirror); |
583 | bool isMirrored() const { |
584 | return effectiveLayoutMirror; |
585 | } |
586 | |
587 | void emitChildrenRectChanged(const QRectF &rect) { |
588 | Q_Q(QQuickItem); |
589 | Q_EMIT q->childrenRectChanged(rect); |
590 | } |
591 | |
592 | QPointF computeTransformOrigin() const; |
593 | virtual void transformChanged(); |
594 | |
595 | QPointF adjustedPosForTransform(const QPointF ¢roid, |
596 | const QPointF &startPos, const QVector2D &activeTranslatation, |
597 | qreal startScale, qreal activeScale, |
598 | qreal startRotation, qreal activeRotation); |
599 | |
600 | void deliverKeyEvent(QKeyEvent *); |
601 | bool filterKeyEvent(QKeyEvent *, bool post); |
602 | #if QT_CONFIG(im) |
603 | void deliverInputMethodEvent(QInputMethodEvent *); |
604 | #endif |
605 | void deliverShortcutOverrideEvent(QKeyEvent *); |
606 | |
607 | bool anyPointerHandlerWants(QQuickEventPoint *point) const; |
608 | virtual bool handlePointerEvent(QQuickPointerEvent *, bool avoidExclusiveGrabber = false); |
609 | |
610 | virtual void setVisible(bool visible); |
611 | |
612 | bool isTransparentForPositioner() const; |
613 | void setTransparentForPositioner(bool trans); |
614 | |
615 | bool calcEffectiveVisible() const; |
616 | bool setEffectiveVisibleRecur(bool); |
617 | bool calcEffectiveEnable() const; |
618 | void setEffectiveEnableRecur(QQuickItem *scope, bool); |
619 | |
620 | |
621 | inline QSGTransformNode *itemNode(); |
622 | inline QSGNode *childContainerNode(); |
623 | |
624 | /* |
625 | QSGNode order is: |
626 | - itemNode |
627 | - (opacityNode) |
628 | - (clipNode) |
629 | - (rootNode) (shader effect source's root node) |
630 | */ |
631 | |
632 | QSGOpacityNode *opacityNode() const { return extra.isAllocated()?extra->opacityNode:nullptr; } |
633 | QQuickDefaultClipNode *clipNode() const { return extra.isAllocated()?extra->clipNode:nullptr; } |
634 | QSGRootNode *rootNode() const { return extra.isAllocated()?extra->rootNode:nullptr; } |
635 | |
636 | QSGTransformNode *itemNodeInstance; |
637 | QSGNode *paintNode; |
638 | |
639 | virtual QSGTransformNode *createTransformNode(); |
640 | |
641 | // A reference from an effect item means that this item is used by the effect, so |
642 | // it should insert a root node. |
643 | void refFromEffectItem(bool hide); |
644 | void recursiveRefFromEffectItem(int refs); |
645 | void derefFromEffectItem(bool unhide); |
646 | |
647 | void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &); |
648 | |
649 | virtual void mirrorChange() {} |
650 | |
651 | void setHasCursorInChild(bool hasCursor); |
652 | void setHasHoverInChild(bool hasHover); |
653 | |
654 | virtual void updatePolish() { } |
655 | }; |
656 | |
657 | /* |
658 | Key filters can be installed on a QQuickItem, but not removed. Currently they |
659 | are only used by attached objects (which are only destroyed on Item |
660 | destruction), so this isn't a problem. If in future this becomes any form |
661 | of public API, they will have to support removal too. |
662 | */ |
663 | class QQuickItemKeyFilter |
664 | { |
665 | public: |
666 | QQuickItemKeyFilter(QQuickItem * = nullptr); |
667 | virtual ~QQuickItemKeyFilter(); |
668 | |
669 | virtual void keyPressed(QKeyEvent *event, bool post); |
670 | virtual void keyReleased(QKeyEvent *event, bool post); |
671 | #if QT_CONFIG(im) |
672 | virtual void inputMethodEvent(QInputMethodEvent *event, bool post); |
673 | virtual QVariant inputMethodQuery(Qt::InputMethodQuery query) const; |
674 | #endif |
675 | virtual void shortcutOverride(QKeyEvent *event); |
676 | virtual void componentComplete(); |
677 | |
678 | bool m_processPost; |
679 | |
680 | private: |
681 | QQuickItemKeyFilter *m_next; |
682 | }; |
683 | |
684 | class QQuickKeyNavigationAttachedPrivate : public QObjectPrivate |
685 | { |
686 | public: |
687 | QQuickKeyNavigationAttachedPrivate() |
688 | : leftSet(false), rightSet(false), upSet(false), downSet(false), |
689 | tabSet(false), backtabSet(false) {} |
690 | |
691 | QPointer<QQuickItem> left; |
692 | QPointer<QQuickItem> right; |
693 | QPointer<QQuickItem> up; |
694 | QPointer<QQuickItem> down; |
695 | QPointer<QQuickItem> tab; |
696 | QPointer<QQuickItem> backtab; |
697 | bool leftSet : 1; |
698 | bool rightSet : 1; |
699 | bool upSet : 1; |
700 | bool downSet : 1; |
701 | bool tabSet : 1; |
702 | bool backtabSet : 1; |
703 | }; |
704 | |
705 | class Q_QUICK_PRIVATE_EXPORT QQuickKeyNavigationAttached : public QObject, public QQuickItemKeyFilter |
706 | { |
707 | Q_OBJECT |
708 | Q_DECLARE_PRIVATE(QQuickKeyNavigationAttached) |
709 | |
710 | Q_PROPERTY(QQuickItem *left READ left WRITE setLeft NOTIFY leftChanged) |
711 | Q_PROPERTY(QQuickItem *right READ right WRITE setRight NOTIFY rightChanged) |
712 | Q_PROPERTY(QQuickItem *up READ up WRITE setUp NOTIFY upChanged) |
713 | Q_PROPERTY(QQuickItem *down READ down WRITE setDown NOTIFY downChanged) |
714 | Q_PROPERTY(QQuickItem *tab READ tab WRITE setTab NOTIFY tabChanged) |
715 | Q_PROPERTY(QQuickItem *backtab READ backtab WRITE setBacktab NOTIFY backtabChanged) |
716 | Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged) |
717 | |
718 | public: |
719 | QQuickKeyNavigationAttached(QObject * = nullptr); |
720 | |
721 | QQuickItem *left() const; |
722 | void setLeft(QQuickItem *); |
723 | QQuickItem *right() const; |
724 | void setRight(QQuickItem *); |
725 | QQuickItem *up() const; |
726 | void setUp(QQuickItem *); |
727 | QQuickItem *down() const; |
728 | void setDown(QQuickItem *); |
729 | QQuickItem *tab() const; |
730 | void setTab(QQuickItem *); |
731 | QQuickItem *backtab() const; |
732 | void setBacktab(QQuickItem *); |
733 | |
734 | enum Priority { BeforeItem, AfterItem }; |
735 | Q_ENUM(Priority) |
736 | Priority priority() const; |
737 | void setPriority(Priority); |
738 | |
739 | static QQuickKeyNavigationAttached *qmlAttachedProperties(QObject *); |
740 | |
741 | Q_SIGNALS: |
742 | void leftChanged(); |
743 | void rightChanged(); |
744 | void upChanged(); |
745 | void downChanged(); |
746 | void tabChanged(); |
747 | void backtabChanged(); |
748 | void priorityChanged(); |
749 | |
750 | private: |
751 | void keyPressed(QKeyEvent *event, bool post) override; |
752 | void keyReleased(QKeyEvent *event, bool post) override; |
753 | void setFocusNavigation(QQuickItem *currentItem, const char *dir, |
754 | Qt::FocusReason reason = Qt::OtherFocusReason); |
755 | }; |
756 | |
757 | class QQuickLayoutMirroringAttached : public QObject |
758 | { |
759 | Q_OBJECT |
760 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled RESET resetEnabled NOTIFY enabledChanged) |
761 | Q_PROPERTY(bool childrenInherit READ childrenInherit WRITE setChildrenInherit NOTIFY childrenInheritChanged) |
762 | |
763 | public: |
764 | explicit QQuickLayoutMirroringAttached(QObject *parent = nullptr); |
765 | |
766 | bool enabled() const; |
767 | void setEnabled(bool); |
768 | void resetEnabled(); |
769 | |
770 | bool childrenInherit() const; |
771 | void setChildrenInherit(bool); |
772 | |
773 | static QQuickLayoutMirroringAttached *qmlAttachedProperties(QObject *); |
774 | Q_SIGNALS: |
775 | void enabledChanged(); |
776 | void childrenInheritChanged(); |
777 | private: |
778 | friend class QQuickItemPrivate; |
779 | QQuickItemPrivate *itemPrivate; |
780 | }; |
781 | |
782 | class QQuickEnterKeyAttached : public QObject |
783 | { |
784 | Q_OBJECT |
785 | Q_PROPERTY(Qt::EnterKeyType type READ type WRITE setType NOTIFY typeChanged) |
786 | |
787 | public: |
788 | explicit QQuickEnterKeyAttached(QObject *parent = nullptr); |
789 | |
790 | Qt::EnterKeyType type() const; |
791 | void setType(Qt::EnterKeyType type); |
792 | |
793 | static QQuickEnterKeyAttached *qmlAttachedProperties(QObject *); |
794 | Q_SIGNALS: |
795 | void typeChanged(); |
796 | private: |
797 | friend class QQuickItemPrivate; |
798 | QQuickItemPrivate *itemPrivate; |
799 | |
800 | Qt::EnterKeyType keyType; |
801 | }; |
802 | |
803 | class QQuickKeysAttachedPrivate : public QObjectPrivate |
804 | { |
805 | public: |
806 | QQuickKeysAttachedPrivate() |
807 | : inPress(false), inRelease(false), inIM(false), enabled(true) |
808 | {} |
809 | |
810 | //loop detection |
811 | bool inPress:1; |
812 | bool inRelease:1; |
813 | bool inIM:1; |
814 | |
815 | bool enabled : 1; |
816 | |
817 | QQuickItem *imeItem = nullptr; |
818 | QList<QQuickItem *> targets; |
819 | QQuickItem *item = nullptr; |
820 | QQuickKeyEvent theKeyEvent; |
821 | }; |
822 | |
823 | class QQuickKeysAttached : public QObject, public QQuickItemKeyFilter |
824 | { |
825 | Q_OBJECT |
826 | Q_DECLARE_PRIVATE(QQuickKeysAttached) |
827 | |
828 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) |
829 | Q_PROPERTY(QQmlListProperty<QQuickItem> forwardTo READ forwardTo) |
830 | Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged) |
831 | |
832 | public: |
833 | QQuickKeysAttached(QObject *parent=nullptr); |
834 | ~QQuickKeysAttached() override; |
835 | |
836 | bool enabled() const { Q_D(const QQuickKeysAttached); return d->enabled; } |
837 | void setEnabled(bool enabled) { |
838 | Q_D(QQuickKeysAttached); |
839 | if (enabled != d->enabled) { |
840 | d->enabled = enabled; |
841 | Q_EMIT enabledChanged(); |
842 | } |
843 | } |
844 | |
845 | enum Priority { BeforeItem, AfterItem}; |
846 | Q_ENUM(Priority) |
847 | Priority priority() const; |
848 | void setPriority(Priority); |
849 | |
850 | QQmlListProperty<QQuickItem> forwardTo() { |
851 | Q_D(QQuickKeysAttached); |
852 | return QQmlListProperty<QQuickItem>(this, d->targets); |
853 | } |
854 | |
855 | void componentComplete() override; |
856 | |
857 | static QQuickKeysAttached *qmlAttachedProperties(QObject *); |
858 | |
859 | Q_SIGNALS: |
860 | void enabledChanged(); |
861 | void priorityChanged(); |
862 | void pressed(QQuickKeyEvent *event); |
863 | void released(QQuickKeyEvent *event); |
864 | void shortcutOverride(QQuickKeyEvent *event); |
865 | void digit0Pressed(QQuickKeyEvent *event); |
866 | void digit1Pressed(QQuickKeyEvent *event); |
867 | void digit2Pressed(QQuickKeyEvent *event); |
868 | void digit3Pressed(QQuickKeyEvent *event); |
869 | void digit4Pressed(QQuickKeyEvent *event); |
870 | void digit5Pressed(QQuickKeyEvent *event); |
871 | void digit6Pressed(QQuickKeyEvent *event); |
872 | void digit7Pressed(QQuickKeyEvent *event); |
873 | void digit8Pressed(QQuickKeyEvent *event); |
874 | void digit9Pressed(QQuickKeyEvent *event); |
875 | |
876 | void leftPressed(QQuickKeyEvent *event); |
877 | void rightPressed(QQuickKeyEvent *event); |
878 | void upPressed(QQuickKeyEvent *event); |
879 | void downPressed(QQuickKeyEvent *event); |
880 | void tabPressed(QQuickKeyEvent *event); |
881 | void backtabPressed(QQuickKeyEvent *event); |
882 | |
883 | void asteriskPressed(QQuickKeyEvent *event); |
884 | void numberSignPressed(QQuickKeyEvent *event); |
885 | void escapePressed(QQuickKeyEvent *event); |
886 | void returnPressed(QQuickKeyEvent *event); |
887 | void enterPressed(QQuickKeyEvent *event); |
888 | void deletePressed(QQuickKeyEvent *event); |
889 | void spacePressed(QQuickKeyEvent *event); |
890 | void backPressed(QQuickKeyEvent *event); |
891 | void cancelPressed(QQuickKeyEvent *event); |
892 | void selectPressed(QQuickKeyEvent *event); |
893 | void yesPressed(QQuickKeyEvent *event); |
894 | void noPressed(QQuickKeyEvent *event); |
895 | void context1Pressed(QQuickKeyEvent *event); |
896 | void context2Pressed(QQuickKeyEvent *event); |
897 | void context3Pressed(QQuickKeyEvent *event); |
898 | void context4Pressed(QQuickKeyEvent *event); |
899 | void callPressed(QQuickKeyEvent *event); |
900 | void hangupPressed(QQuickKeyEvent *event); |
901 | void flipPressed(QQuickKeyEvent *event); |
902 | void (QQuickKeyEvent *event); |
903 | void volumeUpPressed(QQuickKeyEvent *event); |
904 | void volumeDownPressed(QQuickKeyEvent *event); |
905 | |
906 | private: |
907 | void keyPressed(QKeyEvent *event, bool post) override; |
908 | void keyReleased(QKeyEvent *event, bool post) override; |
909 | #if QT_CONFIG(im) |
910 | void inputMethodEvent(QInputMethodEvent *, bool post) override; |
911 | QVariant inputMethodQuery(Qt::InputMethodQuery query) const override; |
912 | #endif |
913 | void shortcutOverride(QKeyEvent *event) override; |
914 | static QByteArray keyToSignal(int key); |
915 | |
916 | bool isConnected(const char *signalName) const; |
917 | }; |
918 | |
919 | Qt::MouseButtons QQuickItemPrivate::acceptedMouseButtons() const |
920 | { |
921 | return ((extra.flag() ? Qt::LeftButton : Qt::MouseButton(0)) | |
922 | (extra.isAllocated() ? extra->acceptedMouseButtons : Qt::MouseButtons(nullptr))); |
923 | } |
924 | |
925 | QSGContext *QQuickItemPrivate::sceneGraphContext() const |
926 | { |
927 | Q_ASSERT(window); |
928 | return static_cast<QQuickWindowPrivate *>(QObjectPrivate::get(window))->context->sceneGraphContext(); |
929 | } |
930 | |
931 | QSGRenderContext *QQuickItemPrivate::sceneGraphRenderContext() const |
932 | { |
933 | Q_ASSERT(window); |
934 | return static_cast<QQuickWindowPrivate *>(QObjectPrivate::get(window))->context; |
935 | } |
936 | |
937 | void QQuickItemPrivate::markSortedChildrenDirty(QQuickItem *child) |
938 | { |
939 | // If sortedChildItems == &childItems then all in childItems have z == 0 |
940 | // and we don't need to invalidate if the changed item also has z == 0. |
941 | if (child->z() != 0. || sortedChildItems != &childItems) { |
942 | if (sortedChildItems != &childItems) |
943 | delete sortedChildItems; |
944 | sortedChildItems = nullptr; |
945 | } |
946 | } |
947 | |
948 | QQuickItem::TransformOrigin QQuickItemPrivate::origin() const |
949 | { |
950 | return extra.isAllocated()?extra->origin:QQuickItem::Center; |
951 | } |
952 | |
953 | QSGTransformNode *QQuickItemPrivate::itemNode() |
954 | { |
955 | if (!itemNodeInstance) { |
956 | itemNodeInstance = createTransformNode(); |
957 | itemNodeInstance->setFlag(QSGNode::OwnedByParent, false); |
958 | #ifdef QSG_RUNTIME_DESCRIPTION |
959 | Q_Q(QQuickItem); |
960 | qsgnode_set_description(itemNodeInstance, QString::fromLatin1("QQuickItem(%1:%2)" ).arg(QString::fromLatin1(q->metaObject()->className())).arg(q->objectName())); |
961 | #endif |
962 | } |
963 | return itemNodeInstance; |
964 | } |
965 | |
966 | QSGNode *QQuickItemPrivate::childContainerNode() |
967 | { |
968 | if (rootNode()) |
969 | return rootNode(); |
970 | else if (clipNode()) |
971 | return clipNode(); |
972 | else if (opacityNode()) |
973 | return opacityNode(); |
974 | else |
975 | return itemNode(); |
976 | } |
977 | |
978 | Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickItemPrivate::ChangeTypes) |
979 | Q_DECLARE_TYPEINFO(QQuickItemPrivate::ChangeListener, Q_PRIMITIVE_TYPE); |
980 | |
981 | QT_END_NAMESPACE |
982 | |
983 | #if QT_CONFIG(quick_shadereffect) |
984 | QML_DECLARE_TYPE(QQuickItemLayer) |
985 | #endif |
986 | QML_DECLARE_TYPE(QQuickKeysAttached) |
987 | QML_DECLARE_TYPEINFO(QQuickKeysAttached, QML_HAS_ATTACHED_PROPERTIES) |
988 | QML_DECLARE_TYPE(QQuickKeyNavigationAttached) |
989 | QML_DECLARE_TYPEINFO(QQuickKeyNavigationAttached, QML_HAS_ATTACHED_PROPERTIES) |
990 | QML_DECLARE_TYPE(QQuickLayoutMirroringAttached) |
991 | QML_DECLARE_TYPEINFO(QQuickLayoutMirroringAttached, QML_HAS_ATTACHED_PROPERTIES) |
992 | QML_DECLARE_TYPE(QQuickEnterKeyAttached) |
993 | QML_DECLARE_TYPEINFO(QQuickEnterKeyAttached, QML_HAS_ATTACHED_PROPERTIES) |
994 | |
995 | #endif // QQUICKITEM_P_H |
996 | |