| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the Qt Quick Layouts module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef QQUICKLINEARLAYOUT_P_H |
| 41 | #define QQUICKLINEARLAYOUT_P_H |
| 42 | |
| 43 | #include "qquicklayout_p.h" |
| 44 | #include "qquickgridlayoutengine_p.h" |
| 45 | |
| 46 | QT_BEGIN_NAMESPACE |
| 47 | |
| 48 | /********************************** |
| 49 | ** |
| 50 | ** QQuickGridLayoutBase |
| 51 | ** |
| 52 | **/ |
| 53 | class QQuickGridLayoutBasePrivate; |
| 54 | |
| 55 | class QQuickGridLayoutBase : public QQuickLayout |
| 56 | { |
| 57 | Q_OBJECT |
| 58 | |
| 59 | Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection NOTIFY layoutDirectionChanged REVISION 1) |
| 60 | QML_ANONYMOUS |
| 61 | QML_ADDED_IN_MINOR_VERSION(1) |
| 62 | |
| 63 | public: |
| 64 | |
| 65 | QQuickGridLayoutBase(); |
| 66 | |
| 67 | explicit QQuickGridLayoutBase(QQuickGridLayoutBasePrivate &dd, |
| 68 | Qt::Orientation orientation, |
| 69 | QQuickItem *parent = 0); |
| 70 | |
| 71 | ~QQuickGridLayoutBase(); |
| 72 | void componentComplete() override; |
| 73 | void invalidate(QQuickItem *childItem = 0) override; |
| 74 | Qt::Orientation orientation() const; |
| 75 | void setOrientation(Qt::Orientation orientation); |
| 76 | QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override; |
| 77 | Qt::LayoutDirection layoutDirection() const; |
| 78 | void setLayoutDirection(Qt::LayoutDirection dir); |
| 79 | Qt::LayoutDirection effectiveLayoutDirection() const; |
| 80 | void setAlignment(QQuickItem *item, Qt::Alignment align) override; |
| 81 | |
| 82 | /* QQuickItemChangeListener */ |
| 83 | void itemDestroyed(QQuickItem *item) override; |
| 84 | void itemVisibilityChanged(QQuickItem *item) override; |
| 85 | |
| 86 | protected: |
| 87 | void updateLayoutItems() override; |
| 88 | QQuickItem *itemAt(int index) const override; |
| 89 | int itemCount() const override; |
| 90 | |
| 91 | void rearrange(const QSizeF &size) override; |
| 92 | virtual void insertLayoutItems() {} |
| 93 | |
| 94 | signals: |
| 95 | Q_REVISION(1) void layoutDirectionChanged(); |
| 96 | |
| 97 | private: |
| 98 | void removeGridItem(QGridLayoutItem *gridItem); |
| 99 | Q_DECLARE_PRIVATE(QQuickGridLayoutBase) |
| 100 | }; |
| 101 | |
| 102 | class QQuickLayoutStyleInfo; |
| 103 | |
| 104 | class QQuickGridLayoutBasePrivate : public QQuickLayoutPrivate |
| 105 | { |
| 106 | Q_DECLARE_PUBLIC(QQuickGridLayoutBase) |
| 107 | |
| 108 | public: |
| 109 | QQuickGridLayoutBasePrivate() : m_recurRearrangeCounter(0) |
| 110 | , m_rearranging(false) |
| 111 | , m_updateAfterRearrange(false) |
| 112 | , m_layoutDirection(Qt::LeftToRight) |
| 113 | {} |
| 114 | |
| 115 | void mirrorChange() override |
| 116 | { |
| 117 | Q_Q(QQuickGridLayoutBase); |
| 118 | q->invalidate(); |
| 119 | } |
| 120 | |
| 121 | QQuickGridLayoutEngine engine; |
| 122 | Qt::Orientation orientation; |
| 123 | unsigned m_recurRearrangeCounter : 2; |
| 124 | unsigned m_rearranging : 1; |
| 125 | unsigned m_updateAfterRearrange : 1; |
| 126 | QVector<QQuickItem *> m_invalidateAfterRearrange; |
| 127 | Qt::LayoutDirection m_layoutDirection : 2; |
| 128 | |
| 129 | QQuickLayoutStyleInfo *styleInfo; |
| 130 | }; |
| 131 | |
| 132 | /********************************** |
| 133 | ** |
| 134 | ** QQuickGridLayout |
| 135 | ** |
| 136 | **/ |
| 137 | class QQuickGridLayoutPrivate; |
| 138 | class QQuickGridLayout : public QQuickGridLayoutBase |
| 139 | { |
| 140 | Q_OBJECT |
| 141 | |
| 142 | Q_PROPERTY(qreal columnSpacing READ columnSpacing WRITE setColumnSpacing NOTIFY columnSpacingChanged) |
| 143 | Q_PROPERTY(qreal rowSpacing READ rowSpacing WRITE setRowSpacing NOTIFY rowSpacingChanged) |
| 144 | Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged) |
| 145 | Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged) |
| 146 | Q_PROPERTY(Flow flow READ flow WRITE setFlow NOTIFY flowChanged) |
| 147 | QML_NAMED_ELEMENT(GridLayout) |
| 148 | public: |
| 149 | explicit QQuickGridLayout(QQuickItem *parent = 0); |
| 150 | qreal columnSpacing() const; |
| 151 | void setColumnSpacing(qreal spacing); |
| 152 | qreal rowSpacing() const; |
| 153 | void setRowSpacing(qreal spacing); |
| 154 | |
| 155 | int columns() const; |
| 156 | void setColumns(int columns); |
| 157 | int rows() const; |
| 158 | void setRows(int rows); |
| 159 | |
| 160 | enum Flow { LeftToRight, TopToBottom }; |
| 161 | Q_ENUM(Flow) |
| 162 | Flow flow() const; |
| 163 | void setFlow(Flow flow); |
| 164 | |
| 165 | void insertLayoutItems() override; |
| 166 | |
| 167 | signals: |
| 168 | void columnSpacingChanged(); |
| 169 | void rowSpacingChanged(); |
| 170 | |
| 171 | void columnsChanged(); |
| 172 | void rowsChanged(); |
| 173 | |
| 174 | void flowChanged(); |
| 175 | private: |
| 176 | Q_DECLARE_PRIVATE(QQuickGridLayout) |
| 177 | }; |
| 178 | |
| 179 | class QQuickGridLayoutPrivate : public QQuickGridLayoutBasePrivate |
| 180 | { |
| 181 | Q_DECLARE_PUBLIC(QQuickGridLayout) |
| 182 | public: |
| 183 | QQuickGridLayoutPrivate(): columns(-1), rows(-1), flow(QQuickGridLayout::LeftToRight) {} |
| 184 | int columns; |
| 185 | int rows; |
| 186 | QQuickGridLayout::Flow flow; |
| 187 | }; |
| 188 | |
| 189 | |
| 190 | /********************************** |
| 191 | ** |
| 192 | ** QQuickLinearLayout |
| 193 | ** |
| 194 | **/ |
| 195 | class QQuickLinearLayoutPrivate; |
| 196 | class QQuickLinearLayout : public QQuickGridLayoutBase |
| 197 | { |
| 198 | Q_OBJECT |
| 199 | Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) |
| 200 | public: |
| 201 | explicit QQuickLinearLayout(Qt::Orientation orientation, |
| 202 | QQuickItem *parent = 0); |
| 203 | void insertLayoutItem(QQuickItem *item); |
| 204 | qreal spacing() const; |
| 205 | void setSpacing(qreal spacing); |
| 206 | |
| 207 | void insertLayoutItems() override; |
| 208 | |
| 209 | signals: |
| 210 | void spacingChanged(); |
| 211 | private: |
| 212 | Q_DECLARE_PRIVATE(QQuickLinearLayout) |
| 213 | }; |
| 214 | |
| 215 | class QQuickLinearLayoutPrivate : public QQuickGridLayoutBasePrivate |
| 216 | { |
| 217 | Q_DECLARE_PUBLIC(QQuickLinearLayout) |
| 218 | public: |
| 219 | QQuickLinearLayoutPrivate() {} |
| 220 | }; |
| 221 | |
| 222 | |
| 223 | /********************************** |
| 224 | ** |
| 225 | ** QQuickRowLayout |
| 226 | ** |
| 227 | **/ |
| 228 | class QQuickRowLayout : public QQuickLinearLayout |
| 229 | { |
| 230 | Q_OBJECT |
| 231 | QML_NAMED_ELEMENT(RowLayout) |
| 232 | |
| 233 | public: |
| 234 | explicit QQuickRowLayout(QQuickItem *parent = 0) |
| 235 | : QQuickLinearLayout(Qt::Horizontal, parent) {} |
| 236 | }; |
| 237 | |
| 238 | |
| 239 | /********************************** |
| 240 | ** |
| 241 | ** QQuickColumnLayout |
| 242 | ** |
| 243 | **/ |
| 244 | class QQuickColumnLayout : public QQuickLinearLayout |
| 245 | { |
| 246 | Q_OBJECT |
| 247 | QML_NAMED_ELEMENT(ColumnLayout) |
| 248 | |
| 249 | public: |
| 250 | explicit QQuickColumnLayout(QQuickItem *parent = 0) |
| 251 | : QQuickLinearLayout(Qt::Vertical, parent) {} |
| 252 | }; |
| 253 | |
| 254 | QT_END_NAMESPACE |
| 255 | |
| 256 | #endif // QQUICKLINEARLAYOUT_P_H |
| 257 | |