Add Anchor::findAnchor()

This commit is contained in:
Sergio Martins
2019-07-05 10:35:15 +01:00
parent 0d9ab0ee00
commit d0a34ae7e7
4 changed files with 36 additions and 0 deletions

View File

@@ -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());

View File

@@ -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);

View File

@@ -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())

View File

@@ -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();