7#if QT_CONFIG(quick_draganddrop)
11#include <private/qqmldata_p.h>
12#include <private/qsgadaptationlayer_p.h>
14#include <QtGui/private/qguiapplication_p.h>
15#include <QtGui/qevent.h>
16#include <QtGui/qstylehints.h>
29 propagateComposedEvents(
false), overThreshold(
false),
30 pressAndHoldInterval(-1)
31#if QT_CONFIG(quick_draganddrop)
42#if QT_CONFIG(quick_draganddrop)
54 q->setAcceptTouchEvents(
false);
55 q->setFiltersChildMouseEvents(
true);
56 if (qmlMaVisualTouchDebugging()) {
89#if QT_CONFIG(wheelevent)
90bool QQuickMouseAreaPrivate::isWheelConnected()
120 for (
int ii =
children.size() - 1; ii >= 0; --ii) {
122 if (!
child->isVisible() || !
child->isEnabled())
132 if (!ma->d_func()->isClickConnected())
136 if (!ma->d_func()->isDoubleClickConnected())
140 if (!ma->d_func()->isPressAndHoldConnected())
426 return d->lastPos.x();
432 return d->lastPos.y();
454 if (
a !=
d->enabled) {
480 return d->scrollGestureEnabled;
486 if (
e !=
d->scrollGestureEnabled) {
487 d->scrollGestureEnabled =
e;
488 emit scrollGestureEnabledChanged();
511 return d->preventStealing;
517 if (prevent !=
d->preventStealing) {
518 d->preventStealing = prevent;
588 return d->propagateComposedEvents;
594 if (prevent !=
d->propagateComposedEvents) {
595 d->propagateComposedEvents = prevent;
630 d->stealMouse =
d->preventStealing;
631 d->overThreshold =
false;
635 d->longPress =
false;
637#if QT_CONFIG(quick_draganddrop)
639 d->drag->setActive(
false);
642 d->startScene =
event->scenePosition();
645 if (
event->isAccepted())
653 if (!
d->enabled && !
d->pressed) {
670#if QT_CONFIG(quick_draganddrop)
671 if (
d->drag &&
d->drag->target()) {
673 d->targetStartPos =
d->drag->target()->parentItem()
674 ?
d->drag->target()->parentItem()->mapToScene(
d->drag->target()->position())
675 :
d->drag->target()->position();
681 startLocalPos = drag()->target()->parentItem()->mapFromScene(
d->startScene);
682 curLocalPos = drag()->target()->parentItem()->mapFromScene(
event->scenePosition());
684 startLocalPos =
d->startScene;
685 curLocalPos =
event->scenePosition();
688 if (
keepMouseGrab() &&
d->stealMouse &&
d->overThreshold && !
d->drag->active())
689 d->drag->setActive(
true);
691 QPointF startPos =
d->drag->target()->parentItem()
692 ?
d->drag->target()->parentItem()->mapFromScene(
d->targetStartPos)
698 QPointF dragPos =
d->drag->target()->position();
699 QPointF boundedDragPos = dragPos;
701 dragPos.
setX(startPos.
x() + curLocalPos.
x() - startLocalPos.
x());
708 dragPos.
setY(startPos.
y() + curLocalPos.
y() - startLocalPos.
y());
715 QPointF targetPos =
d->drag->target()->position();
717 if (
d->drag->active()) {
718 d->drag->target()->setPosition(boundedDragPos);
727 if (!
d->overThreshold && (((targetPos.
x() != boundedDragPos.
x()) && dragOverThresholdX) ||
728 ((targetPos.
y() != boundedDragPos.
y()) && dragOverThresholdY)))
730 d->overThreshold =
true;
731 if (
d->drag->smoothed())
732 d->startScene =
event->scenePosition();
737 d->stealMouse =
true;
745 me.
reset(
d->lastPos.x(),
d->lastPos.y(),
d->lastButton,
d->lastButtons,
d->lastModifiers,
false,
d->longPress,
event->flags());
746#if QT_DEPRECATED_SINCE(6, 6)
747 me.setSource(
event->source());
759 d->stealMouse =
false;
760 d->overThreshold =
false;
761 if (!
d->enabled && !
d->pressed) {
768#if QT_CONFIG(quick_draganddrop)
770 d->drag->setActive(
false);
776 if (
w &&
w->mouseGrabberItem() ==
this)
778 if (!
d->preventStealing)
782 d->doubleClick =
false;
791 me.
reset(
d->lastPos.x(),
d->lastPos.y(),
d->lastButton,
d->lastButtons,
d->lastModifiers,
true,
792 false,
event->flags());
793#if QT_DEPRECATED_SINCE(6, 6)
794 me.setSource(
event->source());
801 d->doubleClick =
d->isDoubleClickConnected() || me.
isAccepted();
812 if (!
d->enabled && !
d->pressed) {
823 d->lastPos =
event->position();
824 d->lastModifiers =
event->modifiers();
841 if (!
d->enabled && !
d->pressed) {
843 }
else if (
d->lastPos !=
event->position()) {
844 d->lastPos =
event->position();
845 d->lastModifiers =
event->modifiers();
862 if (!
d->enabled && !
d->pressed && !
d->hovered)
871#if QT_CONFIG(wheelevent)
872void QQuickMouseArea::wheelEvent(QWheelEvent *
event)
876 QQuickItem::wheelEvent(
event);
882 we.setAccepted(
d->isWheelConnected());
884 if (!we.isAccepted())
885 QQuickItem::wheelEvent(
event);
889void QQuickMouseArea::ungrabMouse()
896 d->stealMouse =
false;
897 d->doubleClick =
false;
898 d->overThreshold =
false;
901#if QT_CONFIG(quick_draganddrop)
903 d->drag->setActive(
false);
908 emit containsPressChanged();
912 qCDebug(lcHoverTrace) <<
"losing hover: not under the mouse";
936 QQuickItem *grabber =
c ?
c->mouseGrabberItem() :
nullptr;
937 bool stealThisEvent =
d->stealMouse;
943 switch (
event->type()) {
952 stealThisEvent =
d->stealMouse;
957 grabber =
c ?
c->mouseGrabberItem() :
nullptr;
958 if (grabber && stealThisEvent && !grabber->
keepMouseGrab() && grabber !=
this)
961 return stealThisEvent;
965 d->pressed &=
~event->button();
969 d->stealMouse =
false;
970 d->overThreshold =
false;
971 if (
c &&
c->mouseGrabberItem() ==
this)
975 emit containsPressChanged();
977 qCDebug(lcHoverTrace) <<
"losing hover: button released";
993 || !
d->drag || !
d->drag->filterChildren()
1013 if (
event->timerId() ==
d->pressAndHoldTimer.timerId()) {
1014 d->pressAndHoldTimer.stop();
1015#if QT_CONFIG(quick_draganddrop)
1016 bool dragged =
d->drag &&
d->drag->active();
1018 bool dragged =
false;
1020 if (
d->pressed && dragged ==
false &&
d->hovered ==
true) {
1021 d->longPress =
true;
1023 me.
reset(
d->lastPos.x(),
d->lastPos.y(),
d->lastButton,
d->lastButtons,
d->lastModifiers,
false,
d->longPress,
d->lastFlags);
1024#if QT_DEPRECATED_SINCE(6, 6)
1032 d->longPress =
false;
1042 if (
d->lastScenePos.isNull)
1044 else if (newGeometry.
x() != oldGeometry.
x() || newGeometry.
y() != oldGeometry.
y())
1055 if (
d->pressed && !
d->effectiveEnable)
1070 QPointF scenePos{
d->window->mapFromGlobal(globalPos) };
1086 if (hoverItem.first ==
this) {
1088 d->lastScenePos = scenePos;
1124 return d_func()->hoverEnabled;
1130 if (
h ==
d->hoverEnabled)
1133 d->hoverEnabled =
h;
1180 return d->pressed &&
d->hovered;
1186 if (
d->hovered !=
h) {
1187 qCDebug(lcHoverTrace) <<
this <<
d->hovered <<
"->" <<
h;
1192 emit containsPressChanged();
1233#if QT_CONFIG(quick_draganddrop)
1234 bool dragged =
d->drag &&
d->drag->active();
1236 bool dragged =
false;
1238 bool wasPressed =
d->pressed &
button;
1239 bool isclick = wasPressed &&
p ==
false && dragged ==
false &&
d->hovered ==
true;
1240 Qt::MouseButtons oldPressed =
d->pressed;
1242 if (wasPressed !=
p) {
1244 me.
reset(
d->lastPos.x(),
d->lastPos.y(),
d->lastButton,
d->lastButtons,
d->lastModifiers, isclick,
d->longPress,
d->lastFlags);
1245#if QT_DEPRECATED_SINCE(6, 6)
1250 if (!
d->doubleClick)
1265 emit containsPressChanged();
1269 d->pressed &= ~button;
1274 emit containsPressChanged();
1277 if (isclick && !
d->longPress && !
d->doubleClick){
1334#if QT_CONFIG(cursor)
1342 if (
cursor().shape() == shape)
1347 emit cursorShapeChanged();
1372 return d->pressAndHoldInterval > -1 ?
1379 if (interval !=
d->pressAndHoldInterval) {
1380 d->pressAndHoldInterval = interval;
1381 emit pressAndHoldIntervalChanged();
1388 if (
d->pressAndHoldInterval > -1) {
1389 d->pressAndHoldInterval = -1;
1390 emit pressAndHoldIntervalChanged();
1443#if QT_CONFIG(quick_draganddrop)
1458 if (!qmlMaVisualTouchDebugging())
1462 if (!rectangle) rectangle =
d->sceneGraphContext()->createInternalRectangleNode();
1472#include "moc_qquickmousearea_p.cpp"
The QColor class provides colors based on RGB, HSV or CMYK values.
Qt::CursorShape shape() const
Returns the cursor shape identifier.
static qint64 currentSecsSinceEpoch() noexcept
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise,...
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...
static struct QGuiApplicationPrivate::QLastCursorPosition lastCursorPosition
static QStyleHints * styleHints()
Returns the application's style hints.
\inmodule QtCore\reentrant
constexpr qreal x() const noexcept
Returns the x coordinate of this point.
constexpr qreal y() const noexcept
Returns the y coordinate of this point.
constexpr void setY(qreal y) noexcept
Sets the y coordinate of this point to the given finite y coordinate.
constexpr void setX(qreal x) noexcept
Sets the x coordinate of this point to the given finite x coordinate.
virtual void setAccepted(bool accepted) override
\reimp
QFlatMap< QPointer< QQuickItem >, uint > hoverItems
bool hoveredLeafItemFound
static bool dragOverThreshold(qreal d, Qt::Axis axis, QMouseEvent *event, int startDragThreshold=-1)
bool deliverHoverEvent(const QPointF &scenePos, const QPointF &lastScenePos, Qt::KeyboardModifiers modifiers, ulong timestamp)
QList< QQuickItem * > paintOrderChildItems() const
Qt::MouseButtons acceptedMouseButtons() const
QQmlListProperty< QQuickItem > children()
static QQuickItemPrivate * get(QQuickItem *item)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
QPointF mapToScene(const QPointF &point) const
Maps the given point in this item's coordinate system to the equivalent point within the scene's coor...
virtual void mouseReleaseEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse release events for an item.
virtual void hoverEnterEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-enter events for an item.
virtual void mouseDoubleClickEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse double-click events for an ite...
Qt::MouseButtons acceptedMouseButtons() const
Returns the mouse buttons accepted by this item.
virtual void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry)
void setAcceptHoverEvents(bool enabled)
If enabled is true, this sets the item to accept hover events; otherwise, hover events are not accept...
QPointF mapFromScene(const QPointF &point) const
Maps the given point in the scene's coordinate system to the equivalent point within this item's coor...
virtual void hoverMoveEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-move events for an item.
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.
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.
QQuickItem * parentItem() const
virtual void itemChange(ItemChange, const ItemChangeData &)
Called when change occurs for this item.
bool keepMouseGrab() const
Returns whether mouse input should exclusively remain with this item.
void setKeepMouseGrab(bool)
Sets whether the mouse input should remain exclusively with this item.
qreal height
This property holds the height of this item.
virtual bool childMouseEventFilter(QQuickItem *, QEvent *)
Reimplement this method to filter the pointer events that are received by this item's children.
ItemChange
Used in conjunction with QQuickItem::itemChange() to notify the item about certain types of changes.
bool isUnderMouse() const
@ ItemClipsChildrenToShape
virtual void hoverLeaveEvent(QHoverEvent *event)
This event handler can be reimplemented in a subclass to receive hover-leave events for an item.
virtual void mouseMoveEvent(QMouseEvent *event)
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
~QQuickMouseAreaPrivate()
bool isDoubleClickConnected()
void saveEvent(QMouseEvent *event)
Qt::MouseButtons lastButtons
bool propagateHelper(QQuickMouseEvent *, QQuickItem *, const QPointF &, PropagateType)
Qt::MouseButton lastButton
void propagate(QQuickMouseEvent *event, PropagateType)
Qt::KeyboardModifiers lastModifiers
Qt::MouseEventFlags lastFlags
bool isPressAndHoldConnected()
QQmlNullableValue< QPointF > lastScenePos
bool propagateComposedEvents
bool isEnabled() const
\qmlproperty bool QtQuick::MouseArea::enabled This property holds whether the item accepts mouse even...
void setAcceptedButtons(Qt::MouseButtons buttons)
bool setPressed(Qt::MouseButton button, bool p, Qt::MouseEventSource source)
void hoverMoveEvent(QHoverEvent *event) override
This event handler can be reimplemented in a subclass to receive hover-move events for an item.
void released(QQuickMouseEvent *mouse)
void mousePressEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse press events for an item.
bool childMouseEventFilter(QQuickItem *i, QEvent *e) override
Reimplement this method to filter the pointer events that are received by this item's children.
void itemChange(ItemChange change, const ItemChangeData &value) override
Called when change occurs for this item.
void mouseXChanged(QQuickMouseEvent *mouse)
void mouseUngrabEvent() override
This event handler can be reimplemented in a subclass to be notified when a mouse ungrab event has oc...
void pressedButtonsChanged()
void mouseReleaseEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse release events for an item.
void resetPressAndHoldInterval()
bool isScrollGestureEnabled() const
\qmlproperty bool QtQuick::MouseArea::scrollGestureEnabled
void hoverEnabledChanged()
bool sendMouseEvent(QMouseEvent *event)
void clicked(QQuickMouseEvent *mouse)
void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override
void setPreventStealing(bool prevent)
void hoverLeaveEvent(QHoverEvent *event) override
This event handler can be reimplemented in a subclass to receive hover-leave events for an item.
void touchUngrabEvent() override
This event handler can be reimplemented in a subclass to be notified when a touch ungrab event has oc...
void positionChanged(QQuickMouseEvent *mouse)
void doubleClicked(QQuickMouseEvent *mouse)
void propagateComposedEventsChanged()
void setPropagateComposedEvents(bool propagate)
Qt::MouseButtons acceptedButtons
void mouseDoubleClickEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse double-click events for an ite...
void preventStealingChanged()
void pressAndHold(QQuickMouseEvent *mouse)
void acceptedButtonsChanged()
void setPressAndHoldInterval(int interval)
bool propagateComposedEvents
void mouseYChanged(QQuickMouseEvent *mouse)
bool hovered() const
\qmlproperty bool QtQuick::MouseArea::containsMouse This property holds whether the mouse is currentl...
void hoverEnterEvent(QHoverEvent *event) override
This event handler can be reimplemented in a subclass to receive hover-enter events for an item.
QSGNode * updatePaintNode(QSGNode *, UpdatePaintNodeData *) override
\qmlpropertygroup QtQuick::MouseArea::drag \qmlproperty Item QtQuick::MouseArea::drag....
FINALint pressAndHoldInterval
bool isPressed() const
\qmlproperty bool QtQuick::MouseArea::pressed This property holds whether any of the \l acceptedButto...
void setScrollGestureEnabled(bool)
FINALQt::MouseButtons pressedButtons
void mouseMoveEvent(QMouseEvent *event) override
This event handler can be reimplemented in a subclass to receive mouse move events for an item.
void timerEvent(QTimerEvent *event) override
This event handler can be reimplemented in a subclass to receive timer events for the object.
QQuickMouseArea(QQuickItem *parent=nullptr)
\qmltype MouseArea \instantiates QQuickMouseArea \inqmlmodule QtQuick
void setHoverEnabled(bool h)
\qmlproperty int QtQuick::KeyEvent::key
void setAccepted(bool accepted)
void reset(qreal x, qreal y, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, bool isClick=false, bool wasHeld=false, Qt::MouseEventFlags flags={ })
void setPosition(const QPointF &point)
\qmlproperty real QtQuick::MouseEvent::x \qmlproperty real QtQuick::MouseEvent::y
static QQuickWindowPrivate * get(QQuickWindow *c)
QQuickDeliveryAgentPrivate * deliveryAgentPrivate() const
\qmltype Window \instantiates QQuickWindow \inqmlmodule QtQuick
QQuickItem * contentItem
\qmlattachedproperty Item Window::contentItem
\inmodule QtCore\reentrant
constexpr qreal y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
virtual void setRect(const QRectF &rect)=0
virtual void setColor(const QColor &color)=0
\group qtquick-scenegraph-nodes \title Qt Quick Scene Graph Node classes
int mousePressAndHoldInterval
the time limit in milliseconds that activates a press and hold.
Combined button and popup list for selecting options.
@ MouseEventSynthesizedByQt
@ MouseEventNotSynthesized
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
#define qCDebug(category,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
constexpr const T & qBound(const T &min, const T &val, const T &max)
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLfloat GLfloat GLfloat GLfloat h
GLsizei GLsizei GLchar * source
GLdouble GLdouble GLdouble GLdouble q
#define DEFINE_BOOL_CONFIG_OPTION(name, var)
#define IS_SIGNAL_CONNECTED(Sender, SenderType, Name, Arguments)
#define QT_CONFIG(feature)
item setCursor(Qt::IBeamCursor)
[1]
Q_GUI_EXPORT QPoint toPoint() const noexcept
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent