Skip to content

Commit

Permalink
WSearchLineEdit: Apply PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
fwcd committed Nov 25, 2022
1 parent d1a78df commit 6e5d3be
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 41 deletions.
1 change: 0 additions & 1 deletion src/preferences/dialog/dlgprefinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "control/controlproxy.h"
#include "defs_urls.h"
#include "moc_dlgprefinterface.cpp"
#include "preferences/configobject.h"
#include "preferences/usersettings.h"
#include "skin/legacy/legacyskinparser.h"
#include "skin/skin.h"
Expand Down
12 changes: 6 additions & 6 deletions src/preferences/dialog/dlgpreflibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ void DlgPrefLibrary::slotResetToDefaults() {
setLibraryFont(QApplication::font());
searchDebouncingTimeoutSpinBox->setValue(
WSearchLineEdit::kDefaultDebouncingTimeoutMillis);
checkBoxEnableSearchCompletions->setChecked(WSearchLineEdit::kEnableSearchCompletionsByDefault);
checkBoxEnableSearchCompletions->setChecked(WSearchLineEdit::kEnableCompletionsByDefault);
checkBoxEnableSearchHistoryShortcuts->setChecked(
WSearchLineEdit::kEnableSearchHistoryShortcutsByDefault);
WSearchLineEdit::kEnableHistoryShortcutsByDefault);
}

void DlgPrefLibrary::slotUpdate() {
Expand Down Expand Up @@ -274,10 +274,10 @@ void DlgPrefLibrary::slotUpdate() {

checkBoxEnableSearchCompletions->setChecked(m_pConfig->getValue(
kEnableSearchCompletionsConfigKey,
WSearchLineEdit::kEnableSearchCompletionsByDefault));
WSearchLineEdit::kEnableCompletionsByDefault));
checkBoxEnableSearchHistoryShortcuts->setChecked(m_pConfig->getValue(
kEnableSearchHistoryShortcutsConfigKey,
WSearchLineEdit::kEnableSearchHistoryShortcutsByDefault));
WSearchLineEdit::kEnableHistoryShortcutsByDefault));

m_originalTrackTableFont = m_pLibrary->getTrackTableFont();
m_iOriginalTrackTableRowHeight = m_pLibrary->getTrackTableRowHeight();
Expand Down Expand Up @@ -516,10 +516,10 @@ void DlgPrefLibrary::slotSearchDebouncingTimeoutMillisChanged(int searchDebounci
void DlgPrefLibrary::searchHistoryOptionsChanged() {
WSearchLineEdit::setSearchCompletionsEnabled(m_pConfig->getValue<bool>(
kEnableSearchCompletionsConfigKey,
WSearchLineEdit::kEnableSearchCompletionsByDefault));
WSearchLineEdit::kEnableCompletionsByDefault));
WSearchLineEdit::setSearchHistoryShortcutsEnabled(m_pConfig->getValue<bool>(
kEnableSearchHistoryShortcutsConfigKey,
WSearchLineEdit::kEnableSearchHistoryShortcutsByDefault));
WSearchLineEdit::kEnableHistoryShortcutsByDefault));
}

