Skip to content

Commit

Permalink
WSearchLineEdit: Add Ctrl+Shift+F shortcut to search the main tracks …
Browse files Browse the repository at this point in the history
…database
  • Loading branch information
cr7pt0gr4ph7 committed May 3, 2024
1 parent 67a41d9 commit f587bae
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/library/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ void Library::bindSearchboxWidget(WSearchLineEdit* pSearchboxWidget) {
&WSearchLineEdit::setLibraryFocus,
m_pLibraryControl,
&LibraryControl::setLibraryFocus);
connect(pSearchboxWidget,
&WSearchLineEdit::switchToLibraryFeature,
this,
&Library::slotSwitchToFeature);
}

void Library::bindSidebarWidget(WLibrarySidebar* pSidebarWidget) {
Expand Down Expand Up @@ -528,6 +532,18 @@ void Library::onPlayerManagerTrackAnalyzerIdle() {
}
}

void Library::slotSwitchToFeature(const QString& featureName) {
if (featureName.isNull()) {
return;
}
for (auto feature : m_features) {

Check warning on line 539 in src/library/library.cpp

View workflow job for this annotation

GitHub Actions / clang-tidy

'auto feature' can be declared as 'auto *feature' [readability-qualified-auto]
if (feature->metaObject()->className() == featureName) {
feature->activate();
return;
}
}
}

void Library::slotShowTrackModel(QAbstractItemModel* model) {
// qDebug() << "Library::slotShowTrackModel" << model;
TrackModel* trackModel = dynamic_cast<TrackModel*>(model);
Expand Down
1 change: 1 addition & 0 deletions src/library/library.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Library: public QObject {

public slots:
void slotShowTrackModel(QAbstractItemModel* model);
void slotSwitchToFeature(const QString& featureName);
void slotSwitchToView(const QString& view);
void slotLoadTrack(TrackPointer pTrack);
void slotLoadTrackToPlayer(TrackPointer pTrack, const QString& group, bool play);
Expand Down
13 changes: 13 additions & 0 deletions src/widget/wsearchlineedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ WSearchLineEdit::WSearchLineEdit(QWidget* pParent, UserSettingsPointer pConfig)
this,
&WSearchLineEdit::slotSetShortcutFocus);

QShortcut* switchToTracksAndSetFocusShortcut =
new QShortcut(QKeySequence("Ctrl+Shift+F"), this);
connect(switchToTracksAndSetFocusShortcut,
&QShortcut::activated,
this,
&WSearchLineEdit::slotSwitchToTracksAndSetFocusShortcut);

// Set up a timer to search after a few hundred milliseconds timeout. This
// stops us from thrashing the database if you type really fast.
m_debouncingTimer.setSingleShot(true);
Expand Down Expand Up @@ -797,6 +804,12 @@ void WSearchLineEdit::slotSetShortcutFocus() {
}
}

void WSearchLineEdit::slotSwitchToTracksAndSetFocusShortcut() {
emit switchToLibraryFeature(LibraryFeatureName::Tracks);

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / clazy

use of undeclared identifier 'LibraryFeatureName'

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04

‘LibraryFeatureName’ has not been declared

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 x64

use of undeclared identifier 'LibraryFeatureName'

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / macOS 11 arm64

use of undeclared identifier 'LibraryFeatureName'

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / coverage

‘LibraryFeatureName’ has not been declared

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'LibraryFeatureName': is not a class or namespace name

Check failure on line 808 in src/widget/wsearchlineedit.cpp

View workflow job for this annotation

GitHub Actions / Windows 2019 (MSVC)

'Tracks': undeclared identifier
setFocus(Qt::ShortcutFocusReason);
lineEdit()->selectAll();
}

// Use the same font as the library table and the sidebar
void WSearchLineEdit::slotSetFont(const QFont& font) {
setFont(font);
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wsearchlineedit.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class WSearchLineEdit : public QComboBox, public WBaseWidget {
signals:
void search(const QString& text);
FocusWidget setLibraryFocus(FocusWidget newFocusWidget);
void switchToLibraryFeature(const QString& featureName);

public slots:
void slotSetFont(const QFont& font);
Expand All @@ -66,6 +67,7 @@ class WSearchLineEdit : public QComboBox, public WBaseWidget {

private slots:
void slotSetShortcutFocus();
void slotSwitchToTracksAndSetFocusShortcut();
void slotTextChanged(const QString& text);
void slotIndexChanged(int index);

Expand Down

0 comments on commit f587bae

Please sign in to comment.