1212#include < qtclasshelpermacros.h>
1313#include < qtmetamacros.h>
1414#include < qtypes.h>
15+ #include < qvariant.h>
16+ #include < qvectornd.h>
1517#include < qwindow.h>
1618
1719#include " ../window/proxywindow.hpp"
@@ -61,7 +63,7 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(PopupAdjustment::Flags);
6163struct PopupAnchorState {
6264 bool operator ==(const PopupAnchorState& other) const ;
6365
64- Box rect = {0 , 0 , 1 , 1 };
66+ QRect rect = {0 , 0 , 1 , 1 };
6567 Edges::Flags edges = Edges::Top | Edges::Left;
6668 Edges::Flags gravity = Edges::Bottom | Edges::Right;
6769 PopupAdjustment::Flags adjustment = PopupAdjustment::Slide;
@@ -90,12 +92,19 @@ class PopupAnchor: public QObject {
9092 // / The anchorpoints the popup will attach to, relative to @@item or @@window.
9193 // / Which anchors will be used is determined by the @@edges, @@gravity, and @@adjustment.
9294 // /
95+ // / If using @@item, the default anchor rectangle matches the dimensions of the item.
96+ // /
9397 // / If you leave @@edges, @@gravity and @@adjustment at their default values,
9498 // / setting more than `x` and `y` does not matter. The anchor rect cannot
9599 // / be smaller than 1x1 pixels.
96100 // /
97101 // / [coordinate mapping functions]: https://doc.qt.io/qt-6/qml-qtquick-item.html#mapFromItem-method
98102 Q_PROPERTY (Box rect READ rect WRITE setRect RESET resetRect NOTIFY rectChanged);
103+ // / A margin applied to the anchor rect.
104+ // /
105+ // / This is most useful when @@item is used and @@rect is left at its default
106+ // / value (matching the Item's dimensions).
107+ Q_PROPERTY (Margins margins READ margins WRITE setMargins NOTIFY marginsChanged);
99108 // / The point on the anchor rectangle the popup should anchor to.
100109 // / Opposing edges suchs as `Edges.Left | Edges.Right` are not allowed.
101110 // /
@@ -138,13 +147,16 @@ class PopupAnchor: public QObject {
138147 [[nodiscard]] QQuickItem* item () const { return this ->mItem ; }
139148 void setItem (QQuickItem* item);
140149
141- [[nodiscard]] Box windowRect () const { return this ->state .rect ; }
142- void setWindowRect (Box rect);
150+ [[nodiscard]] QRect windowRect () const { return this ->state .rect ; }
151+ void setWindowRect (QRect rect);
143152
144153 [[nodiscard]] Box rect () const { return this ->mUserRect ; }
145154 void setRect (Box rect);
146155 void resetRect ();
147156
157+ [[nodiscard]] Margins margins () const { return this ->mMargins ; }
158+ void setMargins (Margins margins);
159+
148160 [[nodiscard]] Edges::Flags edges () const { return this ->state .edges ; }
149161 void setEdges (Edges::Flags edges);
150162
@@ -168,6 +180,7 @@ class PopupAnchor: public QObject {
168180 QSDOC_HIDE void backingWindowVisibilityChanged ();
169181 QSDOC_HIDE void windowRectChanged ();
170182 void rectChanged ();
183+ void marginsChanged ();
171184 void edgesChanged ();
172185 void gravityChanged ();
173186 void adjustmentChanged ();
@@ -183,6 +196,7 @@ private slots:
183196 ProxyWindowBase* mProxyWindow = nullptr ;
184197 PopupAnchorState state;
185198 Box mUserRect ;
199+ Margins mMargins ;
186200 std::optional<PopupAnchorState> lastState;
187201};
188202
0 commit comments