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 updateLayoutItems() override { }
48 void rearrange(const QSizeF &) override;
49 void setStretchFactor(QQuickItem *item, int stretchFactor, Qt::Orientation orient) override;
50
51 // iterator
52 Q_INVOKABLE QQuickItem *itemAt(int index) const override;
53 int itemCount() const override;
54 int indexOf(QQuickItem *item) const;
55
56 /* QQuickItemChangeListener */
57 void itemSiblingOrderChanged(QQuickItem *item) override;
58
59 static QQuickStackLayoutAttached *qmlAttachedProperties(QObject *object);
60
61Q_SIGNALS:
62 void currentIndexChanged();
63 void countChanged();
64
65private:
66 enum AdjustCurrentIndexPolicy {
67 DontAdjustCurrentIndex,
68 AdjustCurrentIndex
69 };
70
71 static void collectItemSizeHints(QQuickItem *item, QSizeF *sizeHints);
72 bool shouldIgnoreItem(QQuickItem *item) const;
73 void childItemsChanged(AdjustCurrentIndexPolicy adjustCurrentIndexPolicy = DontAdjustCurrentIndex);
74 Q_DECLARE_PRIVATE(QQuickStackLayout)
75
76 friend class QQuickStackLayoutAttached;
77
78 QList<QQuickItem*> m_items;
79
80 struct SizeHints {
81 inline QSizeF &min() { return array[Qt::MinimumSize]; }
82 inline QSizeF &pref() { return array[Qt::PreferredSize]; }
83 inline QSizeF &max() { return array[Qt::MaximumSize]; }
84 QSizeF array[Qt::NSizeHints];
85 };
86
87 mutable QHash<QQuickItem*, SizeHints> m_cachedItemSizeHints;
88 mutable QSizeF m_cachedSizeHints[Qt::NSizeHints];
89 SizeHints &cachedItemSizeHints(int index) const;
90};
91
93{
94 Q_DECLARE_PUBLIC(QQuickStackLayout)
95public:
97private:
98 int count;
99 int currentIndex;
100 bool explicitCurrentIndex;
101};
102
103class Q_QUICKLAYOUTS_EXPORT QQuickStackLayoutAttached : public QObject
104{
105 Q_OBJECT
106 Q_PROPERTY(int index READ index NOTIFY indexChanged FINAL)
107 Q_PROPERTY(bool isCurrentItem READ isCurrentItem NOTIFY isCurrentItemChanged FINAL)
108 Q_PROPERTY(QQuickStackLayout *layout READ layout NOTIFY layoutChanged FINAL)
109
110public:
111 QQuickStackLayoutAttached(QObject *object);
112
113 int index() const;
114 void setIndex(int index);
115
116 bool isCurrentItem() const;
117 void setIsCurrentItem(bool isCurrentItem);
118
119 QQuickStackLayout *layout() const;
120 void setLayout(QQuickStackLayout *layout);
121
122Q_SIGNALS:
123 void indexChanged();
124 void isCurrentItemChanged();
125 void layoutChanged();
126
127private:
128 int m_index = -1;
129 bool m_isCurrentItem = false;
130 QQuickStackLayout *m_layout = nullptr;
131};
132
133QT_END_NAMESPACE
134
135#endif // QQUICKSTACKLAYOUT_H