aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicklayouts
diff options
context:
space:
mode:
authorMatthias Rauter <matthias.rauter@qt.io>2023-03-16 14:15:44 +0100
committerMatthias Rauter <matthias.rauter@qt.io>2023-06-01 14:10:53 +0200
commit9982f16eadac1a252353a31972b03e3d3449f815 (patch)
tree9025bf21ef7de97489e5e302489b0b45d380b897 /src/quicklayouts
parentbf712068978ff93f992d5fc8b2c779487828e1b8 (diff)
Add uniformCellWidths and uniformCellHeights to QuickLayout
Some users wish to make layouts with uniform column widths or uniform row heights, ignoring the sizeHints of individual items. This patch enables this mode in the QuickLayout. [ChangeLog][Layouts] Added uniformCellSizes properties to QuickLayout Change-Id: I25777d4d47d8d943f69e8f829a6d9602abccad92 Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quicklayouts')
-rw-r--r--src/quicklayouts/qquicklinearlayout.cpp112
-rw-r--r--src/quicklayouts/qquicklinearlayout_p.h18
2 files changed, 130 insertions, 0 deletions
diff --git a/src/quicklayouts/qquicklinearlayout.cpp b/src/quicklayouts/qquicklinearlayout.cpp
index b34815e449..31c1857d9f 100644
--- a/src/quicklayouts/qquicklinearlayout.cpp
+++ b/src/quicklayouts/qquicklinearlayout.cpp
@@ -622,6 +622,75 @@ void QQuickGridLayout::setFlow(QQuickGridLayout::Flow flow)
emit flowChanged();
}
+/*!
+ \qmlproperty bool GridLayout::uniformCellWidths
+ \since QtQuick.Layouts 6.6
+
+ If this property is set to \c true, the layout will force all cells to have
+ a uniform width. The layout aims to respect
+ \l{Layout::minimumWidth}{Layout.minimumWidth},
+ \l{Layout::preferredWidth}{Layout.preferredWidth} and
+ \l{Layout::maximumWidth}{Layout.maximumWidth} in this mode but might make
+ compromisses to fullfill the requirements of all items.
+
+ Default value is \c false.
+
+ \note This API is considered tech preview and may change or be removed in future versions of
+ Qt.
+
+ \sa GridLayout::uniformCellHeights, RowLayout::uniformCellSizes, ColumnLayout::uniformCellSizes
+*/
+bool QQuickGridLayout::uniformCellWidths() const
+{
+ Q_D(const QQuickGridLayout);
+ return d->engine.uniformCellWidths();
+}
+
+void QQuickGridLayout::setUniformCellWidths(bool uniformCellWidths)
+{
+ Q_D(QQuickGridLayout);
+ if (d->engine.uniformCellWidths() == uniformCellWidths)
+ return;
+ d->engine.setUniformCellWidths(uniformCellWidths);
+ invalidate();
+ emit uniformCellWidthsChanged();
+}
+
+/*!
+ \qmlproperty bool GridLayout::uniformCellHeights
+ \since QtQuick.Layouts 6.6
+
+ If this property is set to \c true, the layout will force all cells to have an
+ uniform Height. The layout aims to respect
+ \l{Layout::minimumHeight}{Layout.minimumHeight},
+ \l{Layout::preferredHeight}{Layout.preferredHeight} and
+ \l{Layout::maximumHeight}{Layout.maximumHeight} in this mode but might make
+ compromisses to fullfill the requirements of all items.
+
+ Default value is \c false.
+
+ \note This API is considered tech preview and may change or be removed in future versions of
+ Qt.
+
+ \sa GridLayout::uniformCellWidths, RowLayout::uniformCellSizes, ColumnLayout::uniformCellSizes
+*/
+bool QQuickGridLayout::uniformCellHeights() const
+{
+ Q_D(const QQuickGridLayout);
+ return d->engine.uniformCellHeights();
+}
+
+void QQuickGridLayout::setUniformCellHeights(bool uniformCellHeights)
+{
+ Q_D(QQuickGridLayout);
+ if (d->engine.uniformCellHeights() == uniformCellHeights)
+ return;
+ d->engine.setUniformCellHeights(uniformCellHeights);
+ invalidate();
+ emit uniformCellHeightsChanged();
+}
+
+
void QQuickGridLayout::insertLayoutItems()
{
Q_D(QQuickGridLayout);
@@ -796,6 +865,49 @@ QQuickLinearLayout::QQuickLinearLayout(Qt::Orientation orientation,
\sa GridLayout::layoutDirection, RowLayout::layoutDirection
*/
+/*!
+ \qmlproperty bool RowLayout::uniformCellSizes
+ \since QtQuick.Layouts 6.6
+
+ If this property is set to \c true, the layout will force all cells to have
+ a uniform size.
+
+ \note This API is considered tech preview and may change or be removed in future versions of
+ Qt.
+
+ \sa GridLayout::uniformCellWidths, GridLayout::uniformCellHeights, ColumnLayout::uniformCellSizes
+*/
+/*!
+ \qmlproperty bool ColumnLayout::uniformCellSizes
+ \since QtQuick.Layouts 6.6
+
+ If this property is set to \c true, the layout will force all cells to have
+ a uniform size.
+
+ \note This API is considered tech preview and may change or be removed in future versions of
+ Qt.
+
+ \sa GridLayout::uniformCellWidths, GridLayout::uniformCellHeights, RowLayout::uniformCellSizes
+*/
+bool QQuickLinearLayout::uniformCellSizes() const
+{
+ Q_D(const QQuickLinearLayout);
+ Q_ASSERT(d->engine.uniformCellWidths() == d->engine.uniformCellHeights());
+ return d->engine.uniformCellWidths();
+}
+
+void QQuickLinearLayout::setUniformCellSizes(bool uniformCellSizes)
+{
+ Q_D(QQuickLinearLayout);
+ Q_ASSERT(d->engine.uniformCellWidths() == d->engine.uniformCellHeights());
+ if (d->engine.uniformCellHeights() == uniformCellSizes)
+ return;
+ d->engine.setUniformCellWidths(uniformCellSizes);
+ d->engine.setUniformCellHeights(uniformCellSizes);
+ invalidate();
+ emit uniformCellSizesChanged();
+}
+
/*!
\qmlproperty real RowLayout::spacing
diff --git a/src/quicklayouts/qquicklinearlayout_p.h b/src/quicklayouts/qquicklinearlayout_p.h
index a29106e8a2..461b7b1e66 100644
--- a/src/quicklayouts/qquicklinearlayout_p.h
+++ b/src/quicklayouts/qquicklinearlayout_p.h
@@ -120,6 +120,11 @@ class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickGridLayout : public QQuickGridLayoutBa
Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged)
+ Q_PROPERTY(bool uniformCellWidths READ uniformCellWidths WRITE setUniformCellWidths
+ NOTIFY uniformCellWidthsChanged REVISION(6, 6))
+ Q_PROPERTY(bool uniformCellHeights READ uniformCellHeights WRITE setUniformCellHeights
+ NOTIFY uniformCellHeightsChanged REVISION(6, 6))
+
QML_NAMED_ELEMENT(GridLayout)
QML_ADDED_IN_VERSION(1, 0)
public:
@@ -139,6 +144,11 @@ public:
Flow flow() const;
void setFlow(Flow flow);
+ bool uniformCellWidths() const;
+ void setUniformCellWidths(bool uniformCellWidths);
+ bool uniformCellHeights() const;
+ void setUniformCellHeights(bool uniformCellHeights);
+
void insertLayoutItems() override;
Q_SIGNALS:
@@ -149,6 +159,9 @@ Q_SIGNALS:
void rowsChanged();
void flowChanged();
+
+ Q_REVISION(6, 6) void uniformCellWidthsChanged();
+ Q_REVISION(6, 6) void uniformCellHeightsChanged();
private:
Q_DECLARE_PRIVATE(QQuickGridLayout)
};
@@ -174,17 +187,22 @@ class Q_QUICKLAYOUTS_PRIVATE_EXPORT QQuickLinearLayout : public QQuickGridLayout
{
Q_OBJECT
Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged)
+ Q_PROPERTY(bool uniformCellSizes READ uniformCellSizes WRITE setUniformCellSizes
+ NOTIFY uniformCellSizesChanged REVISION(6, 6))
public:
explicit QQuickLinearLayout(Qt::Orientation orientation,
QQuickItem *parent = nullptr);
void insertLayoutItem(QQuickItem *item);
qreal spacing() const;
void setSpacing(qreal spacing);
+ bool uniformCellSizes() const;
+ void setUniformCellSizes(bool uniformCellSizes);
void insertLayoutItems() override;
Q_SIGNALS:
void spacingChanged();
+ Q_REVISION(6, 6) void uniformCellSizesChanged();
private:
Q_DECLARE_PRIVATE(QQuickLinearLayout)
};