| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKLINEARLAYOUT_P_H |
| 5 | #define QQUICKLINEARLAYOUT_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtQuickLayouts/private/qquicklayoutglobal_p.h> |
| 19 | #include "qquicklayout_p.h" |
| 20 | #include "qquickgridlayoutengine_p.h" |
| 21 | |
| 22 | QT_BEGIN_NAMESPACE |
| 23 | |
| 24 | /********************************** |
| 25 | ** |
| 26 | ** QQuickGridLayoutBase |
| 27 | ** |
| 28 | **/ |
| 29 | class QQuickGridLayoutBasePrivate; |
| 30 | |
| 31 | class Q_QUICKLAYOUTS_EXPORT QQuickGridLayoutBase : public QQuickLayout |
| 32 | { |
| 33 | Q_OBJECT |
| 34 | |
| 35 | Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection |
| 36 | NOTIFY layoutDirectionChanged REVISION(1, 1)) |
| 37 | QML_ANONYMOUS |
| 38 | QML_ADDED_IN_VERSION(1, 1) |
| 39 | |
| 40 | public: |
| 41 | |
| 42 | QQuickGridLayoutBase(); |
| 43 | |
| 44 | explicit QQuickGridLayoutBase(QQuickGridLayoutBasePrivate &dd, |
| 45 | Qt::Orientation orientation, |
| 46 | QQuickItem *parent = nullptr); |
| 47 | |
| 48 | ~QQuickGridLayoutBase(); |
| 49 | void componentComplete() override; |
| 50 | void invalidate(QQuickItem *childItem = nullptr) override; |
| 51 | Qt::Orientation orientation() const; |
| 52 | void setOrientation(Qt::Orientation orientation); |
| 53 | QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override; |
| 54 | Qt::LayoutDirection layoutDirection() const; |
| 55 | void setLayoutDirection(Qt::LayoutDirection dir); |
| 56 | Qt::LayoutDirection effectiveLayoutDirection() const; |
| 57 | void setAlignment(QQuickItem *item, Qt::Alignment align) override; |
| 58 | void setStretchFactor(QQuickItem *item, int stretchFactor, Qt::Orientation orient) override; |
| 59 | |
| 60 | /* QQuickItemChangeListener */ |
| 61 | void itemDestroyed(QQuickItem *item) override; |
| 62 | void itemVisibilityChanged(QQuickItem *item) override; |
| 63 | |
| 64 | protected: |
| 65 | void updateLayoutItems() override; |
| 66 | QQuickItem *itemAt(int index) const override; |
| 67 | int itemCount() const override; |
| 68 | |
| 69 | void rearrange(const QSizeF &size) override; |
| 70 | virtual void insertLayoutItems() {} |
| 71 | |
| 72 | Q_SIGNALS: |
| 73 | Q_REVISION(1, 1) void layoutDirectionChanged(); |
| 74 | |
| 75 | private: |
| 76 | void removeGridItem(QGridLayoutItem *gridItem); |
| 77 | Q_DECLARE_PRIVATE(QQuickGridLayoutBase) |
| 78 | }; |
| 79 | |
| 80 | class QQuickLayoutStyleInfo; |
| 81 | |
| 82 | class QQuickGridLayoutBasePrivate : public QQuickLayoutPrivate |
| 83 | { |
| 84 | Q_DECLARE_PUBLIC(QQuickGridLayoutBase) |
| 85 | |
| 86 | public: |
| 87 | QQuickGridLayoutBasePrivate() : m_recurRearrangeCounter(0) |
| 88 | , m_rearranging(false) |
| 89 | , m_layoutDirection(Qt::LeftToRight) |
| 90 | {} |
| 91 | |
| 92 | void mirrorChange() override |
| 93 | { |
| 94 | Q_Q(QQuickGridLayoutBase); |
| 95 | q->invalidate(); |
| 96 | } |
| 97 | |
| 98 | QQuickGridLayoutEngine engine; |
| 99 | Qt::Orientation orientation; |
| 100 | unsigned m_recurRearrangeCounter : 2; |
| 101 | unsigned m_rearranging : 1; |
| 102 | QVector<QQuickItem *> m_invalidateAfterRearrange; |
| 103 | Qt::LayoutDirection m_layoutDirection : 2; |
| 104 | |
| 105 | QQuickLayoutStyleInfo *styleInfo; |
| 106 | }; |
| 107 | |
| 108 | /********************************** |
| 109 | ** |
| 110 | ** QQuickGridLayout |
| 111 | ** |
| 112 | **/ |
| 113 | class QQuickGridLayoutPrivate; |
| 114 | class Q_QUICKLAYOUTS_EXPORT QQuickGridLayout : public QQuickGridLayoutBase |
| 115 | { |
| 116 | Q_OBJECT |
| 117 | |
| 118 | Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged) |
| 119 | Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged) |
| 120 | Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) |
| 121 | Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) |
| 122 | Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) |
| 123 | Q_PROPERTY(bool uniformCellWidths READ uniformCellWidths WRITE setUniformCellWidths |
| 124 | NOTIFY uniformCellWidthsChanged REVISION(6, 6) FINAL) |
| 125 | Q_PROPERTY(bool uniformCellHeights READ uniformCellHeights WRITE setUniformCellHeights |
| 126 | NOTIFY uniformCellHeightsChanged REVISION(6, 6) FINAL) |
| 127 | |
| 128 | QML_NAMED_ELEMENT(GridLayout) |
| 129 | QML_ADDED_IN_VERSION(1, 0) |
| 130 | public: |
| 131 | explicit QQuickGridLayout(QQuickItem *parent = nullptr); |
| 132 | qreal columnSpacing() const; |
| 133 | void setColumnSpacing(qreal spacing); |
| 134 | qreal rowSpacing() const; |
| 135 | void setRowSpacing(qreal spacing); |
| 136 | |
| 137 | int columns() const; |
| 138 | void setColumns(int columns); |
| 139 | int rows() const; |
| 140 | void setRows(int rows); |
| 141 | |
| 142 | enum Flow { LeftToRight, TopToBottom }; |
| 143 | Q_ENUM(Flow) |
| 144 | Flow flow() const; |
| 145 | void setFlow(Flow flow); |
| 146 | |
| 147 | bool uniformCellWidths() const; |
| 148 | void setUniformCellWidths(bool uniformCellWidths); |
| 149 | bool uniformCellHeights() const; |
| 150 | void setUniformCellHeights(bool uniformCellHeights); |
| 151 | |
| 152 | void insertLayoutItems() override; |
| 153 | |
| 154 | Q_SIGNALS: |
| 155 | void columnSpacingChanged(); |
| 156 | void rowSpacingChanged(); |
| 157 | |
| 158 | void columnsChanged(); |
| 159 | void rowsChanged(); |
| 160 | |
| 161 | void flowChanged(); |
| 162 | |
| 163 | Q_REVISION(6, 6) void uniformCellWidthsChanged(); |
| 164 | Q_REVISION(6, 6) void uniformCellHeightsChanged(); |
| 165 | private: |
| 166 | Q_DECLARE_PRIVATE(QQuickGridLayout) |
| 167 | }; |
| 168 | |
| 169 | class QQuickGridLayoutPrivate : public QQuickGridLayoutBasePrivate |
| 170 | { |
| 171 | Q_DECLARE_PUBLIC(QQuickGridLayout) |
| 172 | public: |
| 173 | QQuickGridLayoutPrivate(): columns(-1), rows(-1), flow(QQuickGridLayout::LeftToRight) {} |
| 174 | int columns; |
| 175 | int rows; |
| 176 | QQuickGridLayout::Flow flow; |
| 177 | }; |
| 178 | |
| 179 | |
| 180 | /********************************** |
| 181 | ** |
| 182 | ** QQuickLinearLayout |
| 183 | ** |
| 184 | **/ |
| 185 | class QQuickLinearLayoutPrivate; |
| 186 | class Q_QUICKLAYOUTS_EXPORT QQuickLinearLayout : public QQuickGridLayoutBase |
| 187 | { |
| 188 | Q_OBJECT |
| 189 | QML_ANONYMOUS |
| 190 | Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) |
| 191 | Q_PROPERTY(bool uniformCellSizes READ uniformCellSizes WRITE setUniformCellSizes |
| 192 | NOTIFY uniformCellSizesChanged REVISION(6, 6) FINAL) |
| 193 | public: |
| 194 | explicit QQuickLinearLayout(Qt::Orientation orientation, |
| 195 | QQuickItem *parent = nullptr); |
| 196 | void insertLayoutItem(QQuickItem *item); |
| 197 | qreal spacing() const; |
| 198 | void setSpacing(qreal spacing); |
| 199 | bool uniformCellSizes() const; |
| 200 | void setUniformCellSizes(bool uniformCellSizes); |
| 201 | |
| 202 | void insertLayoutItems() override; |
| 203 | |
| 204 | Q_SIGNALS: |
| 205 | void spacingChanged(); |
| 206 | Q_REVISION(6, 6) void uniformCellSizesChanged(); |
| 207 | private: |
| 208 | Q_DECLARE_PRIVATE(QQuickLinearLayout) |
| 209 | }; |
| 210 | |
| 211 | class QQuickLinearLayoutPrivate : public QQuickGridLayoutBasePrivate |
| 212 | { |
| 213 | Q_DECLARE_PUBLIC(QQuickLinearLayout) |
| 214 | public: |
| 215 | QQuickLinearLayoutPrivate() {} |
| 216 | }; |
| 217 | |
| 218 | |
| 219 | /********************************** |
| 220 | ** |
| 221 | ** QQuickRowLayout |
| 222 | ** |
| 223 | **/ |
| 224 | class Q_QUICKLAYOUTS_EXPORT QQuickRowLayout : public QQuickLinearLayout |
| 225 | { |
| 226 | Q_OBJECT |
| 227 | QML_NAMED_ELEMENT(RowLayout) |
| 228 | QML_ADDED_IN_VERSION(1, 0) |
| 229 | |
| 230 | public: |
| 231 | explicit QQuickRowLayout(QQuickItem *parent = nullptr) |
| 232 | : QQuickLinearLayout(Qt::Horizontal, parent) {} |
| 233 | }; |
| 234 | |
| 235 | |
| 236 | /********************************** |
| 237 | ** |
| 238 | ** QQuickColumnLayout |
| 239 | ** |
| 240 | **/ |
| 241 | class Q_QUICKLAYOUTS_EXPORT QQuickColumnLayout : public QQuickLinearLayout |
| 242 | { |
| 243 | Q_OBJECT |
| 244 | QML_NAMED_ELEMENT(ColumnLayout) |
| 245 | QML_ADDED_IN_VERSION(1, 0) |
| 246 | |
| 247 | public: |
| 248 | explicit QQuickColumnLayout(QQuickItem *parent = nullptr) |
| 249 | : QQuickLinearLayout(Qt::Vertical, parent) {} |
| 250 | }; |
| 251 | |
| 252 | QT_END_NAMESPACE |
| 253 | |
| 254 | #endif // QQUICKLINEARLAYOUT_P_H |
| 255 | |