diff --git a/src/multisplitter/Anchor.cpp b/src/multisplitter/Anchor.cpp index b69813a8..3c3739d0 100644 --- a/src/multisplitter/Anchor.cpp +++ b/src/multisplitter/Anchor.cpp @@ -454,6 +454,23 @@ Anchor *Anchor::endFolowee() const return nullptr; } +bool Anchor::findAnchor(Anchor *anchor, Anchor::Side side) const +{ + Q_ASSERT(anchor != this); + Q_ASSERT(anchor->orientation() == orientation()); + + for (Item *item : items(side)) { + Anchor *a = item->anchorAtSide(side, orientation()); + if (anchor == a) + return true; + + if (a->findAnchor(anchor, side)) + return true; + } + + return false; +} + void Anchor::onFolloweePositionChanged(int pos) { Q_ASSERT(isFollowing()); diff --git a/src/multisplitter/Anchor_p.h b/src/multisplitter/Anchor_p.h index a420ef9c..33d40bd0 100644 --- a/src/multisplitter/Anchor_p.h +++ b/src/multisplitter/Anchor_p.h @@ -226,6 +226,14 @@ public: */ Anchor *endFolowee() const; + /** + * @brief Recursively looks for an anchor in the whole layout but only looking at side @p side + * + * This allows us to know if there's an anchor on the top or left of us (side1) or right or bottom + * (side2), in the whole layout. + */ + bool findAnchor(Anchor *anchor, Side side) const; + static int thickness(bool staticAnchor); static Anchor::Side oppositeSide(Side side); void onFolloweePositionChanged(int pos); diff --git a/src/multisplitter/Item.cpp b/src/multisplitter/Item.cpp index 1407ea22..224226ed 100644 --- a/src/multisplitter/Item.cpp +++ b/src/multisplitter/Item.cpp @@ -235,6 +235,16 @@ int Item::minLength(Qt::Orientation orientation) const return KDDockWidgets::widgetMinLength(this, orientation); } +Anchor *Item::anchorAtSide(Anchor::Side side, Qt::Orientation orientation) const +{ + if (!d->m_anchorGroup.isValid()) + qWarning() << Q_FUNC_INFO << "Invalid anchor group" << &d->m_anchorGroup + << "in" << this << "; window=" << parentWidget()->window(); + + return d->m_anchorGroup.anchorAtSide(side, orientation); +} + + Anchor *Item::anchorAtDirection(Anchor::Side side, Qt::Orientation orientation) const { if (!d->m_anchorGroup.isValid()) diff --git a/src/multisplitter/Item_p.h b/src/multisplitter/Item_p.h index 2456d7bb..2d481b5a 100644 --- a/src/multisplitter/Item_p.h +++ b/src/multisplitter/Item_p.h @@ -123,6 +123,7 @@ public: int length(Qt::Orientation) const; int minLength(Qt::Orientation orientation) const; + Anchor *anchorAtSide(Anchor::Side side, Qt::Orientation orientation) const; Anchor *anchorAtDirection(Anchor::Side side, Qt::Orientation orientation) const; Anchor *anchor(const GeometryDiff &) const; AnchorGroup& anchorGroup();