| 1 | // Copyright (C) 2024 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 QQUICKSAFEAREA_P_H |
| 5 | #define QQUICKSAFEAREA_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 <QtQml/qqml.h> |
| 19 | |
| 20 | #include <QtQuick/private/qtquickglobal_p.h> |
| 21 | #include <QtQuick/qquickitem.h> |
| 22 | #include <QtQuick/private/qquickitemchangelistener_p.h> |
| 23 | |
| 24 | QT_BEGIN_NAMESPACE |
| 25 | |
| 26 | class QQuickAnchorLine; |
| 27 | class QQuickItem; |
| 28 | class QQuickControl; |
| 29 | |
| 30 | class Q_QUICK_EXPORT QQuickSafeArea : public QObject, public QQuickItemChangeListener |
| 31 | { |
| 32 | Q_OBJECT |
| 33 | |
| 34 | Q_PROPERTY(QMarginsF margins READ margins NOTIFY marginsChanged FINAL) |
| 35 | Q_PROPERTY(QMarginsF additionalMargins READ additionalMargins WRITE setAdditionalMargins NOTIFY additionalMarginsChanged FINAL) |
| 36 | |
| 37 | QML_NAMED_ELEMENT(SafeArea) |
| 38 | QML_ADDED_IN_VERSION(6, 9) |
| 39 | QML_ATTACHED(QQuickSafeArea) |
| 40 | QML_UNCREATABLE("SafeArea can only be used via the attached property." ) |
| 41 | |
| 42 | public: |
| 43 | QQuickSafeArea(QQuickItem *attachee = nullptr); |
| 44 | ~QQuickSafeArea(); |
| 45 | |
| 46 | static QQuickSafeArea *qmlAttachedProperties(QObject *attachee); |
| 47 | |
| 48 | QMarginsF margins() const; |
| 49 | |
| 50 | QMarginsF additionalMargins() const; |
| 51 | void setAdditionalMargins(const QMarginsF &additionalMargins); |
| 52 | |
| 53 | static void updateSafeAreasRecursively(QQuickItem *fromItem); |
| 54 | |
| 55 | Q_SIGNALS: |
| 56 | void marginsChanged(); |
| 57 | void additionalMarginsChanged(); |
| 58 | |
| 59 | private: |
| 60 | void windowChanged(); |
| 61 | void updateSafeArea(); |
| 62 | |
| 63 | void itemTransformChanged(QQuickItem *, QQuickItem *) override; |
| 64 | void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override; |
| 65 | |
| 66 | #ifndef QT_NO_DEBUG_STREAM |
| 67 | friend Q_QUICK_EXPORT QDebug operator<<(QDebug debug, const QQuickSafeArea *safeArea); |
| 68 | #endif |
| 69 | |
| 70 | QMarginsF m_safeAreaMargins; |
| 71 | QMarginsF m_additionalMargins; |
| 72 | bool emittingMarginsUpdate = false; |
| 73 | bool detectedPossibleBindingLoop = false; |
| 74 | |
| 75 | void addSourceItem(QQuickItem *item) override; |
| 76 | void removeSourceItem(QQuickItem *item) override; |
| 77 | QList<QPointer<QQuickItem>> m_listenedItems; |
| 78 | |
| 79 | friend class QQuickItem; |
| 80 | friend class QQuickControl; |
| 81 | }; |
| 82 | |
| 83 | class Q_QUICK_EXPORT QQuickSafeAreaAttachable |
| 84 | { |
| 85 | public: |
| 86 | virtual ~QQuickSafeAreaAttachable(); |
| 87 | virtual QQuickItem *safeAreaAttachmentItem() = 0; |
| 88 | |
| 89 | private: |
| 90 | friend class QQuickSafeArea; |
| 91 | }; |
| 92 | |
| 93 | #define QQuickSafeAreaAttachable_iid "org.qt-project.Qt.QQuickSafeAreaAttachable" |
| 94 | Q_DECLARE_INTERFACE(QQuickSafeAreaAttachable, QQuickSafeAreaAttachable_iid) |
| 95 | |
| 96 | QT_END_NAMESPACE |
| 97 | |
| 98 | #endif // QQUICKSAFEAREA_P_H |
| 99 | |