Add virtual QWindow::focusObject() method

The method allows to retrieve the object that currently
has the input focus inside the Window. This is e.g.
required to correctly determine the context for keyboard
shortcuts.

Change-Id: I9e05ef62717973bac275ce34cc70fb86aa2d1e5b
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
This commit is contained in:
Lars Knoll 2011-10-21 10:59:27 +02:00 committed by Qt by Nokia
parent e19292120b
commit 68dc5b90c0
4 changed files with 23 additions and 5 deletions

View File

@ -663,6 +663,15 @@ QAccessibleInterface *QWindow::accessibleRoot() const
return 0;
}
/*!
Returns the QObject that will be the final receiver of events tied focus, such
as key events.
*/
QObject *QWindow::focusObject() const
{
return const_cast<QWindow *>(this);
}
void QWindow::showMinimized()
{

View File

@ -196,6 +196,7 @@ public:
void setScreen(QScreen *screen);
virtual QAccessibleInterface *accessibleRoot() const;
virtual QObject *focusObject() const;
QPoint mapToGlobal(const QPoint &pos) const;
QPoint mapFromGlobal(const QPoint &pos) const;

View File

@ -67,6 +67,16 @@ QAccessibleInterface *QWidgetWindow::accessibleRoot() const
return 0;
}
QObject *QWidgetWindow::focusObject() const
{
QWidget *widget = m_widget->focusWidget();
if (!widget)
widget = m_widget;
return widget;
}
bool QWidgetWindow::event(QEvent *event)
{
switch (event->type()) {
@ -287,12 +297,9 @@ void QWidgetWindow::handleKeyEvent(QKeyEvent *event)
if (QApplicationPrivate::instance()->modalState() && !qt_try_modal(m_widget, event->type()))
return;
QWidget *widget = m_widget->focusWidget();
QObject *receiver = focusObject();
if (!widget)
widget = m_widget;
QGuiApplication::sendSpontaneousEvent(widget, event);
QGuiApplication::sendSpontaneousEvent(receiver, event);
}
void QWidgetWindow::updateGeometry()

View File

@ -65,6 +65,7 @@ public:
QWidget *widget() const { return m_widget; }
QAccessibleInterface *accessibleRoot() const;
QObject *focusObject() const;
protected:
bool event(QEvent *);