diff options
| author | Jan Arve Saether <jan-arve.saether@digia.com> | 2014-01-23 18:21:14 +0100 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-27 11:01:32 +0100 |
| commit | 9267bd4e2f52e22f73b37e6a8d974b8eaa51f85d (patch) | |
| tree | 5ff3a5873b6618f13791a9767b03016f97584bc9 | |
| parent | 333381350ba3792f41cb117854ec8bfdccb225ca (diff) | |
Make sure that items don't exceed the layout-computed boundary
When geometries were rounded to their nearest pixel grid geometry they
sometimes exceeded the area the layout calculated them to cover.
This could often be observed by that the visual spacing got shrunk to a
smaller size than was specified.
For small spacings values the visual spacing could even disappear.
With this fix the visual spacing should never be smaller than the
specified spacings value (but might be bigger due to rounding).
Task-number: QTBUG-36235
Change-Id: I5142c793460e50fd2de397abfd2ea6730f1bd042
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
| -rw-r--r-- | src/layouts/qquickgridlayoutengine_p.h | 8 | ||||
| -rw-r--r-- | tests/auto/controls/data/tst_gridlayout.qml | 56 |
2 files changed, 61 insertions, 3 deletions
diff --git a/src/layouts/qquickgridlayoutengine_p.h b/src/layouts/qquickgridlayoutengine_p.h index 886dd850c..94b8677ac 100644 --- a/src/layouts/qquickgridlayoutengine_p.h +++ b/src/layouts/qquickgridlayoutengine_p.h @@ -55,6 +55,7 @@ #include <QtGui/private/qgridlayoutengine_p.h> #include <QtGui/private/qlayoutpolicy_p.h> +#include <QtCore/qmath.h> #include "qquickitem.h" #include "qquicklayout_p.h" @@ -112,9 +113,10 @@ public: void setGeometry(const QRectF &rect) { - const QRect r(rect.toRect()); - const QSize newSize(r.size()); - m_item->setPosition(r.topLeft()); + const QPoint innerTopLeft(qCeil(rect.left()), qCeil(rect.top())); + const QPoint innerBottomRight(qFloor(rect.right()), qFloor(rect.bottom())); + const QSize newSize(innerBottomRight.x() - innerTopLeft.x(), innerBottomRight.y() - innerTopLeft.y()); + m_item->setPosition(innerTopLeft); QSizeF oldSize(m_item->width(), m_item->height()); if (newSize == oldSize) { if (QQuickLayout *lay = qobject_cast<QQuickLayout *>(m_item)) diff --git a/tests/auto/controls/data/tst_gridlayout.qml b/tests/auto/controls/data/tst_gridlayout.qml index f66a623c5..985782d2e 100644 --- a/tests/auto/controls/data/tst_gridlayout.qml +++ b/tests/auto/controls/data/tst_gridlayout.qml @@ -841,5 +841,61 @@ Item { verify(isFinite(layout.implicitWidth)) layout.destroy(); } + + Component { + id: layout_alignToPixelGrid_Component + GridLayout { + columns: 3 + rowSpacing: 0 + columnSpacing: 2 + Repeater { + model: 3*3 + Rectangle { + color: "red" + Layout.fillWidth: true + Layout.fillHeight: true + } + } + } + } + + function test_alignToPixelGrid() + { + var layout = layout_alignToPixelGrid_Component.createObject(container) + layout.width = 30 + layout.height = 28 + + var rectWidth = (layout.width - 2 * layout.columnSpacing)/3 + var rectHeight = layout.height/3 + + waitForRendering(layout); + + var sp = layout.columnSpacing + var idealGeom = [0,0,rectWidth,rectHeight] + for (var r = 0; r < 3; ++r) { + idealGeom[0] = 0 + idealGeom[2] = rectWidth + for (var c = 0; c < 3; ++c) { + var child = layout.children[3*r + c] + var visualGeom = [child.x, child.y, child.x + child.width, child.y + child.height] + + // verify that visualGeom is an integer number + for (var i = 0; i < 4; ++i) + compare(visualGeom[i] % 1, 0) + + // verify that visualGeom is never outside the idealGeom + verify(visualGeom[0] >= idealGeom[0]) + verify(visualGeom[1] >= idealGeom[1]) + verify(visualGeom[2] <= idealGeom[2]) + verify(visualGeom[3] <= idealGeom[3]) + idealGeom[0] = idealGeom[2] + sp + idealGeom[2] = idealGeom[0] + rectWidth + } + idealGeom[1] = idealGeom[3] + idealGeom[3] = idealGeom[1] + rectHeight + } + + layout.destroy() + } } } |
