42 #include "private/qdeclarativemousearea_p.h" 43 #include "private/qdeclarativemousearea_p_p.h" 45 #include "private/qdeclarativeevents_p_p.h" 47 #include <QGraphicsSceneMouseEvent> 55 :
QObject(parent), _target(0), _axis(XandYAxis), _xmin(-FLT_MAX), _xmax(FLT_MAX), _ymin(-FLT_MAX), _ymax(FLT_MAX),
56 _active(false), _filterChildren(false)
423 return d->lastPos.x();
429 return d->lastPos.y();
450 if (a !=
d->absorb) {
479 return d->preventStealing;
485 if (prevent !=
d->preventStealing) {
486 d->preventStealing = prevent;
515 return d->lastButtons;
522 d->stealMouse =
d->preventStealing;
526 d->longPress =
false;
529 d->drag->setActive(
false);
531 d->startScene =
event->scenePos();
533 if (
d->isPressAndHoldConnected())
553 if (
d->hovered && !contains)
555 else if (!
d->hovered && contains)
558 if (
d->drag &&
d->drag->target()) {
570 startLocalPos =
d->startScene;
571 curLocalPos =
event->scenePos();
575 d->drag->setActive(
true);
581 ?
qBound(
d->drag->xmin(),
d->startX + curLocalPos.
x() - startLocalPos.
x(),
d->drag->xmax())
584 ?
qBound(
d->drag->ymin(),
d->startY + curLocalPos.
y() - startLocalPos.
y(),
d->drag->ymax())
587 if (
d->drag->active()) {
589 d->drag->target()->setPos(x,
y);
591 d->drag->target()->setX(x);
593 d->drag->target()->setY(
y);
599 if (
qAbs(x -
d->startX) > dragThreshold ||
qAbs(
y -
d->startY) > dragThreshold) {
601 d->stealMouse =
true;
609 me.setX(
d->lastPos.x());
610 me.setY(
d->lastPos.y());
618 d->stealMouse =
false;
625 d->drag->setActive(
false);
634 d->doubleClick =
false;
643 if (
d->isDoubleClickConnected())
644 d->doubleClick =
true;
659 d->lastPos =
event->pos();
672 d->lastPos =
event->pos();
675 me.setX(
d->lastPos.x());
676 me.setY(
d->lastPos.y());
690 #ifndef QT_NO_CONTEXTMENU 693 bool acceptsContextMenuButton;
694 #if defined(Q_OS_SYMBIAN) 697 #elif defined(Q_WS_WINCE) 707 && acceptsContextMenuButton) {
714 #endif // QT_NO_CONTEXTMENU 725 d->stealMouse =
false;
746 bool stealThisEvent =
d->stealMouse;
749 for (
int i = 0x1; i <= 0x10; i <<= 1) {
774 if (grabber && stealThisEvent && !grabber->
keepMouseGrab() && grabber !=
this)
777 return stealThisEvent;
782 d->stealMouse =
false;
799 if (!
d->absorb || !
isVisible() || !
d->drag || !
d->drag->filterChildren())
805 return sendMouseEvent(static_cast<QGraphicsSceneMouseEvent *>(e));
816 if (event->
timerId() ==
d->pressAndHoldTimer.timerId()) {
817 d->pressAndHoldTimer.stop();
818 bool dragged =
d->drag &&
d->drag->active();
819 if (
d->pressed && dragged ==
false &&
d->hovered ==
true) {
828 const QRectF &oldGeometry)
833 if (
d->lastScenePos.isNull)
835 else if (newGeometry.
x() != oldGeometry.
x() || newGeometry.
y() != oldGeometry.
y())
918 if (
d->hovered != h) {
966 bool dragged =
d->drag &&
d->drag->active();
967 bool isclick =
d->pressed ==
true && p ==
false && dragged ==
false &&
d->hovered ==
true;
969 if (
d->pressed != p) {
975 me.setX(
d->lastPos.x());
976 me.setY(
d->lastPos.y());
981 me.setX(
d->lastPos.x());
982 me.setY(
d->lastPos.y());
984 if (isclick && !
d->longPress && !
d->doubleClick)
988 return me.isAccepted();
The QVariant class acts like a union for the most common Qt data types.
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
void pressAndHold(QDeclarativeMouseEvent *mouse)
bool hoverEnabled() const
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
qreal y() const
Returns the y-coordinate of the rectangle's top edge.
#define QT_END_NAMESPACE
This macro expands to.
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
QDeclarativeParserStatus ** d
qreal y
the y position of the item
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover move events for this item...
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover leave events for this item...
virtual bool event(QEvent *)
bool sceneEvent(QEvent *)
void filterChildrenChanged()
The QPointF class defines a point in the plane using floating point precision.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
The QGraphicsSceneMouseEvent class provides mouse events in the graphics view framework.
static Qt::MouseButtons buttons
bool isVisible() const
Returns true if the item is visible; otherwise, false is returned.
void preventStealingChanged()
Qt::MouseButtons pressedButtons() const
void doubleClicked(QDeclarativeMouseEvent *mouse)
long ASN1_INTEGER_get ASN1_INTEGER * a
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse doubleclick events for thi...
T * qobject_cast(QObject *object)
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QGraphicsItem * mouseGrabberItem() const
Returns the current mouse grabber item, or 0 if no item is currently grabbing the mouse...
Q_DECL_CONSTEXPR T qAbs(const T &t)
The QObject class is the base class of all Qt objects.
void setPreventStealing(bool prevent)
qreal x() const
Returns the x-coordinate of this point.
QDeclarativeMouseArea(QDeclarativeItem *parent=0)
This handler is called when the mouse enters the mouse area.
QRectF boundingRect() const
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover leave events for this item...
bool contains(const QPointF &p) const
Returns true if the given point is inside or on the edge of the rectangle; otherwise returns false...
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse doubleclick events for thi...
void released(QDeclarativeMouseEvent *mouse)
void mousePressEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse press events for this item...
QGraphicsObject * target() const
QPointF lastScenePos() const
Returns the last recorded mouse cursor position in scene coordinates.
#define QT_BEGIN_NAMESPACE
This macro expands to.
bool filterChildren() const
The QRectF class defines a rectangle in the plane using floating point precision. ...
bool isUnderMouse() const
Returns true if this item is currently under the mouse cursor in one of the views; otherwise...
void acceptedButtonsChanged()
void hoverEnabledChanged()
static const int PressAndHoldDelay
The QDeclarativeItem class provides the most basic of all visual items in QML.
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse move events for this item...
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover move events for this item...
Qt::MouseButtons acceptedButtons() const
int timerId() const
Returns the unique timer identifier, which is the same identifier as returned from QObject::startTime...
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover enter events for this item...
void setAcceptedButtons(Qt::MouseButtons buttons)
static int startDragDistance()
virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
This event handler can be reimplemented in a subclass to process context menu events.
bool sendMouseEvent(QGraphicsSceneMouseEvent *event)
virtual void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
This function is called to handle this item's changes in geometry from oldGeometry to newGeometry...
void contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
This event handler can be reimplemented in a subclass to process context menu events.
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...
QDeclarativeDrag(QObject *parent=0)
QGraphicsItem * parentItem() const
Returns a pointer to this item's parent item.
void timerEvent(QTimerEvent *event)
This event handler can be reimplemented in a subclass to receive timer events for the object...
void setTarget(QGraphicsObject *)
qreal y() const
This convenience function is equivalent to calling pos().
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover enter events for this item...
QDeclarativeItem * parentItem() const
Returns the QDeclarativeItem parent of this item.
virtual QVariant itemChange(GraphicsItemChange, const QVariant &)
Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is not called during initial widget p...
The QTimerEvent class contains parameters that describe a timer event.
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Note that unlike QGraphicsItems, QDeclarativeItem::itemChange() is not called during initial widget p...
QPointF scenePos() const
Returns the mouse cursor position in scene coordinates.
qreal x() const
Returns the x-coordinate of the rectangle's left edge.
QPoint toPoint() const
Rounds the coordinates of this point to the nearest integer, and returns a QPoint object with the rou...
void clicked(QDeclarativeMouseEvent *mouse)
QObject * parent() const
Returns a pointer to the parent object.
void setAcceptHoverEvents(bool enabled)
If enabled is true, this item will accept hover events; otherwise, it will ignore them...
qreal x() const
This convenience function is equivalent to calling pos().
Q_DECL_CONSTEXPR const T & qBound(const T &min, const T &val, const T &max)
if(void) toggleToolbarShown
QFuture< void > filter(Sequence &sequence, FilterFunction filterFunction)
bool sceneEventFilter(QGraphicsItem *i, QEvent *e)
Filters events for the item watched.
virtual bool contains(const QPointF &point) const
Returns true if this item contains point, which is in local coordinates; otherwise, false is returned.
static void mouseEvent(MouseAction action, QWidget *widget, Qt::MouseButton button, Qt::KeyboardModifiers stateKey, QPoint pos, int delay=-1)
virtual bool sceneEvent(QEvent *)
qreal y() const
Returns the y-coordinate of this point.
void setAccepted(bool accepted)
bool keepMouseGrab() const
Returns a value indicating whether mouse input should remain with this item exclusively.
QPointF buttonDownPos(Qt::MouseButton button) const
Returns the mouse cursor position in item coordinates where the specified button was clicked...
void mousePositionChanged(QDeclarativeMouseEvent *mouse)
void setAcceptedMouseButtons(Qt::MouseButtons buttons)
Sets the mouse buttons that this item accepts mouse events for.
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
QGraphicsObject * _target
~QDeclarativeMouseAreaPrivate()
QGraphicsScene * scene() const
Returns the current scene for the item, or 0 if the item is not stored in a scene.
bool acceptHoverEvents() const
Returns true if an item accepts hover events (QGraphicsSceneHoverEvent); otherwise, returns false.
void ungrabMouse()
Releases the mouse grab.
qreal x
the x position of the item
The QGraphicsObject class provides a base class for all graphics items that require signals...
void setHoverEnabled(bool h)
void positionChanged(QDeclarativeMouseEvent *mouse)
The QEvent class is the base class of all event classes.
virtual bool sceneEventFilter(QGraphicsItem *watched, QEvent *event)
Filters events for the item watched.
Type type() const
Returns the event type.
QPointF mapToScene(const QPointF &point) const
Maps the point point, which is in this item's coordinate system, to the scene's coordinate system...
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
This event handler, for event event, can be reimplemented to receive mouse release events for this it...
void grabMouse()
Grabs the mouse input.
Qt::MouseButtons buttons() const
Returns the combination of mouse buttons that were pressed at the time the event was sent...
void setFilterChildren(bool)
void setKeepMouseGrab(bool)
The flag indicating whether the mouse should remain with this item is set to keep.
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
QDeclarativeDrag * drag()
Qt::MouseButtons acceptedMouseButtons() const
Returns the mouse buttons that this item accepts mouse events for.
bool preventStealing() const