Proper child delivery of mouse and key events.

This commit is contained in:
Samuel Rødal 2011-05-02 09:25:17 +02:00
parent a90d1b432c
commit af77656f15
5 changed files with 48 additions and 4 deletions

View File

@ -214,6 +214,7 @@ private:
friend class Q3AccelManager;
friend class QShortcutMap;
friend class QWidget;
friend class QWidgetWindow;
friend class QWidgetPrivate;
friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
friend Q_CORE_EXPORT QString qAppName();

View File

@ -642,7 +642,7 @@ void QGuiApplicationPrivate::processKeyEvent(QWindowSystemInterfacePrivate::KeyE
}
}
void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *e)
void QGuiApplicationPrivate::processEnterEvent(QWindowSystemInterfacePrivate::EnterEvent *)
{
// QGuiApplicationPrivate::dispatchEnterLeave(e->enter.data(),0);
// qt_last_mouse_receiver = e->enter.data();

View File

@ -95,7 +95,7 @@ QPlatformScreen * QPlatformScreen::platformScreenForWidget(const QWidget *widget
return integration->screens()[screenIndex];
}
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *)
{
return QGuiApplicationPrivate::platformIntegration()->screens().at(0);
}

View File

@ -50,10 +50,50 @@ QWidgetWindow::QWidgetWindow(QWidget *widget)
bool QWidgetWindow::event(QEvent *event)
{
if (m_widget->event(event))
switch (event->type()) {
case QEvent::MouseMove:
case QEvent::MouseButtonPress:
case QEvent::MouseButtonRelease:
case QEvent::MouseButtonDblClick:
handleMouseEvent(static_cast<QMouseEvent *>(event));
return true;
return QWindow::event(event);
case QEvent::KeyPress:
case QEvent::KeyRelease:
handleKeyEvent(static_cast<QKeyEvent *>(event));
return true;
default:
break;
}
return m_widget->event(event) || QWindow::event(event);
}
void QWidgetWindow::handleMouseEvent(QMouseEvent *event)
{
// which child should have it?
QWidget *widget = m_widget->childAt(event->pos());
// TODO: make sure mouse release is delivered to same widget that got the press event
if (!widget)
widget = m_widget;
QPoint mapped = widget->mapFrom(m_widget, event->pos());
QMouseEvent translated(event->type(), mapped, event->globalPos(), event->button(), event->buttons(), event->modifiers());
QGuiApplication::sendSpontaneousEvent(widget, &translated);
}
void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
{
QWidget *widget = m_widget->focusWidget();
if (!widget)
widget = m_widget;
QGuiApplication::sendSpontaneousEvent(widget, event);
}
QT_END_NAMESPACE

View File

@ -63,6 +63,9 @@ public:
protected:
bool event(QEvent *);
void handleMouseEvent(QMouseEvent *);
void handleKeyEvent(QKeyEvent *);
private:
QWidget *m_widget;
};