core/window: add QsWindow attached object to contained Items

This commit is contained in:
outfoxxed 2024-07-17 20:54:29 -07:00
parent d1c33d48cd
commit e48af44607
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 75 additions and 1 deletions

View file

@ -13,7 +13,15 @@
#include "reload.hpp"
class ProxyWindowBase;
class QsWindowAttached;
///! Base class of Quickshell windows
/// Base class of Quickshell windows
/// ### Attached properties
/// `QSWindow` can be used as an attached object of anything that subclasses @@QtQuick.Item$.
/// It provides the following properties
/// - `window` - the `QSWindow` object.
/// - `contentItem` - the `contentItem` property of the window.
class WindowInterface: public Reloadable {
Q_OBJECT;
// clang-format off
@ -101,6 +109,7 @@ class WindowInterface: public Reloadable {
Q_CLASSINFO("DefaultProperty", "data");
QML_NAMED_ELEMENT(QSWindow);
QML_UNCREATABLE("uncreatable base class");
QML_ATTACHED(QsWindowAttached);
public:
explicit WindowInterface(QObject* parent = nullptr): Reloadable(parent) {}
@ -131,6 +140,8 @@ public:
[[nodiscard]] virtual QQmlListProperty<QObject> data() = 0;
static QsWindowAttached* qmlAttachedProperties(QObject* object);
signals:
void windowConnected();
void visibleChanged();
@ -142,3 +153,17 @@ signals:
void colorChanged();
void maskChanged();
};
class QsWindowAttached: public QObject {
Q_OBJECT;
Q_PROPERTY(QObject* window READ window CONSTANT);
Q_PROPERTY(QQuickItem* contentItem READ contentItem CONSTANT);
QML_ANONYMOUS;
public:
[[nodiscard]] virtual QObject* window() const = 0;
[[nodiscard]] virtual QQuickItem* contentItem() const = 0;
protected:
explicit QsWindowAttached(QObject* parent): QObject(parent) {}
};