summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/layouts/qquicklayout.cpp11
-rw-r--r--src/layouts/qquicklayout_p.h6
-rw-r--r--src/layouts/qquicklinearlayout.cpp5
-rw-r--r--tests/auto/controls/data/tst_rowlayout.qml67
4 files changed, 87 insertions, 2 deletions
diff --git a/src/layouts/qquicklayout.cpp b/src/layouts/qquicklayout.cpp
index 7f80fa8c2..964c20015 100644
--- a/src/layouts/qquicklayout.cpp
+++ b/src/layouts/qquicklayout.cpp
@@ -62,7 +62,8 @@ QQuickLayoutAttached::QQuickLayoutAttached(QObject *parent)
m_fillHeight(false),
m_isFillWidthSet(false),
m_isFillHeightSet(false),
- m_changesNotificationEnabled(true)
+ m_changesNotificationEnabled(true),
+ m_alignment(0)
{
}
@@ -161,6 +162,14 @@ void QQuickLayoutAttached::setColumn(int column)
m_column = column;
}
+
+/*!
+ \qmlproperty Qt.Alignment Layout::alignment
+
+ This property allows you to specify the alignment of an item within the cell(s) it occupies.
+
+ The default value is \c 0, which means it will be \c{Qt.AlignVCenter | Qt.AlignLeft}
+*/
void QQuickLayoutAttached::invalidateItem()
{
quickLayoutDebug() << "QQuickLayoutAttached::invalidateItem";
diff --git a/src/layouts/qquicklayout_p.h b/src/layouts/qquicklayout_p.h
index 26c063463..bf9b007fa 100644
--- a/src/layouts/qquicklayout_p.h
+++ b/src/layouts/qquicklayout_p.h
@@ -118,6 +118,7 @@ class QQuickLayoutAttached : public QObject
Q_PROPERTY(int column READ column WRITE setColumn)
Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan)
Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan)
+ Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
public:
QQuickLayoutAttached(QObject *object);
@@ -160,6 +161,9 @@ public:
int columnSpan() const { return m_columnSpan; }
void setColumnSpan(int span) { m_columnSpan = span; }
+ Qt::Alignment alignment() const { return m_alignment; }
+ void setAlignment (Qt::Alignment align) { m_alignment = align; }
+
bool setChangesNotificationEnabled(bool enabled)
{
const bool old = m_changesNotificationEnabled;
@@ -199,7 +203,9 @@ private:
unsigned m_fillHeight : 1;
unsigned m_isFillWidthSet : 1;
unsigned m_isFillHeightSet : 1;
+
unsigned m_changesNotificationEnabled : 1;
+ Qt::Alignment m_alignment;
friend class QQuickLayout;
};
diff --git a/src/layouts/qquicklinearlayout.cpp b/src/layouts/qquicklinearlayout.cpp
index c3e01d6c2..37f8d5bfc 100644
--- a/src/layouts/qquicklinearlayout.cpp
+++ b/src/layouts/qquicklinearlayout.cpp
@@ -539,6 +539,7 @@ void QQuickGridLayout::insertLayoutItems()
foreach (QQuickItem *child, childItems()) {
if (child->isVisible()) {
+ Qt::Alignment alignment = 0;
QQuickLayoutAttached *info = attachedLayoutObject(child, false);
// Will skip Repeater among other things
@@ -580,6 +581,8 @@ void QQuickGridLayout::insertLayoutItems()
rowSpan < 1 ? rowSpan : columnSpan);
return;
}
+
+ alignment = info->alignment();
}
Q_ASSERT(columnSpan >= 1);
@@ -627,7 +630,7 @@ void QQuickGridLayout::insertLayoutItems()
}
column = nextColumn;
row = nextRow;
- QQuickGridLayoutItem *layoutItem = new QQuickGridLayoutItem(child, row, column, rowSpan, columnSpan);
+ QQuickGridLayoutItem *layoutItem = new QQuickGridLayoutItem(child, row, column, rowSpan, columnSpan, alignment);
d->engine.insertItem(layoutItem, -1);
}
diff --git a/tests/auto/controls/data/tst_rowlayout.qml b/tests/auto/controls/data/tst_rowlayout.qml
index c99d01248..05845215c 100644
--- a/tests/auto/controls/data/tst_rowlayout.qml
+++ b/tests/auto/controls/data/tst_rowlayout.qml
@@ -40,6 +40,7 @@
import QtQuick 2.1
import QtTest 1.0
+import QtQuick.Layouts 1.0
Item {
id: container
@@ -244,5 +245,71 @@ Item {
verify(col.row.counter <= 2);
col.destroy()
}
+
+ Component {
+ id: layout_alignment_Component
+ GridLayout {
+ columns: 2
+ columnSpacing: 0
+ rowSpacing: 0
+ Rectangle {
+ // First one should auto position itself at (0,0)
+ color: "red"
+ Layout.preferredWidth: 20
+ Layout.preferredHeight: 20
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ }
+ Rectangle {
+ // (0,1)
+ color: "red"
+ Layout.preferredWidth: 20
+ Layout.preferredHeight: 20
+ Layout.alignment: Qt.AlignBottom
+ }
+ Rectangle {
+ // (1,0)
+ color: "red"
+ Layout.preferredWidth: 20
+ Layout.preferredHeight: 20
+ Layout.alignment: Qt.AlignRight
+ }
+ Rectangle {
+ // (1,1)
+ color: "red"
+ Layout.preferredWidth: 10
+ Layout.preferredHeight: 10
+ Layout.alignment: Qt.AlignHCenter | Qt.AlignTop
+ }
+ Rectangle {
+ // (2,0)
+ color: "red"
+ Layout.preferredWidth: 30
+ Layout.preferredHeight: 30
+ Layout.alignment: Qt.AlignRight
+ Layout.columnSpan: 2
+ }
+ }
+ }
+
+ function itemRect(item)
+ {
+ return [item.x, item.y, item.width, item.height];
+ }
+
+ function test_alignment()
+ {
+ var layout = layout_alignment_Component.createObject(container);
+ layout.width = 60;
+ layout.height = 90;
+
+ compare(itemRect(layout.children[0]), [ 0, 0, 40, 40]);
+ compare(itemRect(layout.children[1]), [40, 20, 20, 20]);
+ compare(itemRect(layout.children[2]), [20, 40, 20, 20]);
+ compare(itemRect(layout.children[3]), [45, 40, 10, 10]);
+ compare(itemRect(layout.children[4]), [30, 60, 30, 30]);
+
+ layout.destroy();
+ }
}
}