core/window: expose coordinate mapping functions on QsWindow

This commit is contained in:
outfoxxed 2025-05-29 22:35:17 -07:00
parent 6d42d26c79
commit 4a0f6382b0
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 215 additions and 2 deletions

View file

@ -42,6 +42,9 @@ public:
/// It provides the following properties
/// - `window` - the `QSWindow` object.
/// - `contentItem` - the `contentItem` property of the window.
///
/// @@itemPosition(), @@itemRect(), and @@mapFromItem() can also be called directly
/// on the attached object.
class WindowInterface: public Reloadable {
Q_OBJECT;
// clang-format off
@ -150,6 +153,49 @@ class WindowInterface: public Reloadable {
public:
explicit WindowInterface(QObject* parent = nullptr): Reloadable(parent) {}
/// Returns the given Item's position relative to the window. Does not update reactively.
///
/// Equivalent to calling `window.contentItem.mapFromItem(item, 0, 0)`
///
/// See also: @@QtQuick.Item.mapFromItem()
Q_INVOKABLE [[nodiscard]] QPointF itemPosition(QQuickItem* item) const;
/// Returns the given Item's geometry relative to the window. Does not update reactively.
///
/// Equivalent to calling `window.contentItem.mapFromItem(item, 0, 0, 0, 0)`
///
/// See also: @@QtQuick.Item.mapFromItem()
Q_INVOKABLE [[nodiscard]] QRectF itemRect(QQuickItem* item) const;
/// Maps the given point in the coordinate space of `item` to one in the coordinate space
/// of this window. Does not update reactively.
///
/// Equivalent to calling `window.contentItem.mapFromItem(item, point)`
///
/// See also: @@QtQuick.Item.mapFromItem()
Q_INVOKABLE [[nodiscard]] QPointF mapFromItem(QQuickItem* item, QPointF point) const;
/// Maps the given point in the coordinate space of `item` to one in the coordinate space
/// of this window. Does not update reactively.
///
/// Equivalent to calling `window.contentItem.mapFromItem(item, x, y)`
///
/// See also: @@QtQuick.Item.mapFromItem()
Q_INVOKABLE [[nodiscard]] QPointF mapFromItem(QQuickItem* item, qreal x, qreal y) const;
/// Maps the given rect in the coordinate space of `item` to one in the coordinate space
/// of this window. Does not update reactively.
///
/// Equivalent to calling `window.contentItem.mapFromItem(item, rect)`
///
/// See also: @@QtQuick.Item.mapFromItem()
Q_INVOKABLE [[nodiscard]] QRectF mapFromItem(QQuickItem* item, QRectF rect) const;
// clang-format off
/// Maps the given rect in the coordinate space of `item` to one in the coordinate space
/// of this window. Does not update reactively.
///
/// Equivalent to calling `window.contentItem.mapFromItem(item, x, y, width, height)`
///
/// See also: @@QtQuick.Item.mapFromItem()
Q_INVOKABLE [[nodiscard]] QRectF mapFromItem(QQuickItem* item, qreal x, qreal y, qreal width, qreal height) const;
// clang-format on
[[nodiscard]] virtual ProxyWindowBase* proxyWindow() const = 0;
[[nodiscard]] virtual QQuickItem* contentItem() const = 0;
@ -213,8 +259,18 @@ class QsWindowAttached: public QObject {
public:
[[nodiscard]] virtual QObject* window() const = 0;
[[nodiscard]] virtual ProxyWindowBase* proxyWindow() const = 0;
[[nodiscard]] virtual QQuickItem* contentItem() const = 0;
Q_INVOKABLE [[nodiscard]] QPointF itemPosition(QQuickItem* item) const;
Q_INVOKABLE [[nodiscard]] QRectF itemRect(QQuickItem* item) const;
Q_INVOKABLE [[nodiscard]] QPointF mapFromItem(QQuickItem* item, QPointF point) const;
Q_INVOKABLE [[nodiscard]] QPointF mapFromItem(QQuickItem* item, qreal x, qreal y) const;
Q_INVOKABLE [[nodiscard]] QRectF mapFromItem(QQuickItem* item, QRectF rect) const;
Q_INVOKABLE [[nodiscard]] QRectF
mapFromItem(QQuickItem* item, qreal x, qreal y, qreal width, qreal height) const;
signals:
void windowChanged();