Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquickstacklayout_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QQUICKSTACKLAYOUT_H
6#define QQUICKSTACKLAYOUT_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuickLayouts/private/qquicklayoutglobal_p.h>
20#include <QtQuickLayouts/private/qquicklayout_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class QQuickStackLayoutPrivate;
25class QQuickStackLayoutAttached;
26
27class Q_QUICKLAYOUTS_EXPORT QQuickStackLayout : public QQuickLayout
28{
29 Q_OBJECT
30 Q_PROPERTY(int count READ count NOTIFY countChanged)
31 Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
32 QML_NAMED_ELEMENT(StackLayout)
33 QML_ADDED_IN_VERSION(1, 3)
34 QML_ATTACHED(QQuickStackLayoutAttached)
35
36public:
37 explicit QQuickStackLayout(QQuickItem *parent = nullptr);
38 int count() const;
39 int currentIndex() const;
40 void setCurrentIndex(int index);
41
42 void componentComplete() override;
43 void itemChange(ItemChange change, const ItemChangeData &value) override;
44 QSizeF sizeHint(Qt::SizeHint whichSizeHint) const override;
45 void setAlignment(QQuickItem *item, Qt::Alignment align) override;
46 void invalidate(QQuickItem *childItem = nullptr) override;
47 void itemIgnoredChanged(QQuickItem *childItem) override;
48 void updateLayoutItems() override { }
49 void rearrange(const QSizeF &) override;
50 void setStretchFactor(QQuickItem *item, int stretchFactor, Qt::Orientation orient) override;
51
52 // iterator
53 Q_INVOKABLE QQuickItem *itemAt(int index) const override;
54 int itemCount() const override;
55 int indexOf(QQuickItem *item) const;
56
57 /* QQuickItemChangeListener */
58 void itemSiblingOrderChanged(QQuickItem *item) override;
59
60 static QQuickStackLayoutAttached *qmlAttachedProperties(QObject *object);
61
62Q_SIGNALS:
63 void currentIndexChanged();
64 void countChanged();
65
66private:
67 enum AdjustCurrentIndexPolicy {
68 DontAdjustCurrentIndex,
69 AdjustCurrentIndex
70 };
71
72 static void collectItemSizeHints(QQuickItem *item, QSizeF *sizeHints);
73 bool shouldIgnoreItem(QQuickItem *item) const override;
74 void childItemsChanged(AdjustCurrentIndexPolicy adjustCurrentIndexPolicy = DontAdjustCurrentIndex);
75 Q_DECLARE_PRIVATE(QQuickStackLayout)
76
77 friend class QQuickStackLayoutAttached;
78
79 QList<QQuickItem*> m_items;
80
81 struct SizeHints {
82 inline QSizeF &min() { return array[Qt::MinimumSize]; }
83 inline QSizeF &pref() { return array[Qt::PreferredSize]; }
84 inline QSizeF &max() { return array[Qt::MaximumSize]; }
85 QSizeF array[Qt::NSizeHints];
86 };
87
88 mutable QHash<QQuickItem*, SizeHints> m_cachedItemSizeHints;
89 mutable QSizeF m_cachedSizeHints[Qt::NSizeHints];
90 SizeHints &cachedItemSizeHints(int index) const;
91};
92
94{
95 Q_DECLARE_PUBLIC(QQuickStackLayout)
96public:
98private:
99 int count;
100 int currentIndex;
101 bool explicitCurrentIndex;
102};
103
104class Q_QUICKLAYOUTS_EXPORT QQuickStackLayoutAttached : public QObject
105{
106 Q_OBJECT
107 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
108 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY isCurrentItemChanged FINAL)
109 Q_PROPERTY(QQuickStackLayout *layout READ layout NOTIFY layoutChanged FINAL)
110
111public:
112 QQuickStackLayoutAttached(QObject *object);
113
114 int index() const;
115 void setIndex(int index);
116
117 bool isCurrentItem() const;
118 void setIsCurrentItem(bool isCurrentItem);
119
120 QQuickStackLayout *layout() const;
121 void setLayout(QQuickStackLayout *layout);
122
123Q_SIGNALS:
124 void indexChanged();
125 void isCurrentItemChanged();
126 void layoutChanged();
127
128private:
129 int m_index = -1;
130 bool m_isCurrentItem = false;
131 QQuickStackLayout *m_layout = nullptr;
132};
133
134QT_END_NAMESPACE
135
136#endif // QQUICKSTACKLAYOUT_H