void DlgPrefLibrary::slotSyncTrackMetadataToggled() {
Expand Down
18 changes: 5 additions & 13 deletions src/preferences/dialog/dlgpreflibrarydlg.ui
Original file line number Diff line number Diff line change
Expand Up @@ -361,27 +361,17 @@
</widget>
</item>

<item row="4" column="0">
<widget class="QLabel" name="labelSearchHistory">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text">
<string>Search history:</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2">
<item row="4" column="0" colspan="3">
<widget class="QCheckBox" name="checkBoxEnableSearchCompletions">
<property name="text">
<string>Enable search completions</string>
</property>
</widget>
</item>
<item row="14" column="1" colspan="2">
<item row="5" column="0" colspan="3">
<widget class="QCheckBox" name="checkBoxEnableSearchHistoryShortcuts">
<property name="text">
<string>Enable search history shortcuts</string>
<string>Enable search history keyboard shortcuts</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -565,6 +555,8 @@
<tabstop>libraryFont</tabstop>
<tabstop>libraryFontButton</tabstop>
<tabstop>searchDebouncingTimeoutSpinBox</tabstop>
<tabstop>checkBoxEnableSearchCompletions</tabstop>
<tabstop>checkBoxEnableSearchHistoryShortcuts</tabstop>
<tabstop>checkBox_show_rhythmbox</tabstop>
<tabstop>checkBox_show_banshee</tabstop>
<tabstop>checkBox_show_itunes</tabstop>
Expand Down
28 changes: 13 additions & 15 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#include "wsearchlineedit.h"

#include <qcompleter.h>
#include <qstringliteral.h>

#include <QAbstractItemView>
#include <QApplication>
#include <QCompleter>
#include <QFont>
#include <QLineEdit>
#include <QShortcut>
#include <QSizePolicy>
#include <QStringLiteral>
#include <QStyle>

#include "moc_wsearchlineedit.cpp"
Expand Down Expand Up @@ -65,22 +64,22 @@ constexpr int WSearchLineEdit::kMaxSearchEntries;

//static
int WSearchLineEdit::s_debouncingTimeoutMillis = kDefaultDebouncingTimeoutMillis;
bool WSearchLineEdit::s_searchCompletionsEnabled = kEnableSearchCompletionsByDefault;
bool WSearchLineEdit::s_searchHistoryShortcutsEnabled = kEnableSearchHistoryShortcutsByDefault;
bool WSearchLineEdit::s_completionsEnabled = kEnableCompletionsByDefault;
bool WSearchLineEdit::s_historyShortcutsEnabled = kEnableHistoryShortcutsByDefault;

//static
void WSearchLineEdit::setDebouncingTimeoutMillis(int debouncingTimeoutMillis) {
s_debouncingTimeoutMillis = verifyDebouncingTimeoutMillis(debouncingTimeoutMillis);
}

//static
// static
void WSearchLineEdit::setSearchCompletionsEnabled(bool searchCompletionsEnabled) {
s_searchCompletionsEnabled = searchCompletionsEnabled;
s_completionsEnabled = searchCompletionsEnabled;
}

//static
// static
void WSearchLineEdit::setSearchHistoryShortcutsEnabled(bool searchHistoryShortcutsEnabled) {
s_searchHistoryShortcutsEnabled = searchHistoryShortcutsEnabled;
s_historyShortcutsEnabled = searchHistoryShortcutsEnabled;
}

WSearchLineEdit::WSearchLineEdit(QWidget* pParent, UserSettingsPointer pConfig)
Expand Down Expand Up @@ -350,7 +349,7 @@ void WSearchLineEdit::keyPressEvent(QKeyEvent* keyEvent) {
// If we're at the top of the list the Up key clears the search bar,
// no matter if it's a saved or unsaved query.
// Otherwise Up is handled by the combobox itself.
if (!s_searchHistoryShortcutsEnabled) {
if (!s_historyShortcutsEnabled) {
return;
}
currentTextIndex = findCurrentTextIndex();
Expand All @@ -363,7 +362,7 @@ void WSearchLineEdit::keyPressEvent(QKeyEvent* keyEvent) {
case Qt::Key_Down:
// After clearing the text field the Down key
// is expected to show the latest query
if (!s_searchHistoryShortcutsEnabled) {
if (!s_historyShortcutsEnabled) {
return;
}
if (currentText().isEmpty()) {
Expand Down Expand Up @@ -393,7 +392,7 @@ void WSearchLineEdit::keyPressEvent(QKeyEvent* keyEvent) {
return;
case Qt::Key_Space:
// Open/close popup with Ctrl + space
if (s_searchHistoryShortcutsEnabled && keyEvent->modifiers() == Qt::ControlModifier) {
if (s_historyShortcutsEnabled && keyEvent->modifiers() == Qt::ControlModifier) {
if (view()->isVisible()) {
hidePopup();
} else {
Expand Down Expand Up @@ -691,11 +690,10 @@ void WSearchLineEdit::updateClearAndDropdownButton(const QString& text) {
void WSearchLineEdit::updateCompleter() {
#if ENABLE_TRACE_LOG
kLogger.trace()
<< "updateCompleter"
<< text;
<< "updateCompleter";
#endif // ENABLE_TRACE_LOG

lineEdit()->setCompleter(s_searchCompletionsEnabled ? m_completer.toWeakRef() : nullptr);
lineEdit()->setCompleter(s_completionsEnabled ? m_completer.toWeakRef() : nullptr);
}

bool WSearchLineEdit::event(QEvent* pEvent) {
Expand Down
11 changes: 5 additions & 6 deletions src/widget/wsearchlineedit.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#pragma once

#include <qcompleter.h>

#include <QComboBox>
#include <QCompleter>
#include <QDomNode>
#include <QEvent>
#include <QTimer>
Expand All @@ -24,8 +23,8 @@ class WSearchLineEdit : public QComboBox, public WBaseWidget {
static constexpr int kMaxDebouncingTimeoutMillis = 9999;
static constexpr int kSaveTimeoutMillis = 5000;
static constexpr int kMaxSearchEntries = 50;
static constexpr bool kEnableSearchCompletionsByDefault = true;
static constexpr bool kEnableSearchHistoryShortcutsByDefault = true;
static constexpr bool kEnableCompletionsByDefault = true;
static constexpr bool kEnableHistoryShortcutsByDefault = true;

// TODO(XXX): Replace with a public slot
static void setDebouncingTimeoutMillis(int debouncingTimeoutMillis);
Expand Down Expand Up @@ -80,8 +79,8 @@ class WSearchLineEdit : public QComboBox, public WBaseWidget {
// value provider that sends signals whenever the corresponding
// configuration value changes.
static int s_debouncingTimeoutMillis;
static bool s_searchCompletionsEnabled;
static bool s_searchHistoryShortcutsEnabled;
static bool s_completionsEnabled;
static bool s_historyShortcutsEnabled;

void refreshState();

Expand Down

0 comments on commit 6e5d3be

Please sign in to comment.