Proper child delivery of mouse and key events.
This commit is contained in:
parent
a90d1b432c
commit
af77656f15
@ -214,6 +214,7 @@ private:
|
|||||||
friend class Q3AccelManager;
|
friend class Q3AccelManager;
|
||||||
friend class QShortcutMap;
|
friend class QShortcutMap;
|
||||||
friend class QWidget;
|
friend class QWidget;
|
||||||
|
friend class QWidgetWindow;
|
||||||
friend class QWidgetPrivate;
|
friend class QWidgetPrivate;
|
||||||
friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
|
friend bool qt_sendSpontaneousEvent(QObject*, QEvent*);
|
||||||
friend Q_CORE_EXPORT QString qAppName();
|
friend Q_CORE_EXPORT QString qAppName();
|
||||||
|
@ -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);
|
// QGuiApplicationPrivate::dispatchEnterLeave(e->enter.data(),0);
|
||||||
// qt_last_mouse_receiver = e->enter.data();
|
// qt_last_mouse_receiver = e->enter.data();
|
||||||
|
@ -95,7 +95,7 @@ QPlatformScreen * QPlatformScreen::platformScreenForWidget(const QWidget *widget
|
|||||||
return integration->screens()[screenIndex];
|
return integration->screens()[screenIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *window)
|
QPlatformScreen * QPlatformScreen::platformScreenForWindow(const QWindow *)
|
||||||
{
|
{
|
||||||
return QGuiApplicationPrivate::platformIntegration()->screens().at(0);
|
return QGuiApplicationPrivate::platformIntegration()->screens().at(0);
|
||||||
}
|
}
|
||||||
|
@ -50,10 +50,50 @@ QWidgetWindow::QWidgetWindow(QWidget *widget)
|
|||||||
|
|
||||||
bool QWidgetWindow::event(QEvent *event)
|
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 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
|
QT_END_NAMESPACE
|
||||||
|
@ -63,6 +63,9 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
bool event(QEvent *);
|
bool event(QEvent *);
|
||||||
|
|
||||||
|
void handleMouseEvent(QMouseEvent *);
|
||||||
|
void handleKeyEvent(QKeyEvent *);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_widget;
|
QWidget *m_widget;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user