diff options
| -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() + } } } |
