From b4afa87042c61fdf7fd5f60942969ffd2ee7467d Mon Sep 17 00:00:00 2001 From: Alfredo Monclus Date: Thu, 13 Mar 2025 14:18:31 -0300 Subject: [PATCH] start: modify the flowlayout to have homogeneous rows --- src/Mod/Start/Gui/FlowLayout.cpp | 41 +++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/Mod/Start/Gui/FlowLayout.cpp b/src/Mod/Start/Gui/FlowLayout.cpp index 441bfb9fc4..f12b45d003 100644 --- a/src/Mod/Start/Gui/FlowLayout.cpp +++ b/src/Mod/Start/Gui/FlowLayout.cpp @@ -151,12 +151,17 @@ int FlowLayout::doLayout(const QRect& rect, bool testOnly) const int bottom {}; getContentsMargins(&left, &top, &right, &bottom); QRect effectiveRect = rect.adjusted(+left, +top, -right, -bottom); + int x = effectiveRect.x(); int y = effectiveRect.y(); int lineHeight = 0; + QVector currentRow; + for (auto item : std::as_const(itemList)) { QWidget* wid = item->widget(); + QSize itemSizeHint = item->sizeHint(); + int spaceX = horizontalSpacing(); if (spaceX == -1) { spaceX = wid->style()->layoutSpacing(QSizePolicy::PushButton, @@ -171,20 +176,40 @@ int FlowLayout::doLayout(const QRect& rect, bool testOnly) const Qt::Vertical); } - int nextX = x + item->sizeHint().width() + spaceX; - if (nextX - spaceX > effectiveRect.right() && lineHeight > 0) { + int nextX = x + itemSizeHint.width() + spaceX; + + // Step 1: Wrap if necessary + if (nextX - spaceX > effectiveRect.right() && !currentRow.isEmpty()) { + // Apply row height to all items in the current row + for (auto rowItem : currentRow) { + if (!testOnly) { + rowItem->setGeometry(QRect(QPoint(rowItem->geometry().x(), y), + QSize(rowItem->sizeHint().width(), lineHeight))); + } + } + + // Move to next row + y += lineHeight + spaceY; x = effectiveRect.x(); - y = y + lineHeight + spaceY; - nextX = x + item->sizeHint().width() + spaceX; - lineHeight = 0; + currentRow.clear(); } + currentRow.append(item); + lineHeight = std::max(lineHeight, itemSizeHint.height()); + if (!testOnly) { - item->setGeometry(QRect(QPoint(x, y), item->sizeHint())); + item->setGeometry(QRect(QPoint(x, y), QSize(itemSizeHint.width(), lineHeight))); } - x = nextX; - lineHeight = std::max(lineHeight, item->sizeHint().height()); + x += itemSizeHint.width() + spaceX; + } + + // Step 2: Apply the last row's height + for (auto rowItem : currentRow) { + if (!testOnly) { + rowItem->setGeometry(QRect(QPoint(rowItem->geometry().x(), y), + QSize(rowItem->sizeHint().width(), lineHeight))); + } } return y + lineHeight - rect.y() + bottom;