From 2067fa4446a7a616b0e0dc6961650c0c086c6eae Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Mon, 2 Nov 2020 23:59:35 +0100 Subject: [PATCH 1/8] Change searchbar clear behaviour Clear the searchbar on up-key after the first entry and remove tab focus from searchbar clear button. This way, the tab order is fixed again while keeping the possibility to use the arrow mapping for clearing the search bar. --- src/widget/wsearchlineedit.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index 70c627fba52..1d132e44bf3 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -97,6 +97,7 @@ WSearchLineEdit::WSearchLineEdit(QWidget* pParent) m_clearButton->setCursor(Qt::ArrowCursor); m_clearButton->setObjectName(QStringLiteral("SearchClearButton")); + m_clearButton->setFocusPolicy(Qt::ClickFocus); // Query style for arrow width and frame border updateStyleMetrics(); @@ -280,7 +281,13 @@ QString WSearchLineEdit::getSearchText() const { bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast(event); - if (keyEvent->key() == Qt::Key_Down) { + if (keyEvent->key() == Qt::Key_Up) { + if (findCurrentTextIndex() == 0) { + setCurrentIndex(-1); + setCurrentText(""); + return true; + } + } else if (keyEvent->key() == Qt::Key_Down) { // after clearing the text field the down key is expected to // show the last entry if (currentText().isEmpty()) { From 895d3c038e0e68764dc1e7ee0c4442e73787edbc Mon Sep 17 00:00:00 2001 From: Daniel Poelzleithner Date: Mon, 18 Jan 2021 20:20:13 +0100 Subject: [PATCH 2/8] Revert search clear button focus change --- src/widget/wsearchlineedit.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index e0accb1526b..23122c8c5ff 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -93,7 +93,6 @@ WSearchLineEdit::WSearchLineEdit(QWidget* pParent) m_clearButton->setCursor(Qt::ArrowCursor); m_clearButton->setObjectName(QStringLiteral("SearchClearButton")); - m_clearButton->setFocusPolicy(Qt::ClickFocus); // Query style for arrow width and frame border updateStyleMetrics(); From 3d5a94b08891f00d471e310adeb9c47459d6e3e3 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sun, 14 Feb 2021 18:03:48 +0100 Subject: [PATCH 3/8] WSearchLineEdit: let Up key clear text before save timer runs out --- src/widget/wsearchlineedit.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index 23122c8c5ff..fef015ddde0 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -277,7 +277,8 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Up) { - if (findCurrentTextIndex() == 0) { + if (findCurrentTextIndex() == 0 || + (findCurrentTextIndex() == -1 && !currentText().isEmpty())) { setCurrentIndex(-1); setCurrentText(""); return true; From d7b36ba70c307f76b269948a26e72f469df493cd Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sun, 14 Feb 2021 18:09:34 +0100 Subject: [PATCH 4/8] WSearchLineEdit: let Clear only clear the text, not the history lp:1913660 --- src/widget/wsearchlineedit.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index fef015ddde0..5af46a5235f 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -522,7 +522,9 @@ void WSearchLineEdit::slotClearSearch() { // before returning the whole (and probably huge) library. // No need to manually trigger a search at this point! // See also: https://bugs.launchpad.net/mixxx/+bug/1635087 - clear(); + // Note that clear() would not just clear the line edit but + // erase all combobox items, thus clear the entire search history. + setCurrentText(""); // Refocus the edit field setFocus(Qt::OtherFocusReason); } From 6a4f9d9d2845ef823e9ffdc8c5e35136821bdb05 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Sun, 14 Feb 2021 18:11:05 +0100 Subject: [PATCH 5/8] WSearchLineEdit: use slotClearSearch() for Up key events --- src/widget/wsearchlineedit.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index 5af46a5235f..10418ad4806 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -279,8 +279,7 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { if (keyEvent->key() == Qt::Key_Up) { if (findCurrentTextIndex() == 0 || (findCurrentTextIndex() == -1 && !currentText().isEmpty())) { - setCurrentIndex(-1); - setCurrentText(""); + slotClearSearch(); return true; } } else if (keyEvent->key() == Qt::Key_Down) { From 2f729a38066ef623dbfc8df8823488f2a181a2f3 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Tue, 16 Feb 2021 00:25:45 +0100 Subject: [PATCH 6/8] WSearchLineEdit: comment Up key / clear behaviour --- src/widget/wsearchlineedit.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index 10418ad4806..f66ade13478 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -277,6 +277,8 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast(event); if (keyEvent->key() == Qt::Key_Up) { + // if we're at the top of the list the Up key clears the search bar, + // no matter if it's a saved and unsaved query if (findCurrentTextIndex() == 0 || (findCurrentTextIndex() == -1 && !currentText().isEmpty())) { slotClearSearch(); @@ -284,13 +286,13 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { } } else if (keyEvent->key() == Qt::Key_Down) { // after clearing the text field the down key is expected to - // show the last entry + // show the latest entry if (currentText().isEmpty()) { setCurrentIndex(0); return true; } // in case the user entered a new search query - // und presses the down key, save the query for later recall + // and presses the down key, save the query for later recall if (findCurrentTextIndex() == -1) { slotSaveSearch(); } @@ -304,7 +306,7 @@ bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { return true; } else if (keyEvent->key() == Qt::Key_Space && keyEvent->modifiers() == Qt::ControlModifier) { - // open popup on ctrl + space + // open/close popup on ctrl + space if (view()->isVisible()) { hidePopup(); } else { From 973e836d1db8fc316c4a5de0f8dde33668265bf8 Mon Sep 17 00:00:00 2001 From: ronso0 Date: Wed, 17 Feb 2021 01:45:00 +0100 Subject: [PATCH 7/8] WSearchLineEdit: don't intercept Up/Down keys if the popup is open --- src/widget/wsearchlineedit.cpp | 44 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index f66ade13478..fca7d7bc02c 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -276,27 +276,31 @@ QString WSearchLineEdit::getSearchText() const { bool WSearchLineEdit::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::KeyPress) { QKeyEvent* keyEvent = static_cast(event); - if (keyEvent->key() == Qt::Key_Up) { - // if we're at the top of the list the Up key clears the search bar, - // no matter if it's a saved and unsaved query - if (findCurrentTextIndex() == 0 || - (findCurrentTextIndex() == -1 && !currentText().isEmpty())) { - slotClearSearch(); - return true; - } - } else if (keyEvent->key() == Qt::Key_Down) { - // after clearing the text field the down key is expected to - // show the latest entry - if (currentText().isEmpty()) { - setCurrentIndex(0); - return true; - } - // in case the user entered a new search query - // and presses the down key, save the query for later recall - if (findCurrentTextIndex() == -1) { - slotSaveSearch(); + // if the popup is open don't intercept Up/Down keys + if (!view()->isVisible()) { + if (keyEvent->key() == Qt::Key_Up) { + // if we're at the top of the list the Up key clears the search bar, + // no matter if it's a saved and unsaved query + if (findCurrentTextIndex() == 0 || + (findCurrentTextIndex() == -1 && !currentText().isEmpty())) { + slotClearSearch(); + return true; + } + } else if (keyEvent->key() == Qt::Key_Down) { + // after clearing the text field the down key is expected to + // show the latest entry + if (currentText().isEmpty()) { + setCurrentIndex(0); + return true; + } + // in case the user entered a new search query + // and presses the down key, save the query for later recall + if (findCurrentTextIndex() == -1) { + slotSaveSearch(); + } } - } else if (keyEvent->key() == Qt::Key_Enter) { + } + if (keyEvent->key() == Qt::Key_Enter) { if (findCurrentTextIndex() == -1) { slotSaveSearch(); } From 619f9fcab3fb272d943251719648f8e7007d91ba Mon Sep 17 00:00:00 2001 From: ronso0 Date: Wed, 17 Feb 2021 01:55:18 +0100 Subject: [PATCH 8/8] WSearchLineEdit: use lineEdit()->clear() instead of setText("") --- src/widget/wsearchlineedit.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp index fca7d7bc02c..d5e237b61a6 100644 --- a/src/widget/wsearchlineedit.cpp +++ b/src/widget/wsearchlineedit.cpp @@ -527,9 +527,9 @@ void WSearchLineEdit::slotClearSearch() { // before returning the whole (and probably huge) library. // No need to manually trigger a search at this point! // See also: https://bugs.launchpad.net/mixxx/+bug/1635087 - // Note that clear() would not just clear the line edit but - // erase all combobox items, thus clear the entire search history. - setCurrentText(""); + // Note that just clear() would also erase all combobox items, + // thus clear the entire search history. + lineEdit()->clear(); // Refocus the edit field setFocus(Qt::OtherFocusReason); }