aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@digia.com>2014-01-15 17:55:48 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-15 20:00:54 +0100
commite32845b137834ef46d68345a0029d4af7c1d85bb (patch)
tree70dc77b98edef7f2f6185210e17b49c10f5a6d85 /src/quick
parent7409e4f8ae151301843492407cffb2208bb4f111 (diff)
QQuickWindow: Make sure popups receive key events on Mac
Change-Id: Ifaf96e567e735d9a837eaef798061bf08fc4a752 Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com> Reviewed-by: Alan Alpert <aalpert@blackberry.com>
Diffstat (limited to 'src/quick')
-rw-r--r--src/quick/items/qquickwindow.cpp41
-rw-r--r--src/quick/items/qquickwindow_p.h2
2 files changed, 32 insertions, 11 deletions
diff --git a/src/quick/items/qquickwindow.cpp b/src/quick/items/qquickwindow.cpp
index c3f5169804..c57ca5e838 100644
--- a/src/quick/items/qquickwindow.cpp
+++ b/src/quick/items/qquickwindow.cpp
@@ -1299,24 +1299,43 @@ bool QQuickWindow::event(QEvent *e)
void QQuickWindow::keyPressEvent(QKeyEvent *e)
{
Q_D(QQuickWindow);
-
-#ifndef QT_NO_SHORTCUT
- // Try looking for a Shortcut before sending key events
- if (QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(focusObject(), e))
- return;
-#endif
-
- if (d->activeFocusItem)
- sendEvent(d->activeFocusItem, e);
+ d->deliverKeyEvent(e);
}
/*! \reimp */
void QQuickWindow::keyReleaseEvent(QKeyEvent *e)
{
Q_D(QQuickWindow);
+ d->deliverKeyEvent(e);
+}
- if (d->activeFocusItem)
- sendEvent(d->activeFocusItem, e);
+void QQuickWindowPrivate::deliverKeyEvent(QKeyEvent *e)
+{
+ Q_Q(QQuickWindow);
+
+#ifndef QT_NO_SHORTCUT
+ // Try looking for a Shortcut before sending key events
+ if (e->type() == QEvent::KeyPress
+ && QGuiApplicationPrivate::instance()->shortcutMap.tryShortcutEvent(q->focusObject(), e))
+ return;
+#endif
+
+ if (activeFocusItem)
+ q->sendEvent(activeFocusItem, e);
+#ifdef Q_OS_MAC
+ else {
+ // This is the case for popup windows on Mac, where popup windows get focus
+ // in Qt (after exposure) but they are not "key windows" in the Cocoa sense.
+ // Therefore, the will never receive key events from Cocoa. Instead, the
+ // toplevel non-popup window (the application current "key window") will
+ // receive them. (QWidgetWindow does something similar for widgets, by keeping
+ // a list of popup windows, and forwarding the key event to the top-most popup.)
+ QWindow *focusWindow = qApp->focusWindow();
+ if (focusWindow && focusWindow != q
+ && (focusWindow->flags() & Qt::Popup) == Qt::Popup)
+ QGuiApplication::sendEvent(focusWindow, e);
+ }
+#endif
}
QMouseEvent *QQuickWindowPrivate::cloneMouseEvent(QMouseEvent *event, QPointF *transformedLocalPos)
diff --git a/src/quick/items/qquickwindow_p.h b/src/quick/items/qquickwindow_p.h
index 418633b6ac..d5c7b5d64c 100644
--- a/src/quick/items/qquickwindow_p.h
+++ b/src/quick/items/qquickwindow_p.h
@@ -111,6 +111,8 @@ public:
QQuickItem *activeFocusItem;
+ void deliverKeyEvent(QKeyEvent *e);
+
// Keeps track of the item currently receiving mouse events
QQuickItem *mouseGrabberItem;
#ifndef QT_NO_CURSOR