bool QQuickMouseArea::setPressed(Qt::MouseButton button, bool p) { Q_D(QQuickMouseArea); #ifndef QT_NO_DRAGANDDROP bool dragged = d->drag && d->drag->active(); #else bool dragged = false; #endif bool wasPressed = d->pressed & button; bool isclick = wasPressed && p == false && dragged == false && d->hovered == true; Qt::MouseButtons oldPressed = d->pressed; if (wasPressed != p) { QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, isclick, d->longPress); if (p) { d->pressed |= button; if (!d->doubleClick) emit pressed(&me); me.setPosition(d->lastPos); emit mouseXChanged(&me); me.setPosition(d->lastPos); emit mouseYChanged(&me); if (!oldPressed) { emit pressedChanged(); emit containsPressChanged(); } emit pressedButtonsChanged(); } else { d->pressed &= ~button; emit released(&me); me.setPosition(d->lastPos); if (!d->pressed) { emit pressedChanged(); emit containsPressChanged(); } emit pressedButtonsChanged(); if (isclick && !d->longPress && !d->doubleClick){ me.setAccepted(d->isClickConnected()); emit clicked(&me); if (!me.isAccepted()) d->propagate(&me, QQuickMouseAreaPrivate::Click); } } return me.isAccepted(); } return false; }
void QQuickMouseArea::hoverMoveEvent(QHoverEvent *event) { Q_D(QQuickMouseArea); if (!d->enabled && !d->pressed) { QQuickItem::hoverMoveEvent(event); } else { d->lastPos = event->posF(); d->lastModifiers = event->modifiers(); QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), Qt::NoButton, Qt::NoButton, d->lastModifiers, false, false); emit mouseXChanged(&me); me.setPosition(d->lastPos); emit mouseYChanged(&me); me.setPosition(d->lastPos); emit positionChanged(&me); } }
bool AsemanMouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *e) { QMouseEvent *mevent = static_cast<QMouseEvent*>(e); switch(static_cast<int>(e->type())) { case QEvent::MouseMove: { QPointF newP = mapFromItem(item, mevent->pos()); bool xChanged = (newP.x() != p->point.x()); bool yChanged = (newP.y() != p->point.y()); p->point = newP; if(xChanged) Q_EMIT mouseXChanged(); if(yChanged) Q_EMIT mouseYChanged(); Q_EMIT mousePositionChanged(); break; } case QEvent::MouseButtonPress: p->point = mapFromItem(item, mevent->pos()); Q_EMIT mousePressed(); break; case QEvent::MouseButtonRelease: p->point = mapFromItem(item, mevent->pos()); Q_EMIT mouseReleased(); break; default: p->ignoreEvent = false; break; } if(p->ignoreEvent) { p->ignoreEvent = false; return true; } else return QQuickItem::childMouseEventFilter(item, e); }
void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) { Q_D(QQuickMouseArea); if (!d->enabled && !d->pressed) { QQuickItem::mouseMoveEvent(event); return; } d->saveEvent(event); // ### we should skip this if these signals aren't used // ### can GV handle this for us? setHovered(contains(d->lastPos)); #ifndef QT_NO_DRAGANDDROP if (d->drag && d->drag->target()) { if (!d->moved) { d->targetStartPos = d->drag->target()->parentItem() ? d->drag->target()->parentItem()->mapToScene(d->drag->target()->position()) : d->drag->target()->position(); } QPointF startLocalPos; QPointF curLocalPos; if (drag()->target()->parentItem()) { startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); curLocalPos = drag()->target()->parentItem()->mapFromScene(event->windowPos()); } else { startLocalPos = d->startScene; curLocalPos = event->windowPos(); } if (keepMouseGrab() && d->stealMouse && !d->drag->active()) d->drag->setActive(true); QPointF startPos = d->drag->target()->parentItem() ? d->drag->target()->parentItem()->mapFromScene(d->targetStartPos) : d->targetStartPos; bool dragX = drag()->axis() & QQuickDrag::XAxis; bool dragY = drag()->axis() & QQuickDrag::YAxis; QPointF dragPos = d->drag->target()->position(); if (dragX) { dragPos.setX(qBound( d->drag->xmin(), startPos.x() + curLocalPos.x() - startLocalPos.x(), d->drag->xmax())); } if (dragY) { dragPos.setY(qBound( d->drag->ymin(), startPos.y() + curLocalPos.y() - startLocalPos.y(), d->drag->ymax())); } if (d->drag->active()) d->drag->target()->setPosition(dragPos); if (!keepMouseGrab() && (QQuickWindowPrivate::dragOverThreshold(dragPos.x() - startPos.x(), Qt::XAxis, event, d->drag->threshold()) || QQuickWindowPrivate::dragOverThreshold(dragPos.y() - startPos.y(), Qt::YAxis, event, d->drag->threshold()))) { setKeepMouseGrab(true); d->stealMouse = true; if (d->drag->smoothed()) d->startScene = event->windowPos(); } d->moved = true; } #endif QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); emit mouseXChanged(&me); me.setPosition(d->lastPos); emit mouseYChanged(&me); me.setPosition(d->lastPos); emit positionChanged(&me); }
void QQuickMouseArea::mouseMoveEvent(QMouseEvent *event) { Q_D(QQuickMouseArea); if (!d->enabled && !d->pressed) { QQuickItem::mouseMoveEvent(event); return; } d->saveEvent(event); // ### we should skip this if these signals aren't used // ### can GV handle this for us? const bool isInside = contains(d->lastPos); if (d->hovered && !isInside) setHovered(false); else if (!d->hovered && isInside) setHovered(true); #ifndef QT_NO_DRAGANDDROP if (d->drag && d->drag->target()) { if (!d->moved) { d->targetStartPos = d->drag->target()->parentItem() ? d->drag->target()->parentItem()->mapToScene(d->drag->target()->position()) : d->drag->target()->position(); } QPointF startLocalPos; QPointF curLocalPos; if (drag()->target()->parentItem()) { startLocalPos = drag()->target()->parentItem()->mapFromScene(d->startScene); curLocalPos = drag()->target()->parentItem()->mapFromScene(event->windowPos()); } else { startLocalPos = d->startScene; curLocalPos = event->windowPos(); } qreal dx = qAbs(curLocalPos.x() - startLocalPos.x()); qreal dy = qAbs(curLocalPos.y() - startLocalPos.y()); if (keepMouseGrab() && d->stealMouse && !d->drag->active()) d->drag->setActive(true); QPointF startPos = d->drag->target()->parentItem() ? d->drag->target()->parentItem()->mapFromScene(d->targetStartPos) : d->targetStartPos; QPointF dragPos = d->drag->target()->position(); bool dragX = drag()->axis() & QQuickDrag::XAxis; bool dragY = drag()->axis() & QQuickDrag::YAxis; if (dragX && d->drag->active()) { qreal x = (curLocalPos.x() - startLocalPos.x()) + startPos.x(); if (x < drag()->xmin()) x = drag()->xmin(); else if (x > drag()->xmax()) x = drag()->xmax(); dragPos.setX(x); } if (dragY && d->drag->active()) { qreal y = (curLocalPos.y() - startLocalPos.y()) + startPos.y(); if (y < drag()->ymin()) y = drag()->ymin(); else if (y > drag()->ymax()) y = drag()->ymax(); dragPos.setY(y); } d->drag->target()->setPosition(dragPos); if (!keepMouseGrab()) { bool xDragged = QQuickWindowPrivate::dragOverThreshold(dx, Qt::XAxis, event); bool yDragged = QQuickWindowPrivate::dragOverThreshold(dy, Qt::YAxis, event); if ((!dragY && !yDragged && dragX && xDragged) || (!dragX && !xDragged && dragY && yDragged) || (dragX && dragY && (xDragged || yDragged))) { setKeepMouseGrab(true); d->stealMouse = true; } } d->moved = true; } #endif QQuickMouseEvent me(d->lastPos.x(), d->lastPos.y(), d->lastButton, d->lastButtons, d->lastModifiers, false, d->longPress); emit mouseXChanged(&me); me.setPosition(d->lastPos); emit mouseYChanged(&me); me.setPosition(d->lastPos); emit positionChanged(&me); }