diff options
author | Glenn Watson <glenn.watson@nokia.com> | 2011-08-10 13:51:32 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-08-10 07:34:18 +0200 |
commit | 2601011f1c0168f080c488be09c888042812f7cb (patch) | |
tree | 0750fe5651ded96b5a473acd067b2156e0c77dee /src/declarative/items/qsgpositioners.cpp | |
parent | 108c94807a22740d0ecae369846063b4596d3788 (diff) |
Add support for individual row and column spacing to Grid object.
Add rowSpacing and columnSpacing properties to QML Grid object. If
these are specified, use them when laying out the grid. If they are
not specified, default to using the spacing property that was
previously used, so it is backwards compatible.
Task-number: QTBUG-11876
Change-Id: I5c809e89fe124d8d5ea1667b273f19e2c37ff18a
Reviewed-on: http://codereview.qt.nokia.com/2797
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src/declarative/items/qsgpositioners.cpp')
-rw-r--r-- | src/declarative/items/qsgpositioners.cpp | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/src/declarative/items/qsgpositioners.cpp b/src/declarative/items/qsgpositioners.cpp index 5ebf2d7a0d..d500afd81c 100644 --- a/src/declarative/items/qsgpositioners.cpp +++ b/src/declarative/items/qsgpositioners.cpp @@ -780,7 +780,7 @@ void QSGRow::reportConflictingAnchors() \sa rows, columns */ QSGGrid::QSGGrid(QSGItem *parent) : - QSGBasePositioner(Both, parent), m_rows(-1), m_columns(-1), m_flow(LeftToRight) + QSGBasePositioner(Both, parent), m_rows(-1), m_columns(-1), m_rowSpacing(-1), m_columnSpacing(-1), m_flow(LeftToRight) { } @@ -848,6 +848,40 @@ void QSGGrid::setFlow(Flow flow) } /*! + \qmlproperty int QtQuick2::Grid::rowSpacing + + This property holds the spacing in pixels between rows. + + \sa columnSpacing + \since QtQuick2.0 +*/ +void QSGGrid::setRowSpacing(const int rowSpacing) +{ + if (rowSpacing == m_rowSpacing) + return; + m_rowSpacing = rowSpacing; + prePositioning(); + emit rowSpacingChanged(); +} + +/*! + \qmlproperty int QtQuick2::Grid::columnSpacing + + This property holds the spacing in pixels between columns. + + \sa rowSpacing + \since QtQuick2.0 +*/ +void QSGGrid::setColumnSpacing(const int columnSpacing) +{ + if (columnSpacing == m_columnSpacing) + return; + m_columnSpacing = columnSpacing; + prePositioning(); + emit columnSpacingChanged(); +} + +/*! \qmlproperty enumeration QtQuick2::Grid::layoutDirection This property holds the layout direction of the layout. @@ -967,17 +1001,25 @@ void QSGGrid::doPositioning(QSizeF *contentSize) } } + int columnSpacing = m_columnSpacing; + if (columnSpacing == -1) + columnSpacing = spacing(); + + int rowSpacing = m_rowSpacing; + if (rowSpacing == -1) + rowSpacing = spacing(); + int widthSum = 0; for (int j=0; j < maxColWidth.size(); j++){ if (j) - widthSum += spacing(); + widthSum += columnSpacing; widthSum += maxColWidth[j]; } int heightSum = 0; for (int i=0; i < maxRowHeight.size(); i++){ if (i) - heightSum += spacing(); + heightSum += rowSpacing; heightSum += maxRowHeight[i]; } @@ -1008,13 +1050,13 @@ void QSGGrid::doPositioning(QSizeF *contentSize) if (m_flow == LeftToRight) { if (d->isLeftToRight()) - xoffset += maxColWidth[curCol]+spacing(); + xoffset += maxColWidth[curCol]+columnSpacing; else - xoffset -= maxColWidth[curCol]+spacing(); + xoffset -= maxColWidth[curCol]+columnSpacing; curCol++; curCol%=c; if (!curCol){ - yoffset += maxRowHeight[curRow]+spacing(); + yoffset += maxRowHeight[curRow]+rowSpacing; if (d->isLeftToRight()) xoffset = 0; else @@ -1024,14 +1066,14 @@ void QSGGrid::doPositioning(QSizeF *contentSize) break; } } else { - yoffset+=maxRowHeight[curRow]+spacing(); + yoffset+=maxRowHeight[curRow]+rowSpacing; curRow++; curRow%=r; if (!curRow){ if (d->isLeftToRight()) - xoffset += maxColWidth[curCol]+spacing(); + xoffset += maxColWidth[curCol]+columnSpacing; else - xoffset -= maxColWidth[curCol]+spacing(); + xoffset -= maxColWidth[curCol]+columnSpacing; yoffset=0; curCol++; if (curCol>=c) |