Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qquickswipeview.cpp
Go to the documentation of this file.
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#include "qquickswipeview_p.h"
5
6#include <QtQml/qqmlinfo.h>
7#include <QtQuickTemplates2/private/qquickcontainer_p_p.h>
8
10
15
76{
77 Q_DECLARE_PUBLIC(QQuickSwipeView)
78
79public:
81 void resizeItems();
82
84
87
88 qreal getContentWidth() const override;
89 qreal getContentHeight() const override;
90
91 bool interactive = true;
93};
94
96{
97public:
98 Q_DECLARE_PUBLIC(QQuickSwipeViewAttached)
99
101 {
102 return attached->d_func();
103 }
104
105 void update(QQuickSwipeView *newView, int newIndex);
106 void updateCurrentIndex();
107 void setCurrentIndex(int i);
108
110 int index = -1;
111 int currentIndex = -1;
112};
113
115{
116 Q_Q(QQuickSwipeView);
117 const int count = q->count();
118 for (int i = 0; i < count; ++i) {
120 if (item) {
122 // TODO: expose QQuickAnchorLine so we can test for other conflicting anchors
123 if (anchors && (anchors->fill() || anchors->centerIn()) && !item->property("_q_QQuickSwipeView_warned").toBool()) {
124 qmlWarning(item) << "SwipeView has detected conflicting anchors. Unable to layout the item.";
125 item->setProperty("_q_QQuickSwipeView_warned", true);
126 }
128 item->setPosition({i * (contentItem->width() + spacing), 0});
129 else
130 item->setPosition({0, i * (contentItem->height() + spacing)});
131 item->setSize(QSizeF(contentItem->width(), contentItem->height()));
132 }
133 }
134}
135
137{
138 return view->d_func();
139}
140
142{
143 Q_Q(QQuickSwipeView);
145 if (item == q->currentItem())
147}
148
150{
151 Q_Q(QQuickSwipeView);
153 if (item == q->currentItem())
155}
156
158{
159 Q_Q(const QQuickSwipeView);
160 QQuickItem *currentItem = q->currentItem();
161 return currentItem ? currentItem->implicitWidth() : 0;
162}
163
165{
166 Q_Q(const QQuickSwipeView);
167 QQuickItem *currentItem = q->currentItem();
168 return currentItem ? currentItem->implicitHeight() : 0;
169}
170
173{
174 Q_D(QQuickSwipeView);
179}
180
191{
192 Q_D(const QQuickSwipeView);
193 return d->interactive;
194}
195
197{
198 Q_D(QQuickSwipeView);
199 if (d->interactive == interactive)
200 return;
201
202 d->interactive = interactive;
203 emit interactiveChanged();
204}
205
219{
220 Q_D(const QQuickSwipeView);
221 return d->orientation;
222}
223
225{
226 Q_D(QQuickSwipeView);
227 if (d->orientation == orientation)
228 return;
229
230 d->orientation = orientation;
232 d->resizeItems();
233 emit orientationChanged();
234}
235
246{
247 Q_D(const QQuickSwipeView);
248 return d->orientation == Qt::Horizontal;
249}
250
261{
262 Q_D(const QQuickSwipeView);
263 return d->orientation == Qt::Vertical;
264}
265
267{
268 return new QQuickSwipeViewAttached(object);
269}
270
271void QQuickSwipeView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
272{
273 Q_D(QQuickSwipeView);
274 QQuickContainer::geometryChange(newGeometry, oldGeometry);
275 d->resizeItems();
276}
277
279{
280 Q_D(QQuickSwipeView);
282 item->setSize(QSizeF(d->contentItem->width(), d->contentItem->height()));
283 QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item));
284 if (attached)
286}
287
289{
290 QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item));
291 if (attached)
293}
294
296{
297 QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item));
298 if (attached)
299 QQuickSwipeViewAttachedPrivate::get(attached)->update(nullptr, -1);
300}
301
302#if QT_CONFIG(accessibility)
303QAccessible::Role QQuickSwipeView::accessibleRole() const
304{
305 return QAccessible::PageTabList;
306}
307#endif
308
357{
359}
360
362{
363 if (i == currentIndex)
364 return;
365
367 const bool wasCurrent = q->isCurrentItem();
368 const bool wasNext = q->isNextItem();
369 const bool wasPrevious = q->isPreviousItem();
370
371 currentIndex = i;
372 if (wasCurrent != q->isCurrentItem())
373 emit q->isCurrentItemChanged();
374 if (wasNext != q->isNextItem())
375 emit q->isNextItemChanged();
376 if (wasPrevious != q->isPreviousItem())
377 emit q->isPreviousItemChanged();
378}
379
381{
383 int oldIndex = index;
384 QQuickSwipeView *oldView = swipeView;
385
386 index = newIndex;
387 swipeView = newView;
388
389 if (oldView != newView) {
390 if (oldView) {
393 }
394 if (newView) {
397 }
398 emit q->viewChanged();
399 }
400 if (oldIndex != newIndex)
401 emit q->indexChanged();
402
404}
405
408{
410 qmlWarning(parent) << "SwipeView: attached properties must be accessed from within a child item";
411}
412
414{
415 Q_D(const QQuickSwipeViewAttached);
416 return d->index;
417}
418
420{
421 Q_D(const QQuickSwipeViewAttached);
422 return d->index != -1 && d->currentIndex != -1 && d->index == d->currentIndex;
423}
424
426{
427 Q_D(const QQuickSwipeViewAttached);
428 return d->swipeView;
429}
430
432{
433 Q_D(const QQuickSwipeViewAttached);
434 return d->index != -1 && d->currentIndex != -1 && d->index == d->currentIndex + 1;
435}
436
438{
439 Q_D(const QQuickSwipeViewAttached);
440 return d->index != -1 && d->currentIndex != -1 && d->index == d->currentIndex - 1;
441}
442
444
445#include "moc_qquickswipeview_p.cpp"
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:298
\inmodule QtCore
Definition qobject.h:90
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
QQuickItem * fill
QQuickItem * centerIn
QQuickItem * itemAt(int index) const
void currentItemChanged()
void currentIndexChanged()
QQuickDeferredPointer< QQuickItem > contentItem
virtual void itemImplicitWidthChanged(QQuickItem *)
virtual void itemImplicitHeightChanged(QQuickItem *)
QQuickAnchors * _anchors
QQuickAnchors * anchors() const
\qmlpropertygroup QtQuick::Item::anchors \qmlproperty AnchorLine QtQuick::Item::anchors....
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:64
void setFlag(Flag flag, bool enabled=true)
Enables the specified flag for this item if enabled is true; if enabled is false, the flag is disable...
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
qreal implicitWidth
Definition qquickitem.h:113
qreal width
This property holds the width of this item.
Definition qquickitem.h:76
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
qreal implicitHeight
Definition qquickitem.h:114
qreal height
This property holds the height of this item.
Definition qquickitem.h:77
void setActiveFocusOnTab(bool)
static QQuickSwipeViewAttachedPrivate * get(QQuickSwipeViewAttached *attached)
void updateCurrentIndex()
\qmlattachedproperty int QtQuick.Controls::SwipeView::index \readonly
void update(QQuickSwipeView *newView, int newIndex)
QQuickSwipeViewAttached(QObject *parent=nullptr)
Enables the user to navigate pages by swiping sideways.
void resizeItem(QQuickItem *item)
void itemImplicitWidthChanged(QQuickItem *item) override
qreal getContentHeight() const override
qreal getContentWidth() const override
static QQuickSwipeViewPrivate * get(QQuickSwipeView *view)
Qt::Orientation orientation
void itemImplicitHeightChanged(QQuickItem *item) override
void setInteractive(bool interactive)
Qt::Orientation orientation
void setOrientation(Qt::Orientation orientation)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void itemRemoved(int index, QQuickItem *item) override
bool isHorizontal() const
static QQuickSwipeViewAttached * qmlAttachedProperties(QObject *object)
void itemMoved(int index, QQuickItem *item) override
bool isVertical() const
bool isInteractive() const
QQuickSwipeView(QQuickItem *parent=nullptr)
void itemAdded(int index, QQuickItem *item) override
\inmodule QtCore\reentrant
Definition qrect.h:483
\inmodule QtCore
Definition qsize.h:207
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:97
@ Horizontal
Definition qnamespace.h:98
@ Vertical
Definition qnamespace.h:99
GLuint index
[2]
GLenum GLenum GLsizei count
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:483
#define emit
double qreal
Definition qtypes.h:92
myObject disconnect()
[26]
QGraphicsItem * item
QQuickView * view
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent