1// Copyright (C) 2017 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 QQUICKTUMBLER_P_P_H
5#define QQUICKTUMBLER_P_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 <QtQuickTemplates2/private/qquickcontrol_p_p.h>
19#include <QtQuickTemplates2/private/qquicktumbler_p.h>
20
21QT_BEGIN_NAMESPACE
22
23class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickTumblerPrivate : public QQuickControlPrivate
24{
25 Q_DECLARE_PUBLIC(QQuickTumbler)
26
27public:
28 enum ContentItemType {
29 NoContentItem,
30 UnsupportedContentItemType,
31 PathViewContentItem,
32 ListViewContentItem
33 };
34
35 QQuickItem *determineViewType(QQuickItem *contentItem);
36 void resetViewData();
37 QList<QQuickItem *> viewContentItemChildItems() const;
38
39 static QQuickTumblerPrivate *get(QQuickTumbler *tumbler);
40
41 QPalette defaultPalette() const override;
42
43 QVariant model;
44 QQmlComponent *delegate = nullptr;
45 int visibleItemCount = 5;
46 bool wrap = true;
47 bool explicitWrap = false;
48 bool modelBeingSet = false;
49 bool currentIndexSetDuringModelChange = false;
50 QQuickItem *view = nullptr;
51 QQuickItem *viewContentItem = nullptr;
52 ContentItemType viewContentItemType = UnsupportedContentItemType;
53 union {
54 qreal viewOffset; // PathView
55 qreal viewContentY; // ListView
56 };
57 int currentIndex = -1;
58 int pendingCurrentIndex = -1;
59 bool ignoreCurrentIndexChanges = false;
60 int count = 0;
61 bool ignoreSignals = false;
62
63 void _q_updateItemHeights();
64 void _q_updateItemWidths();
65 void _q_onViewCurrentIndexChanged();
66 void _q_onViewCountChanged();
67 void _q_onViewOffsetChanged();
68 void _q_onViewContentYChanged();
69
70 void calculateDisplacements();
71
72 void disconnectFromView();
73 void setupViewData(QQuickItem *newControlContentItem);
74 void warnAboutIncorrectContentItem();
75 void syncCurrentIndex();
76 void setPendingCurrentIndex(int index);
77
78 enum PropertyChangeReason {
79 UserChange,
80 InternalChange
81 };
82
83 static QString propertyChangeReasonToString(PropertyChangeReason changeReason);
84
85 void setCurrentIndex(int newCurrentIndex, PropertyChangeReason changeReason = InternalChange);
86 void setCount(int newCount);
87 void setWrapBasedOnCount();
88 void setWrap(bool shouldWrap, bool isExplicit);
89 void beginSetModel();
90 void endSetModel();
91
92 void itemChildAdded(QQuickItem *, QQuickItem *) override;
93 void itemChildRemoved(QQuickItem *, QQuickItem *) override;
94 void itemGeometryChanged(QQuickItem *, QQuickGeometryChange , const QRectF &) override;
95};
96
97class QQuickTumblerAttachedPrivate : public QObjectPrivate
98{
99 Q_DECLARE_PUBLIC(QQuickTumblerAttached)
100
101public:
102 static QQuickTumblerAttachedPrivate *get(QQuickTumblerAttached *attached)
103 {
104 return attached->d_func();
105 }
106
107 void init(QQuickItem *delegateItem);
108
109 void calculateDisplacement();
110 void emitIfDisplacementChanged(qreal oldDisplacement, qreal newDisplacement);
111
112 // The Tumbler that contains the delegate. Required to calculated the displacement.
113 QPointer<QQuickTumbler> tumbler;
114 // The index of the delegate. Used to calculate the displacement.
115 int index = -1;
116 // The displacement for our delegate.
117 qreal displacement = 0;
118};
119
120QT_END_NAMESPACE
121
122#endif // QQUICKTUMBLER_P_P_H
123

source code of qtdeclarative/src/quicktemplates/qquicktumbler_p_p.h