Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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:
80 void resizeItem(int index, QQuickItem *item);
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{
117 // TODO: expose QQuickAnchorLine so we can test for other conflicting anchors
118 if (anchors && (anchors->fill() || anchors->centerIn()) && !item->property("_q_QQuickSwipeView_warned").toBool()) {
119 qmlWarning(item) << "SwipeView has detected conflicting anchors. Unable to layout the item.";
120 item->setProperty("_q_QQuickSwipeView_warned", true);
121 }
123 item->setPosition({index * (contentItem->width() + spacing), 0});
124 else
125 item->setPosition({0, index * (contentItem->height() + spacing)});
126 item->setSize(QSizeF(contentItem->width(), contentItem->height()));
127}
128
130{
131 Q_Q(QQuickSwipeView);
132 const int count = q->count();
133 for (int i = 0; i < count; ++i) {
135 if (item)
136 resizeItem(i, item);
137 }
138}
139
144
152
160
162{
163 Q_Q(const QQuickSwipeView);
164 QQuickItem *currentItem = q->currentItem();
165 return currentItem ? currentItem->implicitWidth() : 0;
166}
167
169{
170 Q_Q(const QQuickSwipeView);
171 QQuickItem *currentItem = q->currentItem();
172 return currentItem ? currentItem->implicitHeight() : 0;
173}
174
184
195{
196 Q_D(const QQuickSwipeView);
197 return d->interactive;
198}
199
201{
202 Q_D(QQuickSwipeView);
203 if (d->interactive == interactive)
204 return;
205
206 d->interactive = interactive;
207 emit interactiveChanged();
208}
209
223{
224 Q_D(const QQuickSwipeView);
225 return d->orientation;
226}
227
229{
230 Q_D(QQuickSwipeView);
231 if (d->orientation == orientation)
232 return;
233
234 d->orientation = orientation;
236 d->resizeItems();
237 emit orientationChanged();
238}
239
250{
251 Q_D(const QQuickSwipeView);
252 return d->orientation == Qt::Horizontal;
253}
254
265{
266 Q_D(const QQuickSwipeView);
267 return d->orientation == Qt::Vertical;
268}
269
274
281
282void QQuickSwipeView::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
283{
284 Q_D(QQuickSwipeView);
285 QQuickContainer::geometryChange(newGeometry, oldGeometry);
286 d->resizeItems();
287}
288
290{
291 Q_D(QQuickSwipeView);
293 d->resizeItem(index, item);
294 QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item));
295 if (attached)
296 QQuickSwipeViewAttachedPrivate::get(attached)->update(this, index);
297}
298
300{
301 QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item));
302 if (attached)
303 QQuickSwipeViewAttachedPrivate::get(attached)->update(this, index);
304}
305
307{
308 QQuickSwipeViewAttached *attached = qobject_cast<QQuickSwipeViewAttached *>(qmlAttachedPropertiesObject<QQuickSwipeView>(item));
309 if (attached)
310 QQuickSwipeViewAttachedPrivate::get(attached)->update(nullptr, -1);
311}
312
313#if QT_CONFIG(accessibility)
314QAccessible::Role QQuickSwipeView::accessibleRole() const
315{
316 return QAccessible::PageTabList;
317}
318#endif
319
371
373{
374 if (i == currentIndex)
375 return;
376
378 const bool wasCurrent = q->isCurrentItem();
379 const bool wasNext = q->isNextItem();
380 const bool wasPrevious = q->isPreviousItem();
381
382 currentIndex = i;
383 if (wasCurrent != q->isCurrentItem())
384 emit q->isCurrentItemChanged();
385 if (wasNext != q->isNextItem())
386 emit q->isNextItemChanged();
387 if (wasPrevious != q->isPreviousItem())
388 emit q->isPreviousItemChanged();
389}
390
392{
394 int oldIndex = index;
395 QQuickSwipeView *oldView = swipeView;
396
397 index = newIndex;
398 swipeView = newView;
399
400 if (oldView != newView) {
401 if (oldView) {
404 }
405 if (newView) {
408 }
409 emit q->viewChanged();
410 }
411 if (oldIndex != newIndex)
412 emit q->indexChanged();
413
415}
416
419{
420 if (!qobject_cast<QQuickItem *>(parent))
421 qmlWarning(parent) << "SwipeView: attached properties must be accessed from within a child item";
422}
423
425{
426 Q_D(const QQuickSwipeViewAttached);
427 return d->index;
428}
429
431{
432 Q_D(const QQuickSwipeViewAttached);
433 return d->index != -1 && d->currentIndex != -1 && d->index == d->currentIndex;
434}
435
437{
438 Q_D(const QQuickSwipeViewAttached);
439 return d->swipeView;
440}
441
443{
444 Q_D(const QQuickSwipeViewAttached);
445 return d->index != -1 && d->currentIndex != -1 && d->index == d->currentIndex + 1;
446}
447
449{
450 Q_D(const QQuickSwipeViewAttached);
451 return d->index != -1 && d->currentIndex != -1 && d->index == d->currentIndex - 1;
452}
453
455
456#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:299
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
QQuickItem * fill
QQuickItem * centerIn
QQuickItem * itemAt(int index) const
void currentItemChanged()
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void currentIndexChanged()
QQuickDeferredPointer< QQuickItem > contentItem
virtual void itemImplicitWidthChanged(QQuickItem *)
virtual void itemImplicitHeightChanged(QQuickItem *)
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:63
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:114
qreal width
This property holds the width of this item.
Definition qquickitem.h:75
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
qreal implicitHeight
Definition qquickitem.h:115
qreal height
This property holds the height of this item.
Definition qquickitem.h:76
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(int index, 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 componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
void itemAdded(int index, QQuickItem *item) override
\inmodule QtCore\reentrant
Definition qrect.h:484
\inmodule QtCore
Definition qsize.h:208
Combined button and popup list for selecting options.
Orientation
Definition qnamespace.h:98
@ Horizontal
Definition qnamespace.h:99
@ Vertical
Definition qnamespace.h:100
GLuint index
[2]
GLenum GLenum GLsizei count
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
#define emit
double qreal
Definition qtypes.h:187
myObject disconnect()
[26]
QGraphicsItem * item
QQuickView * view
[0]