summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@nokia.com>2011-05-02 09:25:17 +0200
committerSamuel Rødal <samuel.rodal@nokia.com>2011-05-02 09:26:40 +0200
commitaf77656f15bb32cbf532106641522b42cab3a343 (patch)
tree72aaba20121b6987dba7dbea576ae9231aab2055
parenta90d1b432c32becb9066e1542e44c0d7e0147fcc (diff)
Proper child delivery of mouse and key events.
-rw-r--r--src/corelib/kernel/qcoreapplication.h1
-rw-r--r--src/gui/kernel/qguiapplication_qpa.cpp2
-rw-r--r--src/gui/kernel/qplatformscreen_qpa.cpp2
-rw-r--r--src/gui/kernel/qwidgetwindow_qpa.cpp44
-rw-r--r--src/gui/kernel/qwidgetwindow_qpa_p.h3
5 files changed, 48 insertions, 4 deletions
diff --git a/src/corelib/kernel/qcoreapplication.h b/src/corelib/kernel/qcoreapplication.h
index d0dddc9f8f..b83e240566 100644
--- a/src/corelib/kernel/qcoreapplication.h
+++ b/src/corelib/kernel/qcoreapplication.h
@@ -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();
diff --git a/src/gui/kernel/qguiapplication_qpa.cpp b/src/gui/kernel/qguiapplication_qpa.cpp
index 7a6c184fff..768fb767a4 100644
--- a/src/gui/kernel/qguiapplication_qpa.cpp
+++ b/src/gui/kernel/qguiapplication_qpa.cpp
@@ -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();
diff --git a/src/gui/kernel/qplatformscreen_qpa.cpp b/src/gui/kernel/qplatformscreen_qpa.cpp
index 79059de4f7..2e1a13769d 100644
--- a/src/gui/kernel/qplatformscreen_qpa.cpp
+++ b/src/gui/kernel/qplatformscreen_qpa.cpp
@@ -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);
}
diff --git a/src/gui/kernel/qwidgetwindow_qpa.cpp b/src/gui/kernel/qwidgetwindow_qpa.cpp
index 8ab6c9cec3..ec53b794f2 100644
--- a/src/gui/kernel/qwidgetwindow_qpa.cpp
+++ b/src/gui/kernel/qwidgetwindow_qpa.cpp
@@ -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
diff --git a/src/gui/kernel/qwidgetwindow_qpa_p.h b/src/gui/kernel/qwidgetwindow_qpa_p.h
index 3768d655b7..607879dcf5 100644
--- a/src/gui/kernel/qwidgetwindow_qpa_p.h
+++ b/src/gui/kernel/qwidgetwindow_qpa_p.h
@@ -63,6 +63,9 @@ public:
protected:
bool event(QEvent *);
+ void handleMouseEvent(QMouseEvent *);
+ void handleKeyEvent(QKeyEvent *);
+
private:
QWidget *m_widget;
};