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

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