From dc0f9f02a5c390f4a7919db4c32d22cebaf71d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Wed, 4 May 2011 14:19:40 +0200 Subject: Implemented enter / leave events for QWidget. --- src/gui/guikernel/qguiapplication.cpp | 16 ++++++---------- src/gui/kernel/qwidgetwindow_qpa.cpp | 25 +++++++++++++++++++++++++ src/gui/kernel/qwidgetwindow_qpa_p.h | 1 + 3 files changed, 32 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/guikernel/qguiapplication.cpp b/src/gui/guikernel/qguiapplication.cpp index 52303b929f..ceff68f6fd 100644 --- a/src/gui/guikernel/qguiapplication.cpp +++ b/src/gui/guikernel/qguiapplication.cpp @@ -664,22 +664,18 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE } } -void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *) +void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e) { // QGuiApplicationPrivate::dispatchEnterLeave(e->enter.data(),0); // qt_last_mouse_receiver = e->enter.data(); + QEvent event(QEvent::Enter); + QApplication::sendSpontaneousEvent(e->enter.data(), &event); } -void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *) +void QGuiApplicationPrivate::processLeaveEvent(QWindowSystemInterfacePrivate::LeaveEvent *e) { -// QGuiApplicationPrivate::dispatchEnterLeave(0,qt_last_mouse_receiver); - -#if 0 - if (e->leave.data() && !e->leave.data()->isAncestorOf(qt_last_mouse_receiver)) //(???) this should not happen - QGuiApplicationPrivate::dispatchEnterLeave(0, e->leave.data()); -#endif - qt_last_mouse_receiver = 0; - + QEvent event(QEvent::Leave); + QApplication::sendSpontaneousEvent(e->leave.data(), &event); } void QGuiApplicationPrivate::processActivatedEvent(QWindowSystemInterfacePrivate::ActivatedWindowEvent *) diff --git a/src/gui/kernel/qwidgetwindow_qpa.cpp b/src/gui/kernel/qwidgetwindow_qpa.cpp index ec60e57b26..4d79246925 100644 --- a/src/gui/kernel/qwidgetwindow_qpa.cpp +++ b/src/gui/kernel/qwidgetwindow_qpa.cpp @@ -42,6 +42,7 @@ #include "qwidgetwindow_qpa_p.h" #include "private/qwidget_p.h" +#include "private/qapplication_p.h" QT_BEGIN_NAMESPACE @@ -57,6 +58,11 @@ bool QWidgetWindow::event(QEvent *event) handleCloseEvent(static_cast(event)); return true; + case QEvent::Enter: + case QEvent::Leave: + handleEnterLeaveEvent(event); + return true; + case QEvent::KeyPress: case QEvent::KeyRelease: handleKeyEvent(static_cast(event)); @@ -88,6 +94,20 @@ bool QWidgetWindow::event(QEvent *event) return m_widget->event(event) || QWindow::event(event); } +QPointer qt_last_mouse_receiver = 0; + +void QWidgetWindow::handleEnterLeaveEvent(QEvent *event) +{ + if (event->type() == QEvent::Leave) { + QApplicationPrivate::dispatchEnterLeave(0, m_widget); + qt_last_mouse_receiver = 0; + } else { + QApplicationPrivate::dispatchEnterLeave(m_widget, 0); + qt_last_mouse_receiver = m_widget; + printf("Enter event: %p\n", m_widget); + } +} + void QWidgetWindow::handleMouseEvent(QMouseEvent *event) { // which child should have it? @@ -106,6 +126,11 @@ void QWidgetWindow::handleMouseEvent(QMouseEvent *event) QPoint mapped = widget->mapFrom(m_widget, event->pos()); + if (widget != qt_last_mouse_receiver) { + QApplicationPrivate::dispatchEnterLeave(widget, qt_last_mouse_receiver); + qt_last_mouse_receiver = widget; + } + QMouseEvent translated(event->type(), mapped, event->globalPos(), event->button(), event->buttons(), event->modifiers()); QGuiApplication::sendSpontaneousEvent(widget, &translated); diff --git a/src/gui/kernel/qwidgetwindow_qpa_p.h b/src/gui/kernel/qwidgetwindow_qpa_p.h index 7a3ff46e65..9eb1e4f60e 100644 --- a/src/gui/kernel/qwidgetwindow_qpa_p.h +++ b/src/gui/kernel/qwidgetwindow_qpa_p.h @@ -64,6 +64,7 @@ protected: bool event(QEvent *); void handleCloseEvent(QCloseEvent *); + void handleEnterLeaveEvent(QEvent *); void handleKeyEvent(QKeyEvent *); void handleMouseEvent(QMouseEvent *); void handleMoveEvent(QMoveEvent *); -- cgit v1.2.3