]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinviewcontainer.cpp
Make Escape move focus from location bar to view
[dolphin.git] / src / dolphinviewcontainer.cpp
index c89621dbd616dbe67a579a64aba7425989c4bfd3..c6c56ce240deb5a0340a8bdfcf7bbc7ba2bae1b7 100644 (file)
@@ -33,6 +33,9 @@
 #include <KShell>
 #include <kio_version.h>
 
+#ifndef QT_NO_ACCESSIBILITY
+#include <QAccessible>
+#endif
 #include <QApplication>
 #include <QDesktopServices>
 #include <QDropEvent>
@@ -306,6 +309,9 @@ void DolphinViewContainer::connectUrlNavigator(DolphinUrlNavigator *urlNavigator
     // Aside from these, only visual things need to be connected.
     connect(m_view, &DolphinView::urlChanged, urlNavigator, &DolphinUrlNavigator::setLocationUrl);
     connect(urlNavigator, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
+    connect(urlNavigator, &DolphinUrlNavigator::requestToLoseFocus, m_view, [this]() {
+        m_view->setFocus();
+    });
 
     urlNavigator->setReadOnlyBadgeVisible(rootItem().isLocalFile() && !rootItem().isWritable());
 
@@ -322,6 +328,7 @@ void DolphinViewContainer::disconnectUrlNavigator()
     disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::urlsDropped, this, nullptr);
     disconnect(m_view, &DolphinView::urlChanged, m_urlNavigatorConnected, &DolphinUrlNavigator::setLocationUrl);
     disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::activated, this, &DolphinViewContainer::activate);
+    disconnect(m_urlNavigatorConnected, &DolphinUrlNavigator::requestToLoseFocus, m_view, nullptr);
 
     m_urlNavigatorVisualState = m_urlNavigatorConnected->visualState();
     m_urlNavigatorConnected = nullptr;
@@ -436,6 +443,14 @@ void DolphinViewContainer::showMessage(const QString &message, KMessageWidget::M
         m_messageWidget->hide();
     }
     m_messageWidget->animatedShow();
+
+#ifndef QT_NO_ACCESSIBILITY
+    if (QAccessible::isActive() && isActive()) {
+        // To announce the new message keyboard focus must be moved to the message label. However, we do not have direct access to the label that is internal
+        // to the KMessageWidget. Instead we setFocus() on the KMessageWidget and trust that it has set correct focus handling.
+        m_messageWidget->setFocus();
+    }
+#endif
 }
 
 void DolphinViewContainer::readSettings()