| 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 QQUICKSTACKLAYOUT_H |
| 41 | #define QQUICKSTACKLAYOUT_H |
| 42 | |
| 43 | #include <qquicklayout_p.h> |
| 44 | |
| 45 | QT_BEGIN_NAMESPACE |
| 46 | |
| 47 | class QQuickStackLayoutPrivate; |
| 48 | |
| 49 | class QQuickStackLayout : public QQuickLayout |
| 50 | { |
| 51 | Q_OBJECT |
| 52 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
| 53 | Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) |
| 54 | QML_NAMED_ELEMENT(StackLayout) |
| 55 | QML_ADDED_IN_MINOR_VERSION(3) |
| 56 | |
| 57 | public: |
| 58 | explicit QQuickStackLayout(QQuickItem *parent = 0); |
| 59 | int count() const; |
| 60 | int currentIndex() const; |
| 61 | void setCurrentIndex(int index); |
| 62 | |
| 63 | void componentComplete() override; |
| 64 | void itemChange(ItemChange change, const ItemChangeData &value) override; |
| 65 | QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override; |
| 66 | void setAlignment(QQuickItem *item, Qt::Alignment align) override; |
| 67 | void invalidate(QQuickItem *childItem = 0) override; |
| 68 | void updateLayoutItems() override; |
| 69 | void rearrange(const QSizeF &) override; |
| 70 | |
| 71 | // iterator |
| 72 | Q_INVOKABLE QQuickItem *itemAt(int index) const override; |
| 73 | int itemCount() const override; |
| 74 | int indexOf(QQuickItem *item) const; |
| 75 | |
| 76 | |
| 77 | |
| 78 | signals: |
| 79 | void currentIndexChanged(); |
| 80 | void countChanged(); |
| 81 | |
| 82 | public slots: |
| 83 | |
| 84 | private: |
| 85 | static void collectItemSizeHints(QQuickItem *item, QSizeF *sizeHints); |
| 86 | bool shouldIgnoreItem(QQuickItem *item) const; |
| 87 | Q_DECLARE_PRIVATE(QQuickStackLayout) |
| 88 | |
| 89 | QList<QQuickItem*> m_items; |
| 90 | |
| 91 | typedef struct { |
| 92 | inline QSizeF &min() { return array[Qt::MinimumSize]; } |
| 93 | inline QSizeF &pref() { return array[Qt::PreferredSize]; } |
| 94 | inline QSizeF &max() { return array[Qt::MaximumSize]; } |
| 95 | QSizeF array[Qt::NSizeHints]; |
| 96 | } SizeHints; |
| 97 | |
| 98 | mutable QVector<SizeHints> m_cachedItemSizeHints; |
| 99 | mutable QSizeF m_cachedSizeHints[Qt::NSizeHints]; |
| 100 | }; |
| 101 | |
| 102 | class QQuickStackLayoutPrivate : public QQuickLayoutPrivate |
| 103 | { |
| 104 | Q_DECLARE_PUBLIC(QQuickStackLayout) |
| 105 | public: |
| 106 | QQuickStackLayoutPrivate() : count(0), currentIndex(-1), explicitCurrentIndex(false) {} |
| 107 | private: |
| 108 | int count; |
| 109 | int currentIndex; |
| 110 | bool explicitCurrentIndex; |
| 111 | }; |
| 112 | |
| 113 | QT_END_NAMESPACE |
| 114 | |
| 115 | #endif // QQUICKSTACKLAYOUT_H |
| 116 | |