2024-02-01 09:29:45 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <qcolor.h>
|
2024-02-16 14:38:20 +00:00
|
|
|
#include <qcontainerfwd.h>
|
2024-02-04 12:58:58 +00:00
|
|
|
#include <qevent.h>
|
2024-02-17 05:17:05 +00:00
|
|
|
#include <qnamespace.h>
|
2024-02-01 09:29:45 +00:00
|
|
|
#include <qobject.h>
|
|
|
|
#include <qqmllist.h>
|
|
|
|
#include <qqmlparserstatus.h>
|
2024-02-01 10:40:05 +00:00
|
|
|
#include <qquickitem.h>
|
2024-02-01 09:29:45 +00:00
|
|
|
#include <qquickwindow.h>
|
|
|
|
#include <qtmetamacros.h>
|
|
|
|
#include <qtypes.h>
|
|
|
|
|
2024-02-13 14:11:00 +00:00
|
|
|
#include "region.hpp"
|
2024-02-16 14:38:20 +00:00
|
|
|
#include "reload.hpp"
|
2024-02-01 09:29:45 +00:00
|
|
|
|
|
|
|
// Proxy to an actual window exposing a limited property set with the ability to
|
|
|
|
// transfer it to a new window.
|
|
|
|
// Detaching a window and touching any property is a use after free.
|
|
|
|
//
|
|
|
|
// NOTE: setting an `id` in qml will point to the proxy window and not the real window so things
|
2024-02-01 10:40:05 +00:00
|
|
|
// like anchors must use `item`.
|
2024-02-16 14:38:20 +00:00
|
|
|
class ProxyWindowBase: public Reloadable {
|
2024-02-01 09:29:45 +00:00
|
|
|
Q_OBJECT;
|
2024-02-13 08:58:47 +00:00
|
|
|
/// The QtQuick window backing this window.
|
|
|
|
///
|
|
|
|
/// > [!WARNING] Do not expect values set via this property to work correctly.
|
|
|
|
/// > Values set this way will almost certainly misbehave across a reload, possibly
|
|
|
|
/// > even without one.
|
|
|
|
/// >
|
|
|
|
/// > Use **only** if you know what you are doing.
|
|
|
|
Q_PROPERTY(QQuickWindow* _backingWindow READ backingWindow);
|
2024-02-12 12:21:24 +00:00
|
|
|
/// The visibility of the window.
|
|
|
|
///
|
|
|
|
/// > [!INFO] Windows are not visible by default so you will need to set this to make the window
|
2024-02-13 14:11:00 +00:00
|
|
|
/// > appear.
|
2024-02-04 12:58:58 +00:00
|
|
|
Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged);
|
|
|
|
Q_PROPERTY(qint32 width READ width WRITE setWidth NOTIFY widthChanged);
|
|
|
|
Q_PROPERTY(qint32 height READ height WRITE setHeight NOTIFY heightChanged);
|
2024-02-12 12:21:24 +00:00
|
|
|
/// The background color of the window. Defaults to white.
|
|
|
|
///
|
|
|
|
/// > [!WARNING] This seems to behave weirdly when using transparent colors on some systems.
|
|
|
|
/// > Using a colored content item over a transparent window is the recommended way to work around this:
|
|
|
|
/// > ```qml
|
|
|
|
/// > ProxyWindow {
|
|
|
|
/// > Rectangle {
|
|
|
|
/// > anchors.fill: parent
|
|
|
|
/// > color: "#20ffffff"
|
|
|
|
/// >
|
|
|
|
/// > // your content here
|
|
|
|
/// > }
|
|
|
|
/// > }
|
|
|
|
/// > ```
|
2024-02-13 00:01:07 +00:00
|
|
|
Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged);
|
2024-02-13 14:11:00 +00:00
|
|
|
/// The clickthrough mask. Defaults to null.
|
|
|
|
///
|
|
|
|
/// If non null then the clickable areas of the window will be determined by the provided region.
|
|
|
|
///
|
|
|
|
/// ```qml
|
|
|
|
/// ProxyShellWindow {
|
|
|
|
/// // The mask region is set to `rect`, meaning only `rect` is clickable.
|
|
|
|
/// // All other clicks pass through the window to ones behind it.
|
|
|
|
/// mask: Region { item: rect }
|
|
|
|
///
|
|
|
|
/// Rectangle {
|
|
|
|
/// id: rect
|
|
|
|
///
|
|
|
|
/// anchors.centerIn: parent
|
|
|
|
/// width: 100
|
|
|
|
/// height: 100
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// If the provided region's intersection mode is `Combine` (the default),
|
|
|
|
/// then the region will be used as is. Otherwise it will be applied on top of the window region.
|
|
|
|
///
|
|
|
|
/// For example, setting the intersection mode to `Xor` will invert the mask and make everything in
|
|
|
|
/// the mask region not clickable and pass through clicks inside it through the window.
|
|
|
|
///
|
|
|
|
/// ```qml
|
|
|
|
/// ProxyShellWindow {
|
|
|
|
/// // The mask region is set to `rect`, but the intersection mode is set to `Xor`.
|
|
|
|
/// // This inverts the mask causing all clicks inside `rect` to be passed to the window
|
|
|
|
/// // behind this one.
|
|
|
|
/// mask: Region { item: rect; intersection: Intersection.Xor }
|
|
|
|
///
|
|
|
|
/// Rectangle {
|
|
|
|
/// id: rect
|
|
|
|
///
|
|
|
|
/// anchors.centerIn: parent
|
|
|
|
/// width: 100
|
|
|
|
/// height: 100
|
|
|
|
/// }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
Q_PROPERTY(PendingRegion* mask READ mask WRITE setMask NOTIFY maskChanged);
|
2024-02-01 09:29:45 +00:00
|
|
|
Q_PROPERTY(QQmlListProperty<QObject> data READ data);
|
|
|
|
Q_CLASSINFO("DefaultProperty", "data");
|
|
|
|
|
|
|
|
public:
|
2024-02-17 12:13:37 +00:00
|
|
|
explicit ProxyWindowBase(QObject* parent = nullptr);
|
2024-02-01 09:29:45 +00:00
|
|
|
~ProxyWindowBase() override;
|
|
|
|
|
|
|
|
ProxyWindowBase(ProxyWindowBase&) = delete;
|
|
|
|
ProxyWindowBase(ProxyWindowBase&&) = delete;
|
|
|
|
void operator=(ProxyWindowBase&) = delete;
|
|
|
|
void operator=(ProxyWindowBase&&) = delete;
|
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
void onReload(QObject* oldInstance) override;
|
|
|
|
|
|
|
|
virtual void setupWindow();
|
|
|
|
|
2024-02-01 09:29:45 +00:00
|
|
|
// Disown the backing window and delete all its children.
|
2024-02-04 12:58:58 +00:00
|
|
|
virtual QQuickWindow* disownWindow();
|
2024-02-01 09:29:45 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
[[nodiscard]] QQuickWindow* backingWindow() const;
|
2024-02-01 10:40:05 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
[[nodiscard]] virtual bool isVisible() const;
|
|
|
|
virtual void setVisible(bool visible);
|
2024-02-01 09:29:45 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
[[nodiscard]] virtual qint32 width() const;
|
|
|
|
virtual void setWidth(qint32 width);
|
2024-02-01 09:29:45 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
[[nodiscard]] virtual qint32 height() const;
|
|
|
|
virtual void setHeight(qint32 height);
|
2024-02-01 09:29:45 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
[[nodiscard]] QColor color() const;
|
|
|
|
void setColor(QColor color);
|
2024-02-01 09:29:45 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
[[nodiscard]] PendingRegion* mask() const;
|
2024-02-13 14:11:00 +00:00
|
|
|
void setMask(PendingRegion* mask);
|
|
|
|
|
2024-02-01 09:29:45 +00:00
|
|
|
QQmlListProperty<QObject> data();
|
|
|
|
|
2024-02-04 12:58:58 +00:00
|
|
|
signals:
|
2024-02-16 14:38:20 +00:00
|
|
|
void windowConnected();
|
|
|
|
void visibleChanged();
|
|
|
|
void widthChanged();
|
|
|
|
void heightChanged();
|
|
|
|
void colorChanged();
|
2024-02-13 14:11:00 +00:00
|
|
|
void maskChanged();
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onMaskChanged();
|
2024-02-17 12:13:37 +00:00
|
|
|
void onWidthChanged();
|
|
|
|
void onHeightChanged();
|
2024-02-04 12:58:58 +00:00
|
|
|
|
2024-02-16 14:38:20 +00:00
|
|
|
protected:
|
|
|
|
bool mVisible = false;
|
|
|
|
qint32 mWidth = 100;
|
|
|
|
qint32 mHeight = 100;
|
2024-02-17 05:17:05 +00:00
|
|
|
QColor mColor = Qt::white;
|
2024-02-16 14:38:20 +00:00
|
|
|
PendingRegion* mMask = nullptr;
|
|
|
|
QQuickWindow* window = nullptr;
|
2024-02-17 12:13:37 +00:00
|
|
|
QQuickItem* contentItem = nullptr;
|
2024-02-16 14:38:20 +00:00
|
|
|
|
2024-02-01 09:29:45 +00:00
|
|
|
private:
|
2024-02-16 14:38:20 +00:00
|
|
|
void updateMask();
|
2024-02-01 09:29:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// qt attempts to resize the window but fails because wayland
|
|
|
|
// and only resizes the graphics context which looks terrible.
|
|
|
|
class ProxyFloatingWindow: public ProxyWindowBase {
|
|
|
|
Q_OBJECT;
|
|
|
|
QML_ELEMENT;
|
|
|
|
|
|
|
|
public:
|
2024-02-16 14:38:20 +00:00
|
|
|
// Setting geometry while the window is visible makes the content item shrink but not the window
|
|
|
|
// which is awful so we disable it for floating windows.
|
|
|
|
void setWidth(qint32 width) override;
|
|
|
|
void setHeight(qint32 height) override;
|
2024-02-01 09:29:45 +00:00
|
|
|
};
|