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
qquickpageindicator.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
5#include "qquickcontrol_p_p.h"
6
7#include <QtCore/qmath.h>
8#include <QtQuick/private/qquickitem_p.h>
9
11
16
54{
55 Q_DECLARE_PUBLIC(QQuickPageIndicator)
56
57public:
58 bool handlePress(const QPointF &point, ulong timestamp) override;
59 bool handleMove(const QPointF &point, ulong timestamp) override;
60 bool handleRelease(const QPointF &point, ulong timestamp) override;
61 void handleUngrab() override;
62
63 QQuickItem *itemAt(const QPointF &pos) const;
64 void updatePressed(bool pressed, const QPointF &pos = QPointF());
66
67 void itemChildAdded(QQuickItem *, QQuickItem *child) override;
68
69 int count = 0;
70 int currentIndex = 0;
71 bool interactive = false;
74};
75
77{
78 QQuickControlPrivate::handlePress(point, timestamp);
79 if (interactive) {
80 updatePressed(true, point);
81 return true;
82 }
83 return false;
84}
85
87{
88 QQuickControlPrivate::handleMove(point, timestamp);
89 if (interactive) {
90 updatePressed(true, point);
91 return true;
92 }
93 return false;
94}
95
97{
100 if (interactive) {
102 q->setCurrentIndex(contentItem->childItems().indexOf(pressedItem));
103 updatePressed(false);
104 return true;
105 }
106 return false;
107}
108
115
117{
118 Q_Q(const QQuickPageIndicator);
119 if (!contentItem || !q->contains(pos))
120 return nullptr;
121
122 QPointF contentPos = q->mapToItem(contentItem, pos);
123 QQuickItem *item = contentItem->childAt(contentPos.x(), contentPos.y());
124 while (item && item->parentItem() != contentItem)
125 item = item->parentItem();
127 return item;
128
129 // find the nearest
130 qreal distance = qInf();
131 QQuickItem *nearest = nullptr;
132 const auto childItems = contentItem->childItems();
133 for (QQuickItem *child : childItems) {
134 if (QQuickItemPrivate::get(child)->isTransparentForPositioner())
135 continue;
136
137 QPointF center = child->boundingRect().center();
138 QPointF pt = contentItem->mapToItem(child, contentPos);
139
140 qreal len = QLineF(center, pt).length();
141 if (len < distance) {
142 distance = len;
143 nearest = child;
144 }
145 }
146 return nearest;
147}
148
150{
151 QQuickItem *prevItem = pressedItem;
152 pressedItem = pressed ? itemAt(pos) : nullptr;
153 if (prevItem != pressedItem) {
154 setContextProperty(prevItem, QStringLiteral("pressed"), false);
155 setContextProperty(pressedItem, QStringLiteral("pressed"), pressed);
156 }
157}
158
160{
162 if (context && context->isValid()) {
163 context = context->parentContext();
164 if (context && context->isValid())
165 context->setContextProperty(name, value);
166 }
167}
168
174
179
181{
183 if (d->contentItem)
184 QQuickItemPrivate::get(d->contentItem)->removeItemChangeListener(d, QQuickItemPrivate::Children);
185}
186
193{
194 Q_D(const QQuickPageIndicator);
195 return d->count;
196}
197
199{
201 if (d->count == count)
202 return;
203
204 d->count = count;
206}
207
214{
215 Q_D(const QQuickPageIndicator);
216 return d->currentIndex;
217}
218
220{
222 if (d->currentIndex == index)
223 return;
224
225 d->currentIndex = index;
227}
228
247{
248 Q_D(const QQuickPageIndicator);
249 return d->interactive;
250}
251
253{
255 if (d->interactive == interactive)
256 return;
257
258 d->interactive = interactive;
259 if (interactive) {
261#if QT_CONFIG(quicktemplates2_multitouch)
263#endif
264#if QT_CONFIG(cursor)
266#endif
267 } else {
269#if QT_CONFIG(quicktemplates2_multitouch)
271#endif
272#if QT_CONFIG(cursor)
273 unsetCursor();
274#endif
275 }
277}
278
291{
292 Q_D(const QQuickPageIndicator);
293 return d->delegate;
294}
295
297{
299 if (d->delegate == delegate)
300 return;
301
302 d->delegate = delegate;
304}
305
307{
309 QQuickControl::contentItemChange(newItem, oldItem);
310 if (oldItem)
311 QQuickItemPrivate::get(oldItem)->removeItemChangeListener(d, QQuickItemPrivate::Children);
312 if (newItem)
313 QQuickItemPrivate::get(newItem)->addItemChangeListener(d, QQuickItemPrivate::Children);
314}
315
316#if QT_CONFIG(quicktemplates2_multitouch)
318{
320 if (d->interactive)
322 else
323 event->ignore(); // QTBUG-61785
324}
325#endif
326
327#if QT_CONFIG(accessibility)
328QAccessible::Role QQuickPageIndicator::accessibleRole() const
329{
330 return QAccessible::Indicator;
331}
332#endif
333
335
336#include "moc_qquickpageindicator_p.cpp"
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
Definition qline.h:192
qreal length() const
Returns the length of the line.
Definition qline.cpp:548
\inmodule QtCore\reentrant
Definition qpoint.h:217
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
Definition qpoint.h:343
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
Definition qpoint.h:348
The QQmlComponent class encapsulates a QML component definition.
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
virtual bool handlePress(const QPointF &point, ulong timestamp)
QQuickDeferredPointer< QQuickItem > contentItem
virtual void handleUngrab()
virtual bool handleRelease(const QPointF &point, ulong timestamp)
virtual bool handleMove(const QPointF &point, ulong timestamp)
virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem)
static QQuickItemPrivate * get(QQuickItem *item)
bool isTransparentForPositioner() const
QList< QQuickItem * > childItems
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
QList< QQuickItem * > childItems() const
Returns the children of this item.
Q_INVOKABLE QPointF mapToItem(const QQuickItem *item, const QPointF &point) const
Maps the given point in this item's coordinate system to the equivalent point within item's coordinat...
void setAcceptTouchEvents(bool accept)
If enabled is true, this sets the item to accept touch events; otherwise, touch events are not accept...
Q_INVOKABLE QQuickItem * childAt(qreal x, qreal y) const
\qmlmethod QtQuick::Item::childAt(real x, real y)
virtual Q_INVOKABLE bool contains(const QPointF &point) const
\qmlmethod bool QtQuick::Item::contains(point point)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons accepted by this item to buttons.
virtual void touchEvent(QTouchEvent *event)
This event handler can be reimplemented in a subclass to receive touch events for an item.
Indicates the currently active page.
void updatePressed(bool pressed, const QPointF &pos=QPointF())
bool handleRelease(const QPointF &point, ulong timestamp) override
bool handleMove(const QPointF &point, ulong timestamp) override
bool handlePress(const QPointF &point, ulong timestamp) override
void setContextProperty(QQuickItem *item, const QString &name, const QVariant &value)
QQuickItem * itemAt(const QPointF &pos) const
void itemChildAdded(QQuickItem *, QQuickItem *child) override
void setDelegate(QQmlComponent *delegate)
bool isInteractive() const
\qmlproperty bool QtQuick.Controls::PageIndicator::interactive
void setInteractive(bool interactive)
void setCurrentIndex(int index)
QQuickPageIndicator(QQuickItem *parent=nullptr)
void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QTouchEvent class contains parameters that describe a touch event.
Definition qevent.h:917
\inmodule QtCore
Definition qvariant.h:65
Combined button and popup list for selecting options.
@ LeftButton
Definition qnamespace.h:58
@ NoButton
Definition qnamespace.h:57
@ ArrowCursor
static void * context
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static void unsetCursor(QWindow *w)
Q_CORE_EXPORT Q_DECL_CONST_FUNCTION double qInf()
GLuint index
[2]
GLenum GLenum GLsizei count
GLsizei GLsizei GLfloat distance
GLuint name
struct _cl_event * event
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLenum GLsizei len
QQmlContext * qmlContext(const QObject *obj)
Definition qqml.cpp:75
#define QStringLiteral(str)
#define emit
unsigned long ulong
Definition qtypes.h:35
double qreal
Definition qtypes.h:187
item setCursor(Qt::IBeamCursor)
[1]
QGraphicsItem * item
QLayoutItem * child
[0]
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
Definition qlist.h:962