diff options
Diffstat (limited to 'src/quicklayouts/qquicklayout_p.h')
-rw-r--r-- | src/quicklayouts/qquicklayout_p.h | 170 |
1 files changed, 96 insertions, 74 deletions
diff --git a/src/quicklayouts/qquicklayout_p.h b/src/quicklayouts/qquicklayout_p.h index 74eb348928..f0ccc6dbf5 100644 --- a/src/quicklayouts/qquicklayout_p.h +++ b/src/quicklayouts/qquicklayout_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Quick Layouts module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QQUICKLAYOUT_P_H #define QQUICKLAYOUT_P_H @@ -53,10 +17,13 @@ #include <QPointer> #include <QQuickItem> +#include <QtCore/qflags.h> + #include <QtQuickLayouts/private/qquicklayoutglobal_p.h> #include <private/qquickitem_p.h> #include <QtQuick/private/qquickitemchangelistener_p.h> #include <QtGui/private/qlayoutpolicy_p.h> +#include <QtGui/qguiapplication.h> QT_BEGIN_NAMESPACE @@ -64,7 +31,7 @@ class QQuickLayoutAttached; Q_DECLARE_LOGGING_CATEGORY(lcQuickLayouts) class QQuickLayoutPrivate; -class Q_QUICKLAYOUT_PRIVATE_EXPORT QQuickLayout : public QQuickItem, public QQuickItemChangeListener +class Q_QUICKLAYOUTS_EXPORT QQuickLayout : public QQuickItem, public QQuickItemChangeListener { Q_OBJECT @@ -81,7 +48,14 @@ public: NSizes }; - explicit QQuickLayout(QQuickLayoutPrivate &dd, QQuickItem *parent = 0); + enum EnsureLayoutItemsUpdatedOption { + Recursive = 0b001, + ApplySizeHints = 0b010 + }; + + Q_DECLARE_FLAGS(EnsureLayoutItemsUpdatedOptions, EnsureLayoutItemsUpdatedOption) + + explicit QQuickLayout(QQuickLayoutPrivate &dd, QQuickItem *parent = nullptr); ~QQuickLayout(); static QQuickLayoutAttached *qmlAttachedProperties(QObject *object); @@ -90,9 +64,12 @@ public: void componentComplete() override; virtual QSizeF sizeHint(Qt::SizeHint whichSizeHint) const = 0; virtual void setAlignment(QQuickItem *item, Qt::Alignment align) = 0; - virtual void invalidate(QQuickItem * childItem = 0); + virtual void setStretchFactor(QQuickItem *item, int stretchFactor, Qt::Orientation orient) = 0; + + virtual void invalidate(QQuickItem * childItem = nullptr); virtual void updateLayoutItems() = 0; - void ensureLayoutItemsUpdated() const; + + void ensureLayoutItemsUpdated(EnsureLayoutItemsUpdatedOptions options = {}) const; // iterator virtual QQuickItem *itemAt(int index) const = 0; @@ -102,7 +79,7 @@ public: static void effectiveSizeHints_helper(QQuickItem *item, QSizeF *cachedSizeHints, QQuickLayoutAttached **info, bool useFallbackToWidthOrHeight); static QLayoutPolicy::Policy effectiveSizePolicy_helper(QQuickItem *item, Qt::Orientation orientation, QQuickLayoutAttached *info); - bool shouldIgnoreItem(QQuickItem *child, QQuickLayoutAttached *&info, QSizeF *sizeHints) const; + bool shouldIgnoreItem(QQuickItem *child) const; void checkAnchors(QQuickItem *item) const; void itemChange(ItemChange change, const ItemChangeData &value) override; @@ -121,6 +98,8 @@ public: void itemDestroyed(QQuickItem *item) override; void itemVisibilityChanged(QQuickItem *item) override; + void maybeSubscribeToBaseLineOffsetChanges(QQuickItem *item); + Q_INVOKABLE void _q_dumpLayoutTree() const; void dumpLayoutTreeRecursive(int level, QString &buf) const; @@ -133,7 +112,7 @@ protected: NOrientations }; -protected slots: +protected Q_SLOTS: void invalidateSenderItem(); private: @@ -145,15 +124,17 @@ private: friend class QQuickLayoutAttached; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QQuickLayout::EnsureLayoutItemsUpdatedOptions) class QQuickLayoutPrivate : public QQuickItemPrivate { Q_DECLARE_PUBLIC(QQuickLayout) public: - QQuickLayoutPrivate() : m_dirty(true), m_dirtyArrangement(true), m_isReady(false), m_disableRearrange(true), m_hasItemChangeListeners(false) {} - - qreal getImplicitWidth() const override; - qreal getImplicitHeight() const override; + QQuickLayoutPrivate() : m_dirty(true) + , m_dirtyArrangement(true) + , m_isReady(false) + , m_disableRearrange(true) + , m_hasItemChangeListeners(false) {} void applySizeHints() const; @@ -173,62 +154,77 @@ protected: unsigned m_isReady : 1; unsigned m_disableRearrange : 1; unsigned m_hasItemChangeListeners : 1; // if false, we don't need to remove its item change listeners... - mutable QSet<QQuickItem *> m_ignoredItems; }; -class QQuickLayoutAttached : public QObject +class Q_QUICKLAYOUTS_EXPORT QQuickLayoutAttached : public QObject { Q_OBJECT - Q_PROPERTY(qreal minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged) - Q_PROPERTY(qreal minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged) - Q_PROPERTY(qreal preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(qreal preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) - Q_PROPERTY(qreal maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged) - Q_PROPERTY(qreal maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged) - Q_PROPERTY(bool fillHeight READ fillHeight WRITE setFillHeight NOTIFY fillHeightChanged) - Q_PROPERTY(bool fillWidth READ fillWidth WRITE setFillWidth NOTIFY fillWidthChanged) - Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged) - Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged) - Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan NOTIFY rowSpanChanged) - Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan NOTIFY columnSpanChanged) - Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged) - - Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged) - Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin RESET resetLeftMargin NOTIFY leftMarginChanged) - Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin RESET resetTopMargin NOTIFY topMarginChanged) - Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin RESET resetRightMargin NOTIFY rightMarginChanged) - Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin RESET resetBottomMargin NOTIFY bottomMarginChanged) + Q_PROPERTY(qreal minimumWidth READ minimumWidth WRITE setMinimumWidth NOTIFY minimumWidthChanged FINAL) + Q_PROPERTY(qreal minimumHeight READ minimumHeight WRITE setMinimumHeight NOTIFY minimumHeightChanged FINAL) + Q_PROPERTY(qreal preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged FINAL) + Q_PROPERTY(qreal preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged FINAL) + Q_PROPERTY(qreal maximumWidth READ maximumWidth WRITE setMaximumWidth NOTIFY maximumWidthChanged FINAL) + Q_PROPERTY(qreal maximumHeight READ maximumHeight WRITE setMaximumHeight NOTIFY maximumHeightChanged FINAL) + Q_PROPERTY(bool fillHeight READ fillHeight WRITE setFillHeight NOTIFY fillHeightChanged FINAL) + Q_PROPERTY(bool fillWidth READ fillWidth WRITE setFillWidth NOTIFY fillWidthChanged FINAL) + Q_PROPERTY(int row READ row WRITE setRow NOTIFY rowChanged FINAL) + Q_PROPERTY(int column READ column WRITE setColumn NOTIFY columnChanged FINAL) + Q_PROPERTY(int rowSpan READ rowSpan WRITE setRowSpan NOTIFY rowSpanChanged FINAL) + Q_PROPERTY(int columnSpan READ columnSpan WRITE setColumnSpan NOTIFY columnSpanChanged FINAL) + Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged FINAL) + Q_PROPERTY(int horizontalStretchFactor READ horizontalStretchFactor WRITE setHorizontalStretchFactor NOTIFY horizontalStretchFactorChanged FINAL) + Q_PROPERTY(int verticalStretchFactor READ verticalStretchFactor WRITE setVerticalStretchFactor NOTIFY verticalStretchFactorChanged FINAL) + + Q_PROPERTY(qreal margins READ margins WRITE setMargins NOTIFY marginsChanged FINAL) + Q_PROPERTY(qreal leftMargin READ leftMargin WRITE setLeftMargin RESET resetLeftMargin NOTIFY leftMarginChanged FINAL) + Q_PROPERTY(qreal topMargin READ topMargin WRITE setTopMargin RESET resetTopMargin NOTIFY topMarginChanged FINAL) + Q_PROPERTY(qreal rightMargin READ rightMargin WRITE setRightMargin RESET resetRightMargin NOTIFY rightMarginChanged FINAL) + Q_PROPERTY(qreal bottomMargin READ bottomMargin WRITE setBottomMargin RESET resetBottomMargin NOTIFY bottomMarginChanged FINAL) public: QQuickLayoutAttached(QObject *object); qreal minimumWidth() const { return !m_isMinimumWidthSet ? sizeHint(Qt::MinimumSize, Qt::Horizontal) : m_minimumWidth; } void setMinimumWidth(qreal width); + bool isMinimumWidthSet() const {return m_isMinimumWidthSet; } qreal minimumHeight() const { return !m_isMinimumHeightSet ? sizeHint(Qt::MinimumSize, Qt::Vertical) : m_minimumHeight; } void setMinimumHeight(qreal height); + bool isMinimumHeightSet() const {return m_isMinimumHeightSet; } qreal preferredWidth() const { return m_preferredWidth; } void setPreferredWidth(qreal width); + bool isPreferredWidthSet() const {return m_preferredWidth > -1; } qreal preferredHeight() const { return m_preferredHeight; } void setPreferredHeight(qreal width); + bool isPreferredHeightSet() const {return m_preferredHeight > -1; } qreal maximumWidth() const { return !m_isMaximumWidthSet ? sizeHint(Qt::MaximumSize, Qt::Horizontal) : m_maximumWidth; } void setMaximumWidth(qreal width); + bool isMaximumWidthSet() const {return m_isMaximumWidthSet; } qreal maximumHeight() const { return !m_isMaximumHeightSet ? sizeHint(Qt::MaximumSize, Qt::Vertical) : m_maximumHeight; } void setMaximumHeight(qreal height); + bool isMaximumHeightSet() const {return m_isMaximumHeightSet; } void setMinimumImplicitSize(const QSizeF &sz); void setMaximumImplicitSize(const QSizeF &sz); - bool fillWidth() const { return m_fillWidth; } + bool fillWidth() const { + if (auto *itemPriv = itemForSizePolicy(m_isFillWidthSet)) + return (itemPriv->sizePolicy().horizontalPolicy() == QLayoutPolicy::Preferred); + return m_fillWidth; + } void setFillWidth(bool fill); bool isFillWidthSet() const { return m_isFillWidthSet; } - bool fillHeight() const { return m_fillHeight; } + bool fillHeight() const { + if (auto *itemPriv = itemForSizePolicy(m_isFillHeightSet)) + return (itemPriv->sizePolicy().verticalPolicy() == QLayoutPolicy::Preferred); + return m_fillHeight; + } void setFillHeight(bool fill); bool isFillHeightSet() const { return m_isFillHeightSet; } @@ -246,25 +242,38 @@ public: Qt::Alignment alignment() const { return m_alignment; } void setAlignment(Qt::Alignment align); + bool isAlignmentSet() const {return m_isAlignmentSet; } + + int horizontalStretchFactor() const { return m_horizontalStretch; } + void setHorizontalStretchFactor(int stretchFactor); + bool isHorizontalStretchFactorSet() const { return m_horizontalStretch > -1; } + int verticalStretchFactor() const { return m_verticalStretch; } + void setVerticalStretchFactor(int stretchFactor); + bool isVerticalStretchFactorSet() const { return m_verticalStretch > -1; } qreal margins() const { return m_defaultMargins; } void setMargins(qreal m); + bool isMarginsSet() const { return m_isMarginsSet; } qreal leftMargin() const { return m_isLeftMarginSet ? m_margins.left() : m_defaultMargins; } void setLeftMargin(qreal m); void resetLeftMargin(); + bool isLeftMarginSet() const { return m_isLeftMarginSet; } qreal topMargin() const { return m_isTopMarginSet ? m_margins.top() : m_defaultMargins; } void setTopMargin(qreal m); void resetTopMargin(); + bool isTopMarginSet() const {return m_isTopMarginSet; } qreal rightMargin() const { return m_isRightMarginSet ? m_margins.right() : m_defaultMargins; } void setRightMargin(qreal m); void resetRightMargin(); + bool isRightMarginSet() const { return m_isRightMarginSet; } qreal bottomMargin() const { return m_isBottomMarginSet ? m_margins.bottom() : m_defaultMargins; } void setBottomMargin(qreal m); void resetBottomMargin(); + bool isBottomMarginSet() const { return m_isBottomMarginSet; } QMarginsF qMargins() const { return QMarginsF(leftMargin(), topMargin(), rightMargin(), bottomMargin()); @@ -303,7 +312,16 @@ public: return false; } -signals: + QQuickItemPrivate *itemForSizePolicy(bool isFillSet) const + { + QQuickItemPrivate *itemPriv = nullptr; + if (!isFillSet && qobject_cast<QQuickItem *>(item()) && + QGuiApplication::testAttribute(Qt::AA_QtQuickUseDefaultSizePolicy)) + itemPriv = QQuickItemPrivate::get(item()); + return itemPriv; + } + +Q_SIGNALS: void minimumWidthChanged(); void minimumHeightChanged(); void preferredWidthChanged(); @@ -322,6 +340,8 @@ signals: void rowSpanChanged(); void columnSpanChanged(); void alignmentChanged(); + void horizontalStretchFactorChanged(); + void verticalStretchFactorChanged(); private: void invalidateItem(); @@ -358,11 +378,15 @@ private: unsigned m_isMaximumWidthSet : 1; unsigned m_isMaximumHeightSet : 1; unsigned m_changesNotificationEnabled : 1; + unsigned m_isMarginsSet : 1; unsigned m_isLeftMarginSet : 1; unsigned m_isTopMarginSet : 1; unsigned m_isRightMarginSet : 1; unsigned m_isBottomMarginSet : 1; + unsigned m_isAlignmentSet : 1; Qt::Alignment m_alignment; + int m_horizontalStretch; + int m_verticalStretch; friend class QQuickLayout; }; @@ -373,6 +397,4 @@ inline QQuickLayoutAttached *attachedLayoutObject(QQuickItem *item, bool create QT_END_NAMESPACE -QML_DECLARE_TYPE(QQuickLayout) - #endif // QQUICKLAYOUT_P_H |