diff --git a/src/core/popupanchor.cpp b/src/core/popupanchor.cpp index 5700224f..594ec4af 100644 --- a/src/core/popupanchor.cpp +++ b/src/core/popupanchor.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -11,7 +12,8 @@ bool PopupAnchorState::operator==(const PopupAnchorState& other) const { return this->rect == other.rect && this->edges == other.edges && this->gravity == other.gravity - && this->adjustment == other.adjustment && this->anchorpoint == other.anchorpoint; + && this->adjustment == other.adjustment && this->anchorpoint == other.anchorpoint + && this->size == other.size; } bool PopupAnchor::isDirty() const { @@ -128,8 +130,9 @@ void PopupAnchor::setAdjustment(PopupAdjustment::Flags adjustment) { emit this->adjustmentChanged(); } -void PopupAnchor::updateAnchorpoint(const QPoint& anchorpoint) { +void PopupAnchor::updatePlacement(const QPoint& anchorpoint, const QSize& size) { this->state.anchorpoint = anchorpoint; + this->state.size = size; } static PopupPositioner* POSITIONER = nullptr; // NOLINT @@ -140,10 +143,15 @@ void PopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bool only qFatal() << "Cannot reposition popup that does not have a transient parent."; } - auto adjustment = anchor->adjustment(); - auto screenGeometry = parentWindow->screen()->geometry(); auto parentGeometry = parentWindow->geometry(); auto windowGeometry = window->geometry(); + + anchor->updatePlacement(parentGeometry.topLeft(), windowGeometry.size()); + if (onlyIfDirty && !anchor->isDirty()) return; + anchor->markClean(); + + auto adjustment = anchor->adjustment(); + auto screenGeometry = parentWindow->screen()->geometry(); auto anchorRectGeometry = anchor->rect().qrect().translated(parentGeometry.topLeft()); auto anchorEdges = anchor->edges(); @@ -160,10 +168,6 @@ void PopupPositioner::reposition(PopupAnchor* anchor, QWindow* window, bool only : anchorEdges.testFlag(Edges::Bottom) ? anchorRectGeometry.bottom() : anchorRectGeometry.center().y(); - anchor->updateAnchorpoint({anchorX, anchorY}); - if (onlyIfDirty && !anchor->isDirty()) return; - anchor->markClean(); - auto calcEffectiveX = [&]() { return anchorGravity.testFlag(Edges::Left) ? anchorX - windowGeometry.width() + 1 : anchorGravity.testFlag(Edges::Right) ? anchorX diff --git a/src/core/popupanchor.hpp b/src/core/popupanchor.hpp index 04d89f47..11b2ba20 100644 --- a/src/core/popupanchor.hpp +++ b/src/core/popupanchor.hpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,7 @@ struct PopupAnchorState { Edges::Flags gravity = Edges::Bottom | Edges::Right; PopupAdjustment::Flags adjustment = PopupAdjustment::Slide; QPoint anchorpoint; + QSize size; }; ///! Anchorpoint or positioner for popup windows. @@ -123,7 +125,7 @@ public: [[nodiscard]] PopupAdjustment::Flags adjustment() const; void setAdjustment(PopupAdjustment::Flags adjustment); - void updateAnchorpoint(const QPoint& anchorpoint); + void updatePlacement(const QPoint& anchorpoint, const QSize& size); signals: void windowChanged(); diff --git a/src/core/popupwindow.cpp b/src/core/popupwindow.cpp index fa5d7892..7a3d9316 100644 --- a/src/core/popupwindow.cpp +++ b/src/core/popupwindow.cpp @@ -26,12 +26,12 @@ ProxyPopupWindow::ProxyPopupWindow(QObject* parent): ProxyWindowBase(parent) { void ProxyPopupWindow::completeWindow() { this->ProxyWindowBase::completeWindow(); - QObject::connect( - this->window, - &QWindow::visibleChanged, - this, - &ProxyPopupWindow::onVisibleChanged - ); + + // clang-format off + QObject::connect(this->window, &QWindow::visibleChanged, this, &ProxyPopupWindow::onVisibleChanged); + QObject::connect(this->window, &QWindow::widthChanged, this, &ProxyPopupWindow::reposition); + QObject::connect(this->window, &QWindow::heightChanged, this, &ProxyPopupWindow::reposition); + // clang-format on this->window->setFlag(Qt::ToolTip); }