┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Popov <[email protected]>2023-04-21 15:41:13 +0300
committerMéven Car <[email protected]>2023-04-22 17:09:31 +0000
commit6fd77a96b4117b7210ecd5fab1a6304cb3ebc976 (patch)
treea163a1aa1f891f1d65152c75d51748774b95cfa9
parentc9217337c717c336eb8cfcc27e9d4992bc1ebb37 (diff)
FilterBar: improve keyboard behavior and tab ordering
With this MR, when the filterbar has the keyboard focus: - pressing the Tab key moves the keyboard focus to the view - pressing the Down, PageDown, Up and PageUp keys moves the focus to the view and emulate pressing the same key in it (you can navigate directly from the filterbar)
-rw-r--r--src/filterbar/filterbar.cpp26
-rw-r--r--src/filterbar/filterbar.h2
2 files changed, 22 insertions, 6 deletions
diff --git a/src/filterbar/filterbar.cpp b/src/filterbar/filterbar.cpp
index 76e23d420..e24025c5b 100644
--- a/src/filterbar/filterbar.cpp
+++ b/src/filterbar/filterbar.cpp
@@ -10,6 +10,7 @@
#include <KLocalizedString>
+#include <QApplication>
#include <QHBoxLayout>
#include <QKeyEvent>
#include <QLineEdit>
@@ -47,6 +48,9 @@ FilterBar::FilterBar(QWidget *parent)
hLayout->addWidget(m_lockButton);
hLayout->addWidget(m_filterInput);
hLayout->addWidget(closeButton);
+
+ setTabOrder(m_lockButton, closeButton);
+ setTabOrder(closeButton, m_filterInput);
}
FilterBar::~FilterBar()
@@ -96,10 +100,8 @@ void FilterBar::showEvent(QShowEvent *event)
}
}
-void FilterBar::keyReleaseEvent(QKeyEvent *event)
+void FilterBar::keyPressEvent(QKeyEvent *event)
{
- QWidget::keyReleaseEvent(event);
-
switch (event->key()) {
case Qt::Key_Escape:
if (m_filterInput->text().isEmpty()) {
@@ -107,14 +109,28 @@ void FilterBar::keyReleaseEvent(QKeyEvent *event)
} else {
m_filterInput->clear();
}
- break;
+ return;
case Qt::Key_Enter:
case Qt::Key_Return:
Q_EMIT focusViewRequest();
- break;
+ return;
+
+ case Qt::Key_Down:
+ case Qt::Key_PageDown:
+ case Qt::Key_Up:
+ case Qt::Key_PageUp: {
+ Q_EMIT focusViewRequest();
+ QWidget *focusWidget = QApplication::focusWidget();
+ if (focusWidget && focusWidget != this) {
+ QApplication::sendEvent(focusWidget, event);
+ }
+ return;
+ }
default:
break;
}
+
+ QWidget::keyPressEvent(event);
}
diff --git a/src/filterbar/filterbar.h b/src/filterbar/filterbar.h
index 8a0b81431..353055883 100644
--- a/src/filterbar/filterbar.h
+++ b/src/filterbar/filterbar.h
@@ -62,7 +62,7 @@ Q_SIGNALS:
protected:
void showEvent(QShowEvent *event) override;
- void keyReleaseEvent(QKeyEvent *event) override;
+ void keyPressEvent(QKeyEvent *event) override;
private:
QLineEdit *m_filterInput;