Commit 0a43c978 authored by Thomas BOUTROUE's avatar Thomas BOUTROUE

Fix potential layout issue in FormContainer

parent de945256
Pipeline #1005 passed with stage
in 14 seconds
......@@ -25,12 +25,12 @@ void QQuickFormContainer::setupHandlers (void) {
}
void QQuickFormContainer::relayout (void) {
const QList<QQuickItem *> childItemsList { childItems () };
int itemIdx { 0 };
int totalItemsHeight { 0 };
int maxLeftImplicitWidth { 0 };
int maxRightImplicitWidth { 0 };
QVector<Line> layoutLines { };
const QList<QQuickItem *> childItemsList { childItems () };
layoutLines.reserve (childItemsList.count ());
for (QQuickItem * childItem : childItemsList) {
if (!childItem->inherits (REPEATER_CLASSNAME)) {
......@@ -47,7 +47,7 @@ void QQuickFormContainer::relayout (void) {
else {
layoutLines.last ().field = childItem;
layoutLines.last ().stretched = (attached != Q_NULLPTR && attached->get_horizontalStretch () > 0);
layoutLines.last ().forcedW = (attached != Q_NULLPTR ? attached->get_forcedWidth () : 0);
layoutLines.last ().forcedW = (attached != Q_NULLPTR ? attached->get_forcedWidth () : 0);
layoutLines.last ().forcedH = (attached != Q_NULLPTR ? attached->get_forcedHeight () : 0);
layoutLines.last ().computedH = qMax (qCeil (layoutLines.last ().label->implicitHeight ()),
qCeil (layoutLines.last ().field->implicitHeight ()));
......@@ -60,28 +60,32 @@ void QQuickFormContainer::relayout (void) {
}
}
}
if (!layoutLines.isEmpty () && layoutLines.last ().field != Q_NULLPTR) {
if (!layoutLines.isEmpty ()) {
const int totalVerticalSpacing { (layoutLines.count () > 1 ? ((layoutLines.count () -1) * m_verticalSpacing) : 0) };
setImplicitWidth (maxLeftImplicitWidth + maxRightImplicitWidth + m_horizontalSpacing);
setImplicitHeight (totalItemsHeight + totalVerticalSpacing);
const int strechedRightItemsWidth { (qFloor (width ()) - maxLeftImplicitWidth - m_horizontalSpacing) };
int currentY { 0 };
for (const Line & line : layoutLines) {
line.label->setX (0);
line.label->setY (currentY);
line.label->setWidth (maxLeftImplicitWidth);
line.label->setHeight (line.computedH);
line.field->setX (maxLeftImplicitWidth + m_horizontalSpacing);
line.field->setY (currentY);
line.field->setHeight (line.computedH);
if (line.stretched) {
line.field->setWidth (strechedRightItemsWidth);
if (line.label != nullptr) {
line.label->setX (0);
line.label->setY (currentY);
line.label->setWidth (maxLeftImplicitWidth);
line.label->setHeight (line.computedH);
}
else if (line.forcedW > 0) {
line.field->setWidth (line.forcedW);
}
else {
line.field->setWidth (line.field->implicitWidth ());
if (line.field != nullptr) {
line.field->setX (maxLeftImplicitWidth + m_horizontalSpacing);
line.field->setY (currentY);
line.field->setHeight (line.computedH);
if (line.stretched) {
line.field->setWidth (strechedRightItemsWidth);
}
else if (line.forcedW > 0) {
line.field->setWidth (line.forcedW);
}
else {
line.field->setWidth (line.field->implicitWidth ());
}
}
currentY += line.computedH;
currentY += m_verticalSpacing;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment