1/*
2 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7#ifndef SCENEPOSITIONATTACHED_H
8#define SCENEPOSITIONATTACHED_H
9
10#include <QObject>
11#include <QQmlEngine>
12
13class QQuickItem;
14
15/**
16 * This attached property contains the information about the scene position of the item:
17 * Its global x and y coordinates will update automatically and can be binded
18 * @code
19 * import org.kde.kirigami 2.5 as Kirigami
20 * Text {
21 * text: ScenePosition.x
22 * }
23 * @endcode
24 * @since 2.3
25 */
26class ScenePositionAttached : public QObject
27{
28 Q_OBJECT
29 QML_ELEMENT
30 QML_ATTACHED(ScenePositionAttached)
31 QML_NAMED_ELEMENT(ScenePosition)
32 QML_UNCREATABLE("")
33 /**
34 * The global scene X position
35 */
36 Q_PROPERTY(qreal x READ x NOTIFY xChanged FINAL)
37
38 /**
39 * The global scene Y position
40 */
41 Q_PROPERTY(qreal y READ y NOTIFY yChanged FINAL)
42
43public:
44 explicit ScenePositionAttached(QObject *parent = nullptr);
45 ~ScenePositionAttached() override;
46
47 qreal x() const;
48 qreal y() const;
49
50 // QML attached property
51 static ScenePositionAttached *qmlAttachedProperties(QObject *object);
52
53Q_SIGNALS:
54 void xChanged();
55 void yChanged();
56
57private:
58 void connectAncestors(QQuickItem *item);
59
60 QQuickItem *m_item = nullptr;
61 QList<QQuickItem *> m_ancestors;
62};
63
64QML_DECLARE_TYPEINFO(ScenePositionAttached, QML_HAS_ATTACHED_PROPERTIES)
65
66#endif // SCENEPOSITIONATTACHED_H
67

source code of kirigami/src/scenepositionattached.h