Fix max-size only working in one orientation
ItemContainer::maxSizeHint() algo was wrong. Add unit-test too.
This commit is contained in:
@@ -1820,28 +1820,38 @@ QSize ItemContainer::minSize() const
|
||||
|
||||
QSize ItemContainer::maxSizeHint() const
|
||||
{
|
||||
int maxW = KDDOCKWIDGETS_MAX_WIDTH;
|
||||
int maxH = KDDOCKWIDGETS_MAX_HEIGHT;
|
||||
int maxW = isVertical() ? KDDOCKWIDGETS_MAX_WIDTH : 0;
|
||||
int maxH = isVertical() ? 0 : KDDOCKWIDGETS_MAX_HEIGHT;
|
||||
|
||||
if (!isEmpty()) {
|
||||
const Item::List visibleChildren = this->visibleChildren();
|
||||
const Item::List visibleChildren = this->visibleChildren();
|
||||
if (!visibleChildren.isEmpty()) {
|
||||
for (Item *item : visibleChildren) {
|
||||
const QSize itemMaxSz = item->maxSizeHint();
|
||||
const int itemMaxWidth = itemMaxSz.width();
|
||||
const int itemMaxHeight = itemMaxSz.height();
|
||||
if (isVertical()) {
|
||||
maxW = qMin(maxW, item->maxSizeHint().width());
|
||||
maxH += item->maxSizeHint().height();
|
||||
maxW = qMin(maxW, itemMaxWidth);
|
||||
maxH = qMin(maxH + itemMaxHeight, KDDOCKWIDGETS_MAX_HEIGHT);
|
||||
} else {
|
||||
maxH = qMin(maxH, item->maxSizeHint().height());
|
||||
maxW += item->maxSizeHint().width();
|
||||
maxH = qMin(maxH, itemMaxHeight);
|
||||
maxW = qMin(maxW + itemMaxWidth, KDDOCKWIDGETS_MAX_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
const int separatorWaste = (visibleChildren.size() - 1) * separatorThickness;
|
||||
if (isVertical())
|
||||
maxH += separatorWaste;
|
||||
else
|
||||
maxW += separatorWaste;
|
||||
if (isVertical()) {
|
||||
maxH = qMin(maxH + separatorWaste, KDDOCKWIDGETS_MAX_HEIGHT);
|
||||
} else {
|
||||
maxW = qMin(maxW + separatorWaste, KDDOCKWIDGETS_MAX_WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxW == 0)
|
||||
maxW = KDDOCKWIDGETS_MAX_WIDTH;
|
||||
|
||||
if (maxH == 0)
|
||||
maxH = KDDOCKWIDGETS_MAX_HEIGHT;
|
||||
|
||||
return QSize(maxW, maxH).expandedTo(minSize());
|
||||
}
|
||||
|
||||
|
||||
@@ -196,6 +196,7 @@ private Q_SLOTS:
|
||||
void tst_minSizeChangedBeforeRestore();
|
||||
void tst_separatorMoveCrash();
|
||||
void tst_maxSizeHonoured1();
|
||||
void tst_maxSizeHonoured2();
|
||||
};
|
||||
|
||||
class MyHostWidget : public QWidget
|
||||
@@ -1561,6 +1562,24 @@ void TestMultiSplitter::tst_maxSizeHonoured1()
|
||||
QCOMPARE(item2->height(), maxHeight);
|
||||
}
|
||||
|
||||
void TestMultiSplitter::tst_maxSizeHonoured2()
|
||||
{
|
||||
// Tests that a container gets the max size of its children
|
||||
|
||||
auto root1 = createRoot();
|
||||
auto root2 = createRoot();
|
||||
auto item1 = createItem();
|
||||
auto item2 = createItem();
|
||||
|
||||
root1->insertItem(item1, Item::Location_OnTop);
|
||||
root2->insertItem(item2, Item::Location_OnTop);
|
||||
|
||||
item2->setMaxSizeHint(QSize(200, 200));
|
||||
|
||||
root1->insertItem(root2.release(), Item::Location_OnBottom);
|
||||
QCOMPARE(item2->parentContainer()->maxSizeHint(), item2->maxSizeHint());
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
bool qpaPassed = false;
|
||||
|
||||
Reference in New Issue
Block a user