diff --git a/src/declarativeimports/qtextracomponents/mouseeventlistener.cpp b/src/declarativeimports/qtextracomponents/mouseeventlistener.cpp index 9c20610f4..42a441177 100644 --- a/src/declarativeimports/qtextracomponents/mouseeventlistener.cpp +++ b/src/declarativeimports/qtextracomponents/mouseeventlistener.cpp @@ -35,7 +35,8 @@ MouseEventListener::MouseEventListener(QQuickItem *parent) m_pressed(false), m_pressAndHoldEvent(0), m_lastEvent(0), - m_containsMouse(false) + m_containsMouse(false), + m_acceptedButtons(Qt::LeftButton) { m_pressAndHoldTimer = new QTimer(this); m_pressAndHoldTimer->setSingleShot(true); @@ -53,6 +54,21 @@ MouseEventListener::~MouseEventListener() { } +Qt::MouseButtons MouseEventListener::acceptedButtons() const +{ + return m_acceptedButtons; +} + +void MouseEventListener::setAcceptedButtons(Qt::MouseButtons buttons) +{ + if (buttons == m_acceptedButtons) { + return; + } + + m_acceptedButtons = buttons; + emit acceptedButtonsChanged(); +} + void MouseEventListener::setHoverEnabled(bool enable) { if (enable == acceptHoverEvents()) { @@ -107,7 +123,8 @@ bool MouseEventListener::containsMouse() const void MouseEventListener::mousePressEvent(QMouseEvent *me) { - if (m_lastEvent == me) { + if (m_lastEvent == me || !(me->buttons() & m_acceptedButtons)) { + me->setAccepted(false); return; } @@ -130,7 +147,8 @@ void MouseEventListener::mousePressEvent(QMouseEvent *me) void MouseEventListener::mouseMoveEvent(QMouseEvent *me) { - if (m_lastEvent == me) { + if (m_lastEvent == me || !(me->buttons() & m_acceptedButtons)) { + me->setAccepted(false); return; } @@ -140,7 +158,8 @@ void MouseEventListener::mouseMoveEvent(QMouseEvent *me) void MouseEventListener::mouseReleaseEvent(QMouseEvent *me) { - if (m_lastEvent == me) { + if (m_lastEvent == me || !(me->buttons() & m_acceptedButtons)) { + me->setAccepted(false); return; } @@ -191,6 +210,11 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event) case QEvent::MouseButtonPress: { m_lastEvent = event; QMouseEvent *me = static_cast(event); + + if (!(me->buttons() & m_acceptedButtons)) { + break; + } + //the parent will receive events in its own coordinates const QPointF myPos = item->mapToItem(this, me->pos()); KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers()); @@ -225,6 +249,10 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event) case QEvent::MouseMove: { m_lastEvent = event; QMouseEvent *me = static_cast(event); + if (!(me->buttons() & m_acceptedButtons)) { + break; + } + const QPointF myPos = item->mapToItem(this, me->pos()); KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers()); //qDebug() << "positionChanged..." << dme.x() << dme.y(); @@ -235,6 +263,10 @@ bool MouseEventListener::childMouseEventFilter(QQuickItem *item, QEvent *event) case QEvent::MouseButtonRelease: { m_lastEvent = event; QMouseEvent *me = static_cast(event); + if (!(me->buttons() & m_acceptedButtons)) { + break; + } + const QPointF myPos = item->mapToItem(this, me->pos()); KDeclarativeMouseEvent dme(myPos.x(), myPos.y(), me->screenPos().x(), me->screenPos().y(), me->button(), me->buttons(), me->modifiers()); m_pressed = false; diff --git a/src/declarativeimports/qtextracomponents/mouseeventlistener.h b/src/declarativeimports/qtextracomponents/mouseeventlistener.h index 26d51859c..6d34fdc67 100644 --- a/src/declarativeimports/qtextracomponents/mouseeventlistener.h +++ b/src/declarativeimports/qtextracomponents/mouseeventlistener.h @@ -135,6 +135,8 @@ class MouseEventListener : public QQuickItem */ Q_PROPERTY(bool containsMouse READ containsMouse NOTIFY containsMouseChanged) + Q_PROPERTY(Qt::MouseButtons acceptedButtons READ acceptedButtons WRITE setAcceptedButtons NOTIFY acceptedButtonsChanged) + public: MouseEventListener(QQuickItem *parent=0); ~MouseEventListener(); @@ -143,6 +145,9 @@ public: void setHoverEnabled(bool enable); bool hoverEnabled() const; + Qt::MouseButtons acceptedButtons() const; + void setAcceptedButtons(Qt::MouseButtons buttons); + protected: void hoverEnterEvent(QHoverEvent *event); void hoverLeaveEvent(QHoverEvent *event); @@ -162,6 +167,7 @@ Q_SIGNALS: void wheelMoved(KDeclarativeWheelEvent *wheel); void containsMouseChanged(bool containsMouseChanged); void hoverEnabledChanged(bool hoverEnabled); + void acceptedButtonsChanged(); private Q_SLOTS: void handlePressAndHold(); @@ -175,6 +181,7 @@ private: QEvent *m_lastEvent; QTimer *m_pressAndHoldTimer; bool m_containsMouse; + Qt::MouseButtons m_acceptedButtons; }; #endif