diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2016-05-10 10:38:50 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2016-05-13 08:09:33 +0000 |
commit | f9939dd4155063d381b340b4b0b2f14e2f37f620 (patch) | |
tree | 61911c2608f5d20903e94b07ada0277241b28647 | |
parent | b623352c62e512d671cda46212d58d4f746dd220 (diff) | |
download | qtwayland-f9939dd4155063d381b340b4b0b2f14e2f37f620.tar.gz |
Add containsMouse property to QWaylandMouseTracker
This is useful for enabling and disabling the cursorItem when moving the
mouse between outputs.
Change-Id: I71cb588314a500a263b39986f7ddcde7951c61d0
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
Reviewed-by: Giulio Camuffo <giulio.camuffo@kdab.com>
-rw-r--r-- | src/imports/compositor/qwaylandmousetracker.cpp | 31 | ||||
-rw-r--r-- | src/imports/compositor/qwaylandmousetracker_p.h | 6 |
2 files changed, 37 insertions, 0 deletions
diff --git a/src/imports/compositor/qwaylandmousetracker.cpp b/src/imports/compositor/qwaylandmousetracker.cpp index fd6a591e..e54321f1 100644 --- a/src/imports/compositor/qwaylandmousetracker.cpp +++ b/src/imports/compositor/qwaylandmousetracker.cpp @@ -46,6 +46,7 @@ class QWaylandMouseTrackerPrivate : public QQuickItemPrivate public: QWaylandMouseTrackerPrivate() : enableWSCursor(false) + , hovered(false) { QImage cursorImage(64,64,QImage::Format_ARGB32); cursorImage.fill(Qt::transparent); @@ -65,9 +66,19 @@ public: } } + void setHovered(bool hovered) + { + Q_Q(QWaylandMouseTracker); + if (this->hovered == hovered) + return; + this->hovered = hovered; + emit q->hoveredChanged(); + } + QPointF mousePos; bool enableWSCursor; QPixmap cursorPixmap; + bool hovered; }; QWaylandMouseTracker::QWaylandMouseTracker(QQuickItem *parent) @@ -110,6 +121,12 @@ bool QWaylandMouseTracker::enableWSCursor() const return d->enableWSCursor; } +bool QWaylandMouseTracker::hovered() const +{ + Q_D(const QWaylandMouseTracker); + return d->hovered; +} + bool QWaylandMouseTracker::childMouseEventFilter(QQuickItem *item, QEvent *event) { Q_D(QWaylandMouseTracker); @@ -137,4 +154,18 @@ void QWaylandMouseTracker::hoverMoveEvent(QHoverEvent *event) d->handleMousePos(event->posF()); } +void QWaylandMouseTracker::hoverEnterEvent(QHoverEvent *event) +{ + Q_D(QWaylandMouseTracker); + Q_UNUSED(event); + d->setHovered(true); +} + +void QWaylandMouseTracker::hoverLeaveEvent(QHoverEvent *event) +{ + Q_D(QWaylandMouseTracker); + Q_UNUSED(event); + d->setHovered(false); +} + QT_END_NAMESPACE diff --git a/src/imports/compositor/qwaylandmousetracker_p.h b/src/imports/compositor/qwaylandmousetracker_p.h index 2cc8798b..1bc37a5e 100644 --- a/src/imports/compositor/qwaylandmousetracker_p.h +++ b/src/imports/compositor/qwaylandmousetracker_p.h @@ -51,6 +51,7 @@ class Q_WAYLAND_COMPOSITOR_EXPORT QWaylandMouseTracker : public QQuickItem Q_DECLARE_PRIVATE(QWaylandMouseTracker) Q_PROPERTY(qreal mouseX READ mouseX NOTIFY mouseXChanged) Q_PROPERTY(qreal mouseY READ mouseY NOTIFY mouseYChanged) + Q_PROPERTY(bool containsMouse READ hovered NOTIFY hoveredChanged) Q_PROPERTY(bool enableWSCursor READ enableWSCursor WRITE setEnableWSCursor NOTIFY enableWSCursorChanged) public: @@ -61,15 +62,20 @@ public: void setEnableWSCursor(bool enable); bool enableWSCursor() const; + bool hovered() const; + signals: void mouseXChanged(); void mouseYChanged(); void enableWSCursorChanged(); + void hoveredChanged(); protected: bool childMouseEventFilter(QQuickItem *item, QEvent *event) Q_DECL_OVERRIDE; void mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; void hoverMoveEvent(QHoverEvent *event) Q_DECL_OVERRIDE; + void hoverEnterEvent(QHoverEvent *event) Q_DECL_OVERRIDE; + void hoverLeaveEvent(QHoverEvent *event) Q_DECL_OVERRIDE; }; QT_END_NAMESPACE |