Implemented enter / leave events for QWidget.

This commit is contained in:
Samuel Rødal 2011-05-04 14:19:40 +02:00
parent 4e69052efc
commit dc0f9f02a5
3 changed files with 32 additions and 10 deletions

View File

@ -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 *)

View File

@ -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<QCloseEvent *>(event));
return true;
case QEvent::Enter:
case QEvent::Leave:
handleEnterLeaveEvent(event);
return true;
case QEvent::KeyPress:
case QEvent::KeyRelease:
handleKeyEvent(static_cast<QKeyEvent *>(event));
@ -88,6 +94,20 @@ bool QWidgetWindow::event(QEvent *event)
return m_widget->event(event) || QWindow::event(event);
}
QPointer<QWidget> 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);

View File

@ -64,6 +64,7 @@ protected:
bool event(QEvent *);
void handleCloseEvent(QCloseEvent *);
void handleEnterLeaveEvent(QEvent *);
void handleKeyEvent(QKeyEvent *);
void handleMouseEvent(QMouseEvent *);
void handleMoveEvent(QMoveEvent *);