From 6e77dce573ba7329c4ed9b6f701010d354060f6e Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 10 Jun 2020 18:54:34 +0100 Subject: [PATCH] Add Item::neighboursMaxLengthFor() --- src/private/multisplitter/Item.cpp | 31 ++++++++++++++++++++++++++++++ src/private/multisplitter/Item_p.h | 1 + 2 files changed, 32 insertions(+) diff --git a/src/private/multisplitter/Item.cpp b/src/private/multisplitter/Item.cpp index 65452579..bd97b1f2 100644 --- a/src/private/multisplitter/Item.cpp +++ b/src/private/multisplitter/Item.cpp @@ -2588,6 +2588,37 @@ int ItemContainer::neighboursMinLengthFor(const Item *item, Side side, Qt::Orien } } +int ItemContainer::neighboursMaxLengthFor(const Item *item, Side side, Qt::Orientation o) const +{ + const Item::List children = visibleChildren(); + const int index = children.indexOf(const_cast(item)); + if (index == -1) { + qWarning() << Q_FUNC_INFO << "Couldn't find item" << item; + return 0; + } + + if (o == d->m_orientation) { + int neighbourMaxLength = 0; + int start = 0; + int end = -1; + if (side == Side1) { + start = 0; + end = index - 1; + } else { + start = index + 1; + end = children.size() - 1; + } + + for (int i = start; i <= end; ++i) + neighbourMaxLength = qMin(length(), neighbourMaxLength + children.at(i)->maxLengthHint(d->m_orientation)); + + return neighbourMaxLength; + } else { + // No neighbours here + return 0; + } +} + int ItemContainer::availableOnSide(const Item *child, Side side) const { const int length = neighboursLengthFor(child, side, d->m_orientation); diff --git a/src/private/multisplitter/Item_p.h b/src/private/multisplitter/Item_p.h index ad5dca65..893bb9a9 100644 --- a/src/private/multisplitter/Item_p.h +++ b/src/private/multisplitter/Item_p.h @@ -464,6 +464,7 @@ private: int neighboursLengthFor(const Item *item, Side, Qt::Orientation) const; int neighboursLengthFor_recursive(const Item *item, Side, Qt::Orientation) const; int neighboursMinLengthFor(const Item *item, Side, Qt::Orientation) const; + int neighboursMaxLengthFor(const Item *item, Side, Qt::Orientation) const; int availableOnSide(const Item *child, Side) const; int availableOnSide_recursive(const Item *child, Side, Qt::Orientation orientation) const; void onChildMinSizeChanged(Item *child);