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 | |
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')
-rw-r--r-- | src/declarative/items/qsgpositioners.cpp | 60 | ||||
-rw-r--r-- | src/declarative/items/qsgpositioners_p.h | 12 |
2 files changed, 63 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) diff --git a/src/declarative/items/qsgpositioners_p.h b/src/declarative/items/qsgpositioners_p.h index a23c9d446c..8f9d3eb310 100644 --- a/src/declarative/items/qsgpositioners_p.h +++ b/src/declarative/items/qsgpositioners_p.h @@ -155,6 +155,8 @@ class Q_AUTOTEST_EXPORT QSGGrid : public QSGBasePositioner Q_OBJECT Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) + Q_PROPERTY(int rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged) + Q_PROPERTY(int columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged) Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged) Q_PROPERTY(Qt::LayoutDirection effectiveLayoutDirection READ effectiveLayoutDirection NOTIFY effectiveLayoutDirectionChanged) @@ -168,6 +170,12 @@ public: int columns() const {return m_columns;} void setColumns(const int columns); + int rowSpacing() const { return m_rowSpacing; } + void setRowSpacing(int); + + int columnSpacing() const { return m_columnSpacing; } + void setColumnSpacing(int); + Q_ENUMS(Flow) enum Flow { LeftToRight, TopToBottom }; Flow flow() const; @@ -183,6 +191,8 @@ Q_SIGNALS: void flowChanged(); void layoutDirectionChanged(); void effectiveLayoutDirectionChanged(); + void rowSpacingChanged(); + void columnSpacingChanged(); protected: virtual void doPositioning(QSizeF *contentSize); @@ -191,6 +201,8 @@ protected: private: int m_rows; int m_columns; + int m_rowSpacing; + int m_columnSpacing; Flow m_flow; Q_DISABLE_COPY(QSGGrid) }; |