6#include <QtCore/qloggingcategory.h>
7#include <QtGui/qpa/qplatformtheme.h>
8#include <QtQml/qqmlinfo.h>
9#include <QtQuick/private/qquickflickable_p.h>
10#include <QtQuickTemplates2/private/qquickcontrol_p_p.h>
11#include <QtQuickTemplates2/private/qquicktumbler_p_p.h>
120 return QList<QQuickItem *>();
127 return tumbler->d_func();
138 const qreal itemHeight = delegateHeight(
q);
141 childItem->setHeight(itemHeight);
150 const qreal availableWidth =
q->availableWidth();
153 childItem->setWidth(availableWidth);
163 qCDebug(lcTumbler).nospace() <<
"view currentIndex changed to "
165 <<
", but we're ignoring it because one or more of the following conditions are true:"
166 <<
"\n- !view: " << !
view
175 qCDebug(lcTumbler).nospace() <<
"view currentIndex changed to "
177 <<
", our old currentIndex was " << oldCurrentIndex;
180 emit q->currentIndexChanged();
229 QQuickTumblerAttached *attached = qobject_cast<QQuickTumblerAttached *>(qmlAttachedPropertiesObject<QQuickTumbler>(childItem,
false));
277 d->disconnectFromView();
304 d->currentIndexSetDuringModelChange =
false;
309 d->setCurrentIndex(-1);
337 return d->currentIndex;
343 if (
d->modelBeingSet)
344 d->currentIndexSetDuringModelChange =
true;
359 return d->view ?
d->view->property(
"currentItem").value<
QQuickItem*>() :
nullptr;
392 return d->visibleItemCount;
402 d->_q_updateItemHeights();
433 d->setWrap(
wrap,
true);
439 d->explicitWrap =
false;
440 d->setWrapBasedOnCount();
453 return d->view &&
d->view->property(
"moving").toBool();
484 d->warnAboutIncorrectContentItem();
497 d->_q_updateItemHeights();
499 if (newGeometry.
width() != oldGeometry.
width())
500 d->_q_updateItemWidths();
506 qCDebug(lcTumbler) <<
"componentComplete()";
511 qCDebug(lcTumbler) <<
"emitting wrapChanged() to force view to be created";
514 d->setupViewData(
d->contentItem);
524 d->_q_updateItemHeights();
525 d->_q_updateItemWidths();
526 d->_q_onViewCountChanged();
528 qCDebug(lcTumbler) <<
"componentComplete() is done";
538 d->disconnectFromView();
546 d->setupViewData(newItem);
548 d->_q_updateItemHeights();
549 d->_q_updateItemWidths();
623 qmlWarning(
q) <<
"Tumbler: contentItem must contain either a PathView or a ListView";
635 if (actualViewIndex == indexToSet) {
642 if (
q->count() == 0 && actualViewIndex <= 0)
651 else if (isPendingCurrentIndex)
657 qCDebug(lcTumbler) <<
"setting pendingCurrentIndex to" <<
index;
671 qCDebug(lcTumbler).nospace() <<
"setting currentIndex to " << newCurrentIndex
674 if (newCurrentIndex ==
currentIndex || newCurrentIndex < -1)
677 if (!
q->isComponentComplete()) {
679 qCDebug(lcTumbler) <<
"we're not complete; setting pendingCurrentIndex instead";
689 qCDebug(lcTumbler) <<
"a model is being set; setting pendingCurrentIndex instead";
698 if ((
count > 0 && newCurrentIndex == -1) || (newCurrentIndex >=
count)) {
707 bool couldSet =
false;
708 if (
count == 0 && newCurrentIndex == -1) {
725 emit q->currentIndexChanged();
735 qCDebug(lcTumbler).nospace() <<
"setting count to " << newCount
736 <<
", old count was " <<
count;
737 if (newCount ==
count)
745 emit q->countChanged();
758 qCDebug(lcTumbler) <<
"setting wrap to" << shouldWrap <<
"- explicit?" << isExplicit;
763 if (
q->isComponentComplete() && shouldWrap ==
wrap)
780 emit q->wrapChanged();
815 if (
event->isAutoRepeat() || !
d->view)
828 if (
d->pendingCurrentIndex != -1) {
831 d->setCount(
d->view->property(
"count").toInt());
835 d->setPendingCurrentIndex(-1);
842 d->setCurrentIndex(
d->pendingCurrentIndex);
844 if (
d->currentIndex !=
d->pendingCurrentIndex &&
d->currentIndex == -1) {
847 d->setCurrentIndex(0);
850 d->setPendingCurrentIndex(-1);
862 if (!delegateItem->parentItem()) {
863 qmlWarning(
q) <<
"Tumbler: attached properties must be accessed through a delegate item that has a parent";
868 if (!indexContextProperty.isValid()) {
869 qmlWarning(
q) <<
"Tumbler: attempting to access attached property on item without an \"index\" property";
873 index = indexContextProperty.toInt();
876 while ((parentItem = parentItem->
parentItem())) {
877 if ((
tumbler = qobject_cast<QQuickTumbler*>(parentItem)))
895 if (!tumblerPrivate->viewContentItem) {
902 const int count = tumblerPrivate->view->property(
"count").toInt();
915 const int halfVisibleItems = visibleItems / 2 + (visibleItems <
count ? 1 : 0);
921 const qreal contentY = tumblerPrivate->viewContentY;
923 const qreal preferredHighlightBegin = tumblerPrivate->view->property(
"preferredHighlightBegin").toReal();
925 qreal currentItemY = 0;
926 auto currentItem = tumblerPrivate->view->property(
"currentItem").value<
QQuickItem*>();
928 currentItemY = currentItem->
y();
930 const qreal topOfCurrentItemInViewport = currentItemY - contentY;
932 const qreal relativePositionToPreferredHighlightBegin = topOfCurrentItemInViewport - preferredHighlightBegin;
934 const qreal distanceFromCurrentItem = currentItemY - itemY;
935 const qreal displacementInPixels = distanceFromCurrentItem - relativePositionToPreferredHighlightBegin;
946 if (newDisplacement != oldDisplacement)
947 emit q->displacementChanged();
956 d->init(delegateItem);
958 qmlWarning(
parent) <<
"Tumbler: attached properties of Tumbler must be accessed through a delegate item";
967 tumblerPrivate->setupViewData(tumblerPrivate->contentItem);
969 if (delegateItem && delegateItem->parentItem() == tumblerPrivate->viewContentItem) {
973 d->calculateDisplacement();
1012 return d->displacement;
1017#include "moc_qquicktumbler_p.cpp"
The QKeyEvent class describes a key event.
static constexpr Policy Preferred
QObject * parent() const
Returns a pointer to the parent object.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
QVariant property(const char *name) const
Returns the value of the object's name property.
bool setProperty(const char *name, const QVariant &value)
Sets the value of the object's name property to value.
bool inherits(const char *classname) const
Returns true if this object is an instance of a class that inherits className or a QObject subclass t...
The QPalette class contains color groups for each widget state.
The QQmlComponent class encapsulates a QML component definition.
QVariant contextProperty(const QString &) const
Returns the value of the name property for this context as a QVariant.
void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) override
QQuickDeferredPointer< QQuickItem > contentItem
virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void rightPaddingChanged()
void bottomPaddingChanged()
void leftPaddingChanged()
static QQuickItemPrivate * get(QQuickItem *item)
QList< QQuickItem * > childItems
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
QList< QQuickItem * > childItems() const
Returns the children of this item.
virtual void keyPressEvent(QKeyEvent *event)
This event handler can be reimplemented in a subclass to receive key press events for an item.
qreal y
Defines the item's y position relative to its parent.
QQuickItem * parentItem() const
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
void setActiveFocusOnTab(bool)
static QPalette palette(Scope scope)
static QFont font(Scope scope)
static QQuickTumblerAttachedPrivate * get(QQuickTumblerAttached *attached)
void calculateDisplacement()
void emitIfDisplacementChanged(qreal oldDisplacement, qreal newDisplacement)
void init(QQuickItem *delegateItem)
QPointer< QQuickTumbler > tumbler
QQuickTumblerAttached(QObject *parent=nullptr)
bool ignoreCurrentIndexChanges
ContentItemType viewContentItemType
QQuickItem * viewContentItem
void _q_onViewOffsetChanged()
bool currentIndexSetDuringModelChange
void warnAboutIncorrectContentItem()
void itemGeometryChanged(QQuickItem *, QQuickGeometryChange, const QRectF &) override
void setCurrentIndex(int newCurrentIndex, PropertyChangeReason changeReason=InternalChange)
void _q_updateItemHeights()
QQuickItem * determineViewType(QQuickItem *contentItem)
void setWrapBasedOnCount()
void itemChildAdded(QQuickItem *, QQuickItem *) override
void _q_updateItemWidths()
void setCount(int newCount)
void _q_onViewCountChanged()
void disconnectFromView()
static QQuickTumblerPrivate * get(QQuickTumbler *tumbler)
void itemChildRemoved(QQuickItem *, QQuickItem *) override
QList< QQuickItem * > viewContentItemChildItems() const
void setPendingCurrentIndex(int index)
void _q_onViewContentYChanged()
void setupViewData(QQuickItem *newControlContentItem)
@ UnsupportedContentItemType
void _q_onViewCurrentIndexChanged()
void calculateDisplacements()
void setWrap(bool shouldWrap, bool isExplicit)
QPalette defaultPalette() const override
static QString propertyChangeReasonToString(PropertyChangeReason changeReason)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void updatePolish() override
This function should perform any layout as required for this item.
void keyPressEvent(QKeyEvent *event) override
This event handler can be reimplemented in a subclass to receive key press events for an item.
QFont defaultFont() const override
void setCurrentIndex(int currentIndex)
QQuickTumbler(QQuickItem *parent=nullptr)
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void visibleItemCountChanged()
void setDelegate(QQmlComponent *delegate)
void setModel(const QVariant &model)
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override
void setVisibleItemCount(int visibleItemCount)
static QQuickTumblerAttached * qmlAttachedProperties(QObject *object)
bool isMoving() const
\qmlproperty bool QtQuick.Controls::Tumbler::moving
\inmodule QtCore\reentrant
constexpr qreal width() const noexcept
Returns the width of the rectangle.
\macro QT_RESTRICTED_CAST_FROM_ASCII
qreal toReal(bool *ok=nullptr) const
Returns the variant as a qreal if the variant has userType() \l QMetaType::Double,...
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
QString toString() const
Returns the variant as a QString if the variant has a userType() including, but not limited to:
Combined button and popup list for selecting options.
static qreal delegateHeight(const QQuickTumbler *tumbler)
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
#define Q_ARG(Type, data)
GLenum GLenum GLsizei count
GLenum GLuint GLintptr offset
GLdouble GLdouble GLdouble GLdouble q
QQmlContext * qmlContext(const QObject *obj)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
static QT_BEGIN_NAMESPACE QAsn1Element wrap(quint8 type, const QAsn1Element &child)
#define QStringLiteral(str)
QSqlQueryModel * model
[16]