From f25aca5c658b018e3b510990d82e7195d0c3b7c0 Mon Sep 17 00:00:00 2001 From: Jan Arve Saether Date: Tue, 11 Feb 2014 13:22:16 +0100 Subject: Don't ignore horizontal alignment for items with baseline alignments Horizontal alignment were ignored when an item had baseline alignment specified. Change-Id: I2df526dc830952cdc26e1973d4787e9457c94edd Reviewed-by: J-P Nurmi Reviewed-by: Shawn Rutledge --- src/gui/util/qgridlayoutengine.cpp | 86 +++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'src/gui/util') diff --git a/src/gui/util/qgridlayoutengine.cpp b/src/gui/util/qgridlayoutengine.cpp index 31f00c0601..10b4a2ee35 100644 --- a/src/gui/util/qgridlayoutengine.cpp +++ b/src/gui/util/qgridlayoutengine.cpp @@ -618,52 +618,52 @@ QGridLayoutBox QGridLayoutItem::box(Qt::Orientation orientation, qreal constrain QRectF QGridLayoutItem::geometryWithin(qreal x, qreal y, qreal width, qreal height, qreal rowDescent, Qt::Alignment align) const { - QGridLayoutBox vBox = box(Qt::Vertical); - if (!(align & Qt::AlignBaseline) || vBox.q_minimumDescent < 0.0 || rowDescent < 0.0) { - qreal cellWidth = width; - qreal cellHeight = height; - - - QSizeF size = effectiveMaxSize(QSizeF(-1,-1)); - if (hasDynamicConstraint()) { - if (dynamicConstraintOrientation() == Qt::Vertical) { - if (size.width() > cellWidth) - size = effectiveMaxSize(QSizeF(cellWidth, -1)); - } else if (size.height() > cellHeight) { - size = effectiveMaxSize(QSizeF(-1, cellHeight)); - } - } - size = size.boundedTo(QSizeF(cellWidth, cellHeight)); - width = size.width(); - height = size.height(); - - switch (align & Qt::AlignHorizontal_Mask) { - case Qt::AlignHCenter: - x += (cellWidth - width)/2; - break; - case Qt::AlignRight: - x += cellWidth - width; - break; - default: - break; + const qreal cellWidth = width; + const qreal cellHeight = height; + + QSizeF size = effectiveMaxSize(QSizeF(-1,-1)); + if (hasDynamicConstraint()) { + if (dynamicConstraintOrientation() == Qt::Vertical) { + if (size.width() > cellWidth) + size = effectiveMaxSize(QSizeF(cellWidth, -1)); + } else if (size.height() > cellHeight) { + size = effectiveMaxSize(QSizeF(-1, cellHeight)); } - switch (align & Qt::AlignVertical_Mask) { - case Qt::AlignVCenter: - y += (cellHeight - height)/2; - break; - case Qt::AlignBottom: - y += cellHeight - height; - break; - default: - break; - } - return QRectF(x, y, width, height); - } else { + } + size = size.boundedTo(QSizeF(cellWidth, cellHeight)); + width = size.width(); + height = size.height(); + + switch (align & Qt::AlignHorizontal_Mask) { + case Qt::AlignHCenter: + x += (cellWidth - width)/2; + break; + case Qt::AlignRight: + x += cellWidth - width; + break; + default: + break; + } + + switch (align & Qt::AlignVertical_Mask) { + case Qt::AlignVCenter: + y += (cellHeight - height)/2; + break; + case Qt::AlignBottom: + y += cellHeight - height; + break; + case Qt::AlignBaseline: { width = qMin(effectiveMaxSize(QSizeF(-1,-1)).width(), width); - qreal descent = vBox.q_minimumDescent; - qreal ascent = vBox.q_minimumSize - descent; - return QRectF(x, y + height - rowDescent - ascent, width, ascent + descent); + QGridLayoutBox vBox = box(Qt::Vertical); + const qreal descent = vBox.q_minimumDescent; + const qreal ascent = vBox.q_minimumSize - descent; + y += (cellHeight - rowDescent - ascent); + height = ascent + descent; + break; } + default: + break; } + return QRectF(x, y, width, height); } void QGridLayoutItem::transpose() -- cgit v1.2.3