10#include <QtGui/qstylehints.h>
11#include <QtGui/private/qguiapplication_p.h>
12#include <QtGui/private/qeventpoint_p.h>
13#include <QtGui/qpa/qplatformtheme.h>
14#include <QtQml/qqmlinfo.h>
15#include <QtQuick/private/qquickanimation_p.h>
16#include <QtQuick/private/qquicktransition_p.h>
17#include <QtQuick/private/qquicktransitionmanager_p_p.h>
78 return qobject_cast<Attached*>(qmlAttachedPropertiesObject<QQuickSwipeDelegate>(
item,
false));
113 void reposition(PositionAnimation animationPolicy);
162 QQmlListProperty<QQuickAbstractAnimation> animations =
transition->animations();
163 const int count = animations.count(&animations);
169 QList<QQuickStateAction> actions;
181 return swipe->d_func();
270 const qreal relevantWidth = relevantItem ? relevantItem->width() : 0.0;
275 if (animationPolicy == AnimatePosition) {
277 contentItem->setProperty(
"x", contentItemX);
279 background->setProperty(
"x",
position * relevantWidth);
282 contentItem->setX(contentItemX);
284 background->setX(
position * relevantWidth);
357 qmlWarning(
control) <<
"left/right/behind properties may only be set when swipe.position is 0";
376 q->setPosition(newPosition);
419 d->warnAboutMixingDelegates();
424 d->warnAboutSettingDelegatesWhileVisible();
432 d->leftItem =
nullptr;
435 d->control->setFiltersChildMouseEvents(
d->hasDelegates());
452 if (
d->left ||
d->right) {
453 d->warnAboutMixingDelegates();
458 d->warnAboutSettingDelegatesWhileVisible();
465 delete d->behindItem;
466 d->behindItem =
nullptr;
469 d->control->setFiltersChildMouseEvents(
d->hasDelegates());
487 d->warnAboutMixingDelegates();
492 d->warnAboutSettingDelegatesWhileVisible();
500 d->rightItem =
nullptr;
503 d->control->setFiltersChildMouseEvents(
d->hasDelegates());
517 if (
item ==
d->leftItem)
527 d->leftItem->setZ(-2);
536 return d->behindItem;
542 if (
item ==
d->behindItem)
545 delete d->behindItem;
546 d->behindItem =
item;
552 d->behindItem->setZ(-2);
567 if (
item ==
d->rightItem)
577 d->rightItem->setZ(-2);
597 d->reposition(AnimatePosition);
638 return d->transition;
662 d->beginTransition(side);
663 d->wasComplete =
true;
664 d->velocityCalculator.reset();
665 d->positionBeforePress =
d->position;
668void QQuickSwipe::close()
674 if (
d->control->isPressed()) {
679 d->beginTransition(0.0);
680 d->waitForTransition =
true;
681 d->wasComplete =
false;
682 d->positionBeforePress = 0.0;
683 d->velocityCalculator.reset();
699 const bool extraAllocated =
extra.isAllocated();
701 if (((!
p->widthValid() || !extraAllocated || !
extra->hasBackgroundWidth))
702 || (extraAllocated && (
extra->hasLeftInset ||
extra->hasRightInset))) {
706 || (extraAllocated && (
extra->hasTopInset ||
extra->hasBottomInset))) {
723 q->mousePressEvent(
event);
733 if (swipePrivate->complete)
739 swipePrivate->positionBeforePress = swipePrivate->position;
740 swipePrivate->velocityCalculator.startMeasuring(
event->position().toPoint(),
event->timestamp());
763 if (!swipePrivate->enabled)
771 if (!swipePrivate->left && !swipePrivate->right && !swipePrivate->behind)
774 if (
item !=
q && swipePrivate->complete) {
785 const qreal distance = (
event->globalPosition() -
event->points().first().globalPressPosition()).
x();
786 if (!
q->keepMouseGrab()) {
791 if (
window && overThreshold) {
793 if (!grabber || !grabber->keepMouseGrab()) {
795 q->setKeepMouseGrab(
true);
804 if (
q->keepMouseGrab()) {
809 if (swipePrivate->behind
810 || ((swipePrivate->left || swipePrivate->right)
812 || (swipePrivate->positionBeforePress == -1.0 &&
distance >= 0.0)
813 || (swipePrivate->positionBeforePress == 1.0 &&
distance <= 0.0)))) {
820 const qreal normalizedDistance = relevantItem ?
distance / relevantItem->
width() : 0.0;
842 }
else if (!swipePrivate->wasComplete) {
845 position =
distance > 0 ? normalizedDistance - 1.0 : normalizedDistance + 1.0;
848 if (swipePrivate->isTransitioning())
849 swipePrivate->transitionManager->cancel();
854 if (
event->position().toPoint().y() < 0 ||
event->position().toPoint().y() >
height) {
857 q->setPressed(
false);
863 return q->keepMouseGrab();
872 swipePrivate->velocityCalculator.stopMeasuring(
event->position().toPoint(),
event->timestamp());
874 const bool hadGrabbedMouse =
q->keepMouseGrab();
875 q->setKeepMouseGrab(
false);
879 if (!
qIsNull(swipePrivate->position))
880 q->setPressed(
false);
888 if (hadGrabbedMouse) {
891 q->setPressed(
false);
898 if (
item !=
q && (swipePrivate->complete || swipePrivate->wasComplete))
902 const qreal swipeVelocity = swipePrivate->velocityCalculator.velocity().x();
903 if (swipePrivate->position > 0.5 ||
905 swipePrivate->beginTransition(1.0);
906 swipePrivate->wasComplete =
true;
907 }
else if (swipePrivate->position < -0.5 ||
909 swipePrivate->beginTransition(-1.0);
910 swipePrivate->wasComplete =
true;
911 }
else if (!swipePrivate->isTransitioning()) {
916 swipePrivate->beginTransition(0.0);
917 swipePrivate->wasComplete =
false;
924 return hadGrabbedMouse;
934 QMutableEventPoint::setPosition(localizedEvent.point(0), localPos);
936 q->setPressed(!localizedEvent.isAccepted());
949 QVarLengthArray<QQuickItem *, 16> itemAndChildren;
950 itemAndChildren.append(
item);
951 for (
int i = 0;
i < itemAndChildren.size(); ++
i) {
952 auto item = itemAndChildren.at(
i);
956 const bool wasPressed = attached->isPressed();
959 emit attached->clicked();
964 itemAndChildren.append(
child);
976 && !
item->property(
"_q_QQuickSwipeDelegate_warned").toBool()) {
978 item->setProperty(
"_q_QQuickSwipeDelegate_warned",
true);
993 if (!swipePrivate->complete) {
1016 if (!childItem || !
event)
1021 if (childItem->acceptedMouseButtons() &&
1022 childItem->contains(childItem->mapFromScene(
event->scenePosition()))) {
1025 const auto &
childItems = childItem->childItems();
1238 switch (
event->type()) {
1248 return d->handleMouseReleaseEvent(
child, mouseEvent);
1255 attached->setPressed(
false);
1270 if (!swipePrivate->enabled)
1273 swipePrivate->positionBeforePress = swipePrivate->position;
1274 swipePrivate->velocityCalculator.startMeasuring(
event->position().toPoint(),
event->timestamp());
1276 if (swipePrivate->complete) {
1277 d->pressedItem =
d->getPressedItem(
d->swipe.rightItem(),
event);
1278 if (!
d->pressedItem)
1279 d->pressedItem =
d->getPressedItem(
d->swipe.leftItem(),
event);
1281 d->handleMousePressEvent(
d->pressedItem,
event);
1289 d->handleMouseMoveEvent(
this,
event);
1293 d->handleMouseMoveEvent(
d->pressedItem,
event);
1302 if (
d->pressedItem) {
1303 if (
d->pressedItem->acceptedMouseButtons())
1304 d->handleMouseReleaseEvent(
d->pressedItem,
event);
1305 d->pressedItem =
nullptr;
1314 auto item =
d->swipe.rightItem();
1316 if (
auto control = qmlobject_cast<QQuickControl *>(
item))
1320 attached->setPressed(
false);
1322 item =
d->swipe.leftItem();
1324 if (
auto control = qmlobject_cast<QQuickControl *>(
item))
1328 attached->setPressed(
false);
1332 d->pressedItem =
nullptr;
1356 swipePrivate->reposition(DontAnimatePosition);
1365#if QT_CONFIG(accessibility)
1366QAccessible::Role QQuickSwipeDelegate::accessibleRole()
const
1368 return QAccessible::ListItem;
1412 qWarning() <<
"Attached properties of SwipeDelegate must be accessed through an Item";
1520#include "moc_qquickswipe_p.cpp"
1521#include "moc_qquickswipedelegate_p.cpp"
static bool sendEvent(QObject *receiver, QEvent *event)
Sends event event directly to receiver receiver, using the notify() function.
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise,...
QPointF mapToItem(const QGraphicsItem *item, const QPointF &point) const
Maps the point point, which is in this item's coordinate system, to item's coordinate system,...
QList< QGraphicsItem * > childItems() const
void setParentItem(QGraphicsItem *parent)
Sets this item's parent item to newParent.
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons that this item accepts mouse events for.
QPointF mapFromScene(const QPointF &point) const
Maps the point point, which is in this item's scene's coordinate system, to this item's coordinate sy...
bool isAncestorOf(const QGraphicsItem *child) const
Returns true if this item is an ancestor of child (i.e., if this item is child's parent,...
static QStyleHints * styleHints()
Returns the application's style hints.
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
\inmodule QtCore\compares equality \compareswith equality QLine \endcompareswith
qreal length() const
Returns the length of the line.
The QPalette class contains color groups for each widget state.
\inmodule QtCore\reentrant
The QQmlComponent class encapsulates a QML component definition.
QList< QQmlError > errors() const
Returns the list of errors that occurred during the last compile or create operation.
The QQmlContext class defines a context within a QML engine.
virtual void componentComplete()=0
Invoked after the root component that caused this instantiation has completed construction.
The QQmlProperty class abstracts accessing properties on objects created from QML.
void setDefaultTarget(const QQmlProperty &)
QQuickDeferredPointer< QQuickItem > background
QQuickDeferredPointer< QQuickItem > contentItem
qreal getRightInset() const
qreal getLeftInset() const
qreal getBottomInset() const
QLazilyAllocated< ExtraData > extra
qreal getTopInset() const
virtual void resizeContent()
static QQuickControlPrivate * get(QQuickControl *control)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
static QQuickItemPrivate * get(QQuickItem *item)
QList< QQuickItem * > childItems
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
virtual void mouseReleaseEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse release events for an item.
qreal y
Defines the item's y position relative to its parent.
void setAcceptTouchEvents(bool accept)
If enabled is true, this sets the item to accept touch events; otherwise, touch events are not accept...
QQuickWindow * window() const
Returns the window in which this item is rendered.
virtual void mousePressEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
qreal width
This property holds the width of this item.
bool filtersChildMouseEvents() const
Returns whether pointer events intended for this item's children should be filtered through this item...
bool isComponentComplete() const
Returns true if construction of the QML component is complete; otherwise returns false.
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
QQuickSwipeDelegateAttached(QObject *object=nullptr)
void setPressed(bool pressed)
bool handleMouseMoveEvent(QQuickItem *item, QMouseEvent *event)
void forwardMouseEvent(QMouseEvent *event, QQuickItem *destination, QPointF localPos)
QQuickSwipeDelegatePrivate(QQuickSwipeDelegate *control)
void resizeBackground() override
QPalette defaultPalette() const override
bool attachedObjectsSetPressed(QQuickItem *item, QPointF scenePos, bool pressed, bool cancel=false)
QQuickItem * getPressedItem(QQuickItem *childItem, QMouseEvent *event) const
bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event)
bool handleMousePressEvent(QQuickItem *item, QMouseEvent *event)
void resizeContent() override
void mousePressEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
void componentComplete() override
Invoked after the root component that caused this instantiation has completed construction.
static QQuickSwipeDelegateAttached * qmlAttachedProperties(QObject *object)
void mouseUngrabEvent() override
This event handler can be reimplemented in a subclass to be notified when a mouse ungrab event has oc...
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
QQuickSwipeDelegate(QQuickItem *parent=nullptr)
void touchEvent(QTouchEvent *event) override
This event handler can be reimplemented in a subclass to receive touch events for an item.
void mouseMoveEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
void mouseReleaseEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse release events for an item.
bool childMouseEventFilter(QQuickItem *child, QEvent *event) override
Reimplement this method to filter the pointer events that are received by this item's children.
QFont defaultFont() const override
void warnAboutMixingDelegates()
void createAndShowRightItem()
QQuickTransition * transition
void createAndShowLeftItem()
QQuickSwipePrivate(QQuickSwipeDelegate *control)
QQuickVelocityCalculator velocityCalculator
QScopedPointer< QQuickSwipeTransitionManager > transitionManager
QQuickItem * showRelevantItemForPosition(qreal position)
qreal positionBeforePress
bool isTransitioning() const
void reposition(PositionAnimation animationPolicy)
bool hasDelegates() const
void createAndShowBehindItem()
QQuickItem * createDelegateItem(QQmlComponent *component)
static QQuickSwipePrivate * get(QQuickSwipe *swipe)
QQuickItem * createRelevantItemForDistance(qreal distance)
void beginTransition(qreal position)
QQuickSwipeDelegate * control
void warnAboutSettingDelegatesWhileVisible()
QQuickSwipeTransitionManager(QQuickSwipe *swipe)
void transition(QQuickTransition *transition, qreal position)
void setRightItem(QQuickItem *item)
void setComplete(bool complete)
void setBehindItem(QQuickItem *item)
void setEnabled(bool enabled)
QQuickSwipe(QQuickSwipeDelegate *control)
void setBehind(QQmlComponent *behind)
void setTransition(QQuickTransition *transition)
void setPosition(qreal position)
void setLeftItem(QQuickItem *item)
QQuickTransition * transition
void setLeft(QQmlComponent *left)
void setRight(QQmlComponent *right)
static QPalette palette(Scope scope)
static QFont font(Scope scope)
void transition(const QList< QQuickStateAction > &, QQuickTransition *transition, QObject *defaultTarget=nullptr)
static bool dragOverThreshold(qreal d, Qt::Axis axis, const QEventPoint *tp, int startDragThreshold=-1)
\inmodule QtCore\reentrant
constexpr qreal width() const noexcept
Returns the width of the rectangle.
void reset(T *other=nullptr) noexcept(noexcept(Cleanup::cleanup(std::declval< T * >())))
Deletes the existing object it is pointing to (if any), and sets its pointer to other.
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QTouchEvent class contains parameters that describe a touch event.
Combined button and popup list for selecting options.
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char * destination
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
bool qFuzzyIsNull(qfloat16 f) noexcept
bool qIsNull(qfloat16 f) noexcept
constexpr T qAbs(const T &t)
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLsizei GLsizei GLfloat distance
GLdouble GLdouble GLdouble GLdouble q
static qreal component(const QPointF &point, unsigned int i)
void qmlExecuteDeferred(QObject *object)
QQmlContext * qmlContext(const QObject *obj)
Q_QML_EXPORT QQmlInfo qmlWarning(const QObject *me)
static qreal adjustedPosition(QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
static QQuickAttachedPropertyPropagator * attachedObject(const QMetaObject *type, QObject *object, bool create=false)
QQuickAnchors * anchors(QQuickItem *item)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
static bool isChildOrGrandchildOf(QQuickItem *child, QQuickItem *item)
static const qreal exposeVelocityThreshold
static void warnIfHorizontallyAnchored(QQuickItem *item, const QString &itemName)
QLatin1StringView QLatin1String
#define QStringLiteral(str)