aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/declarative/whatsnew.qdoc2
-rw-r--r--src/declarative/items/qsgpositioners.cpp60
-rw-r--r--src/declarative/items/qsgpositioners_p.h12
-rw-r--r--tests/auto/declarative/qsgpositioners/data/grid-row-column-spacing.qml43
-rw-r--r--tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp34
5 files changed, 142 insertions, 9 deletions
diff --git a/doc/src/declarative/whatsnew.qdoc b/doc/src/declarative/whatsnew.qdoc
index d3db1346ea..3707d41cd9 100644
--- a/doc/src/declarative/whatsnew.qdoc
+++ b/doc/src/declarative/whatsnew.qdoc
@@ -52,6 +52,8 @@ The Loader element now only emits the \c sourceChanged signal when the source is
\c sourceComponentChanged signal when the sourceComponent is changed. It used to emit both signals when one
of the properties was changed.
+Grid now has rowSpacing and columnSpacing properties.
+
\section2 QtQuick 1 is now a separate library and module
Writing C++ applications using QtQuick 1 specific API, i.e. QDeclarativeView or QDeclarativeItem
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)
};
diff --git a/tests/auto/declarative/qsgpositioners/data/grid-row-column-spacing.qml b/tests/auto/declarative/qsgpositioners/data/grid-row-column-spacing.qml
new file mode 100644
index 0000000000..49bbd337e7
--- /dev/null
+++ b/tests/auto/declarative/qsgpositioners/data/grid-row-column-spacing.qml
@@ -0,0 +1,43 @@
+import QtQuick 2.0
+
+Item {
+ width: 640
+ height: 480
+ Grid {
+ objectName: "grid"
+ columns: 3
+ spacing: 4
+ rowSpacing: 7
+ columnSpacing: 11
+ Rectangle {
+ objectName: "one"
+ color: "red"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "two"
+ color: "green"
+ width: 20
+ height: 50
+ }
+ Rectangle {
+ objectName: "three"
+ color: "blue"
+ width: 50
+ height: 20
+ }
+ Rectangle {
+ objectName: "four"
+ color: "cyan"
+ width: 50
+ height: 50
+ }
+ Rectangle {
+ objectName: "five"
+ color: "magenta"
+ width: 10
+ height: 10
+ }
+ }
+}
diff --git a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
index 3b2a504ff4..497f511335 100644
--- a/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
+++ b/tests/auto/declarative/qsgpositioners/tst_qsgpositioners.cpp
@@ -76,6 +76,7 @@ private slots:
void test_grid_topToBottom();
void test_grid_rightToLeft();
void test_grid_spacing();
+ void test_grid_row_column_spacing();
void test_grid_animated();
void test_grid_animated_rightToLeft();
void test_grid_zero_columns();
@@ -622,6 +623,39 @@ void tst_qsgpositioners::test_grid_spacing()
delete canvas;
}
+void tst_qsgpositioners::test_grid_row_column_spacing()
+{
+ QSGView *canvas = createView(SRCDIR "/data/grid-row-column-spacing.qml");
+
+ QSGRectangle *one = canvas->rootObject()->findChild<QSGRectangle*>("one");
+ QVERIFY(one != 0);
+ QSGRectangle *two = canvas->rootObject()->findChild<QSGRectangle*>("two");
+ QVERIFY(two != 0);
+ QSGRectangle *three = canvas->rootObject()->findChild<QSGRectangle*>("three");
+ QVERIFY(three != 0);
+ QSGRectangle *four = canvas->rootObject()->findChild<QSGRectangle*>("four");
+ QVERIFY(four != 0);
+ QSGRectangle *five = canvas->rootObject()->findChild<QSGRectangle*>("five");
+ QVERIFY(five != 0);
+
+ QCOMPARE(one->x(), 0.0);
+ QCOMPARE(one->y(), 0.0);
+ QCOMPARE(two->x(), 61.0);
+ QCOMPARE(two->y(), 0.0);
+ QCOMPARE(three->x(), 92.0);
+ QCOMPARE(three->y(), 0.0);
+ QCOMPARE(four->x(), 0.0);
+ QCOMPARE(four->y(), 57.0);
+ QCOMPARE(five->x(), 61.0);
+ QCOMPARE(five->y(), 57.0);
+
+ QSGItem *grid = canvas->rootObject()->findChild<QSGItem*>("grid");
+ QCOMPARE(grid->width(), 142.0);
+ QCOMPARE(grid->height(), 107.0);
+
+ delete canvas;
+}
+
void tst_qsgpositioners::test_grid_animated()
{
QSGView *canvas = createView(SRCDIR "/data/grid-animated.qml");