summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@digia.com>2012-11-07 16:23:32 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-11-10 20:08:28 +0100
commit2d07d3b4e3036179667a822aa40285d071b76b9e (patch)
tree715e5c6a92426f1ac1cd4cd585e02cf8cab05002 /src/gui
parent1fe0c2c25dc96e9af6f442cf059ad627d45f10fa (diff)
Add a QEnterEvent containing the mouse position.
Enter handling requires knowledge of the mouse position. Extend the enter handling of QWindowSystemInterface to receive the position (implemented for Windows, XCB and Mac), passing it on to QEnterEvent. Dispatch QEnterEvent from widgets code. Change-Id: I49c07d2b1f46310c877017dd55d4cd7d636bdbce Reviewed-by: Miikka Heikkinen <miikka.heikkinen@digia.com> Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qevent.cpp34
-rw-r--r--src/gui/kernel/qevent.h22
-rw-r--r--src/gui/kernel/qguiapplication.cpp2
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp8
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h4
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h6
6 files changed, 67 insertions, 9 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 3dbef228a5..66434f9a53 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -56,6 +56,40 @@
QT_BEGIN_NAMESPACE
/*!
+ \class QEnterEvent
+ \ingroup events
+
+ \brief The QEnterEvent class contains parameters that describe an enter event.
+
+ Enter events occur when the mouse cursor enters a window or a widget.
+
+ \since 5.0
+*/
+
+/*!
+ Constructs an enter event object.
+
+ The points \a localPos, \a windowPos and \a screenPos specify the
+ mouse cursor's position relative to the receiving widget or item,
+ window, and screen, respectively.
+*/
+
+QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos)
+ : QEvent(QEvent::Enter)
+ , l(localPos)
+ , w(windowPos)
+ , s(screenPos)
+{
+}
+
+/*!
+ \internal
+*/
+QEnterEvent::~QEnterEvent()
+{
+}
+
+/*!
\class QInputEvent
\ingroup events
\inmodule QtGui
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index b35dd88c2a..82d22aec05 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -83,6 +83,28 @@ protected:
ulong ts;
};
+class Q_GUI_EXPORT QEnterEvent : public QEvent
+{
+public:
+ QEnterEvent(const QPointF &localPos, const QPointF &windowPos, const QPointF &screenPos);
+ ~QEnterEvent();
+
+#ifndef QT_NO_INTEGER_EVENT_COORDINATES
+ inline QPoint pos() const { return l.toPoint(); }
+ inline QPoint globalPos() const { return s.toPoint(); }
+ inline int x() const { return qRound(l.x()); }
+ inline int y() const { return qRound(l.y()); }
+ inline int globalX() const { return qRound(s.x()); }
+ inline int globalY() const { return qRound(s.y()); }
+#endif
+ const QPointF &localPos() const { return l; }
+ const QPointF &windowPos() const { return w; }
+ const QPointF &screenPos() const { return s; }
+
+protected:
+ QPointF l, w, s;
+};
+
class Q_GUI_EXPORT QMouseEvent : public QInputEvent
{
public:
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index ca9d60fcdf..4c4e75c4f6 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1424,7 +1424,7 @@ void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::En
currentMouseWindow = e->enter;
- QEvent event(QEvent::Enter);
+ QEnterEvent event(e->localPos, e->localPos, e->globalPos);
QCoreApplication::sendSpontaneousEvent(e->enter.data(), &event);
}
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index 6fb10b6c75..acc6eace99 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -75,10 +75,10 @@ extern QPointer<QWindow> qt_last_mouse_receiver;
until sendWindowSystemEvents() is called by the event dispatcher.
*/
-void QWindowSystemInterface::handleEnterEvent(QWindow *tlw)
+void QWindowSystemInterface::handleEnterEvent(QWindow *tlw, const QPointF &local, const QPointF &global)
{
if (tlw) {
- QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw);
+ QWindowSystemInterfacePrivate::EnterEvent *e = new QWindowSystemInterfacePrivate::EnterEvent(tlw, local, global);
QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
}
}
@@ -96,13 +96,13 @@ void QWindowSystemInterface::handleLeaveEvent(QWindow *tlw)
determine where mouse went and act accordingly. E.g. QWidgetWindow needs to know if mouse
cursor moves between windows in same window hierarchy.
*/
-void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave)
+void QWindowSystemInterface::handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local, const QPointF& global)
{
bool wasSynchronous = QWindowSystemInterfacePrivate::synchronousWindowsSystemEvents;
if (wasSynchronous)
setSynchronousWindowsSystemEvents(false);
handleLeaveEvent(leave);
- handleEnterEvent(enter);
+ handleEnterEvent(enter, local, global);
if (wasSynchronous) {
flushWindowSystemEvents();
setSynchronousWindowsSystemEvents(true);
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index b4b2e845fc..a3d2f1b000 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -134,9 +134,9 @@ public:
static void handleGeometryChange(QWindow *w, const QRect &newRect);
static void handleCloseEvent(QWindow *w);
- static void handleEnterEvent(QWindow *w);
+ static void handleEnterEvent(QWindow *w, const QPointF &local = QPointF(), const QPointF& global = QPointF());
static void handleLeaveEvent(QWindow *w);
- static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave);
+ static void handleEnterLeaveEvent(QWindow *enter, QWindow *leave, const QPointF &local = QPointF(), const QPointF& global = QPointF());
static void handleWindowActivated(QWindow *w);
static void handleWindowStateChanged(QWindow *w, Qt::WindowState newState);
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 5867337de6..b174fd0ca2 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -119,10 +119,12 @@ public:
class EnterEvent : public WindowSystemEvent {
public:
- explicit EnterEvent(QWindow *enter)
- : WindowSystemEvent(Enter), enter(enter)
+ explicit EnterEvent(QWindow *enter, const QPointF &local, const QPointF &global)
+ : WindowSystemEvent(Enter), enter(enter), localPos(local), globalPos(global)
{ }
QPointer<QWindow> enter;
+ const QPointF localPos;
+ const QPointF globalPos;
};
class LeaveEvent : public WindowSystemEvent {