summaryrefslogtreecommitdiffstats
path: root/src/widget
diff options
context:
space:
mode:
authorUwe Klotz <uklotz@mixxx.org>2018-10-16 22:55:32 +0200
committerDaniel Schürmann <daschuer@mixxx.org>2018-11-14 21:53:14 +0100
commit7a2e5513aeab235bdcd27f94a24655ba2efe3e05 (patch)
tree6dbc05b9146c6e4f8847bd887b5f85982c4c7765 /src/widget
parent7a37334edda3b2193e7853e7c2a125ad8bf9ef58 (diff)
Respect timeout when clearing the search field by editing
Diffstat (limited to 'src/widget')
-rw-r--r--src/widget/wsearchlineedit.cpp46
-rw-r--r--src/widget/wtracktableview.cpp4
2 files changed, 15 insertions, 35 deletions
diff --git a/src/widget/wsearchlineedit.cpp b/src/widget/wsearchlineedit.cpp
index 1b3ca9450e..df8a027f68 100644
--- a/src/widget/wsearchlineedit.cpp
+++ b/src/widget/wsearchlineedit.cpp
@@ -122,17 +122,12 @@ void WSearchLineEdit::disableSearch() {
void WSearchLineEdit::restoreSearch(const QString& text) {
if (text.isNull()) {
// disable
- blockSignals(true);
- setText(kDisabledText);
- blockSignals(false);
setEnabled(false);
+ setText(kDisabledText);
} else {
- blockSignals(true);
- setText(text);
- blockSignals(false);
- updatePlaceholder(text);
- updateClearButton(text);
setEnabled(true);
+ // Updating the placeholder implicitly sets the text and updates the clear button
+ updatePlaceholder(text);
}
}
@@ -143,11 +138,11 @@ void WSearchLineEdit::triggerSearch() {
}
void WSearchLineEdit::showPlaceholder() {
- m_debouncingTimer.stop();
+ DEBUG_ASSERT(isEnabled());
+
+ // Deactivate text change listener
+ m_showingPlaceholder = true;
- // Must block signals here so that we don't emit a search() signal via
- // textChanged().
- blockSignals(true);
setText(tr("Search...", "noun"));
setToolTip(
tr("Search", "noun") + "\n" + tr("Enter a string to search for") + "\n\n" +
@@ -155,8 +150,6 @@ void WSearchLineEdit::showPlaceholder() {
tr("Focus", "Give search bar input focus") + "\n" + tr("Ctrl+Backspace") + " " +
tr("Clear input", "Clear the search bar input field") + "\n" + tr("Esc") + " " +
tr("Exit search", "Exit search bar and leave focus"));
- m_showingPlaceholder = true;
- blockSignals(false);
QPalette pal = palette();
pal.setColor(foregroundRole(), Qt::lightGray);
@@ -164,20 +157,16 @@ void WSearchLineEdit::showPlaceholder() {
}
void WSearchLineEdit::hidePlaceholder(const QString& text) {
- if (!m_showingPlaceholder) {
- return; // nothing to do
- }
+ DEBUG_ASSERT(isEnabled());
+
+ // Reactivate text change listener
+ m_showingPlaceholder = false;
- // Must block signals here so that we don't emit a search() signal via
- // textChanged().
- blockSignals(true);
if (text.isNull()) {
setText(kEmptySearch);
} else {
setText(text);
}
- m_showingPlaceholder = false;
- blockSignals(false);
QPalette pal = palette();
pal.setColor(foregroundRole(), m_foregroundColor);
@@ -210,26 +199,21 @@ bool WSearchLineEdit::event(QEvent* pEvent) {
void WSearchLineEdit::clearSearch() {
DEBUG_ASSERT(!m_showingPlaceholder);
setText(kEmptySearch);
+ emit searchCleared();
// Enforce immediate update of track table
triggerSearch();
}
// slot
void WSearchLineEdit::updateText(const QString& text) {
- if (m_showingPlaceholder) {
- DEBUG_ASSERT(!m_debouncingTimer.isActive());
- return; // do nothing while showing placeholder
- }
-
- if (text.isEmpty()) {
+ if (m_showingPlaceholder || !isEnabled()) {
+ updateClearButton(kEmptySearch);
m_debouncingTimer.stop();
- emit searchCleared();
} else {
+ updateClearButton(text);
DEBUG_ASSERT(m_debouncingTimer.isSingleShot());
m_debouncingTimer.start(kDebouncingTimeoutMillis);
}
-
- updateClearButton(text);
}
// slot
diff --git a/src/widget/wtracktableview.cpp b/src/widget/wtracktableview.cpp
index 9419c668ff..25d0f0dc73 100644
--- a/src/widget/wtracktableview.cpp
+++ b/src/widget/wtracktableview.cpp
@@ -1067,10 +1067,6 @@ void WTrackTableView::onSearchStarting() {
void WTrackTableView::onSearchCleared() {
restoreVScrollBarPos();
- TrackModel* trackModel = getTrackModel();
- if (trackModel) {
- trackModel->search("");
- }
}
void WTrackTableView::onShow() {