File indexing completed on 2024-04-21 03:56:01

0001 /*
0002  *  SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #ifndef SCENEPOSITIONATTACHED_H
0008 #define SCENEPOSITIONATTACHED_H
0009 
0010 #include <QObject>
0011 #include <QQmlEngine>
0012 
0013 class QQuickItem;
0014 
0015 /**
0016  * This attached property contains the information about the scene position of the item:
0017  * Its global x and y coordinates will update automatically and can be binded
0018  * @code
0019  * import org.kde.kirigami 2.5 as Kirigami
0020  * Text {
0021  *    text: ScenePosition.x
0022  * }
0023  * @endcode
0024  * @since 2.3
0025  */
0026 class ScenePositionAttached : public QObject
0027 {
0028     Q_OBJECT
0029     QML_ELEMENT
0030     QML_ATTACHED(ScenePositionAttached)
0031     QML_NAMED_ELEMENT(ScenePosition)
0032     QML_UNCREATABLE("")
0033     /**
0034      * The global scene X position
0035      */
0036     Q_PROPERTY(qreal x READ x NOTIFY xChanged FINAL)
0037 
0038     /**
0039      * The global scene Y position
0040      */
0041     Q_PROPERTY(qreal y READ y NOTIFY yChanged FINAL)
0042 
0043 public:
0044     explicit ScenePositionAttached(QObject *parent = nullptr);
0045     ~ScenePositionAttached() override;
0046 
0047     qreal x() const;
0048     qreal y() const;
0049 
0050     // QML attached property
0051     static ScenePositionAttached *qmlAttachedProperties(QObject *object);
0052 
0053 Q_SIGNALS:
0054     void xChanged();
0055     void yChanged();
0056 
0057 private:
0058     void connectAncestors(QQuickItem *item);
0059 
0060     QQuickItem *m_item = nullptr;
0061     QList<QQuickItem *> m_ancestors;
0062 };
0063 
0064 QML_DECLARE_TYPEINFO(ScenePositionAttached, QML_HAS_ATTACHED_PROPERTIES)
0065 
0066 #endif // SCENEPOSITIONATTACHED_H