1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKITEMCHANGELISTENER_P_H
5#define QQUICKITEMCHANGELISTENER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/private/qtquickglobal_p.h>
19
20QT_BEGIN_NAMESPACE
21
22class QRectF;
23class QQuickItem;
24class QQuickAnchorsPrivate;
25
26class QQuickGeometryChange
27{
28public:
29 enum Kind: int {
30 Nothing = 0x00,
31 X = 0x01,
32 Y = 0x02,
33 Width = 0x04,
34 Height = 0x08,
35
36 Size = Width | Height,
37 All = X | Y | Size
38 };
39
40 QQuickGeometryChange(int change = Nothing)
41 : kind(change)
42 {}
43
44 bool noChange() const { return kind == Nothing; }
45 bool anyChange() const { return !noChange(); }
46
47 bool xChange() const { return kind & X; }
48 bool yChange() const { return kind & Y; }
49 bool widthChange() const { return kind & Width; }
50 bool heightChange() const { return kind & Height; }
51
52 bool positionChange() const { return xChange() || yChange(); }
53 bool sizeChange() const { return widthChange() || heightChange(); }
54
55 bool horizontalChange() const { return xChange() || widthChange(); }
56 bool verticalChange() const { return yChange() || heightChange(); }
57
58 void setXChange(bool enabled) { set(bits: X, enabled); }
59 void setYChange(bool enabled) { set(bits: Y, enabled); }
60 void setWidthChange(bool enabled) { set(bits: Width, enabled); }
61 void setHeightChange(bool enabled) { set(bits: Height, enabled); }
62 void setSizeChange(bool enabled) { set(bits: Size, enabled); }
63 void setAllChanged(bool enabled) { set(bits: All, enabled); }
64 void setHorizontalChange(bool enabled) { set(bits: X | Width, enabled); }
65 void setVerticalChange(bool enabled) { set(bits: Y | Height, enabled); }
66
67 void set(int bits, bool enabled)
68 {
69 if (enabled) {
70 kind |= bits;
71 } else {
72 kind &= ~bits;
73 }
74 }
75
76 bool matches(QQuickGeometryChange other) const { return kind & other.kind; }
77
78private:
79 int kind;
80};
81
82#define QT_QUICK_NEW_GEOMETRY_CHANGED_HANDLING
83
84class Q_QUICK_PRIVATE_EXPORT QQuickItemChangeListener
85{
86public:
87 virtual ~QQuickItemChangeListener();
88
89 virtual void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF & /* oldGeometry */) {}
90 virtual void itemSiblingOrderChanged(QQuickItem *) {}
91 virtual void itemVisibilityChanged(QQuickItem *) {}
92 virtual void itemEnabledChanged(QQuickItem *) {}
93 virtual void itemOpacityChanged(QQuickItem *) {}
94 virtual void itemDestroyed(QQuickItem *) {}
95 virtual void itemChildAdded(QQuickItem *, QQuickItem * /* child */ ) {}
96 virtual void itemChildRemoved(QQuickItem *, QQuickItem * /* child */ ) {}
97 virtual void itemParentChanged(QQuickItem *, QQuickItem * /* parent */ ) {}
98 virtual void itemRotationChanged(QQuickItem *) {}
99 virtual void itemImplicitWidthChanged(QQuickItem *) {}
100 virtual void itemImplicitHeightChanged(QQuickItem *) {}
101 virtual void itemFocusChanged(QQuickItem *, Qt::FocusReason /* reason */) {}
102
103 virtual QQuickAnchorsPrivate *anchorPrivate() { return nullptr; }
104};
105
106QT_END_NAMESPACE
107
108#endif // QQUICKITEMCHANGELISTENER_P_H
109

source code of qtdeclarative/src/quick/items/qquickitemchangelistener_p.h