Skip to content

Commit f4066cb

Browse files
committed
core/popupanchor: add anchoring signal for last second repositioning
1 parent ee93306 commit f4066cb

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/core/popupanchor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ void PopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bool only
151151
if (onlyIfDirty && !anchor->isDirty()) return;
152152
anchor->markClean();
153153

154+
emit anchor->anchoring();
155+
154156
auto adjustment = anchor->adjustment();
155157
auto screenGeometry = parentWindow->screen()->geometry();
156158
auto anchorRectGeometry = anchor->rect().qrect().translated(parentGeometry.topLeft());

src/core/popupanchor.hpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,18 @@ class PopupAnchor: public QObject {
7777
/// determined by the @@edges, @@gravity, and @@adjustment.
7878
///
7979
/// If you leave @@edges, @@gravity and @@adjustment at their default values,
80-
/// setting more than `x` and `y` does not matter.
80+
/// setting more than `x` and `y` does not matter. The anchor rect cannot
81+
/// be smaller than 1x1 pixels.
8182
///
82-
/// > [!INFO] The anchor rect cannot be smaller than 1x1 pixels.
83+
/// > [!INFO] To position a popup relative to an item inside a window,
84+
/// > you can use [coordinate mapping functions] (note the warning below).
85+
///
86+
/// > [!WARNING] Using [coordinate mapping functions] in a binding to
87+
/// > this property will position the anchor incorrectly.
88+
/// > If you want to use them, do so in @@anchoring(s), or use
89+
/// > @@TransformWatcher if you need real-time updates to mapped coordinates.
90+
///
91+
/// [coordinate mapping functions]: https://doc.qt.io/qt-6/qml-qtquick-item.html#mapFromItem-method
8392
Q_PROPERTY(Box rect READ rect WRITE setRect NOTIFY rectChanged);
8493
/// The point on the anchor rectangle the popup should anchor to.
8594
/// Opposing edges suchs as `Edges.Left | Edges.Right` are not allowed.
@@ -127,6 +136,12 @@ class PopupAnchor: public QObject {
127136
void updatePlacement(const QPoint& anchorpoint, const QSize& size);
128137

129138
signals:
139+
/// Emitted when this anchor is about to be used. Mostly useful for modifying
140+
/// the anchor @@rect using [coordinate mapping functions], which are not reactive.
141+
///
142+
/// [coordinate mapping functions]: https://doc.qt.io/qt-6/qml-qtquick-item.html#mapFromItem-method
143+
void anchoring();
144+
130145
void windowChanged();
131146
QSDOC_HIDE void backingWindowVisibilityChanged();
132147
void rectChanged();

src/wayland/popupanchor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void WaylandPopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bo
4141

4242
positioner.set_constraint_adjustment(anchor->adjustment().toInt());
4343

44+
emit anchor->anchoring();
45+
4446
auto anchorRect = anchor->rect();
4547

4648
if (auto* p = window->transientParent()) {
@@ -101,6 +103,7 @@ void WaylandPopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bo
101103
bool WaylandPopupPositioner::shouldRepositionOnMove() const { return true; }
102104

103105
void WaylandPopupPositioner::setFlags(PopupAnchor* anchor, QWindow* window) {
106+
emit anchor->anchoring();
104107
auto anchorRect = anchor->rect();
105108

106109
if (auto* p = window->transientParent()) {

0 commit comments

Comments
 (0)