\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
\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)
{
}
}
/*!
+ \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.
}
}
+ 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];
}
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
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)
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)
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;
void flowChanged();
void layoutDirectionChanged();
void effectiveLayoutDirectionChanged();
+ void rowSpacingChanged();
+ void columnSpacingChanged();
protected:
virtual void doPositioning(QSizeF *contentSize);
private:
int m_rows;
int m_columns;
+ int m_rowSpacing;
+ int m_columnSpacing;
Flow m_flow;
Q_DISABLE_COPY(QSGGrid)
};
--- /dev/null
+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
+ }
+ }
+}
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();
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");