Make pressing enter in the library filter widget add the search results to the playlist. Also make the cursor keys work when the filter widget is focused. Fixes issue #641
This commit is contained in:
parent
4277e61cd3
commit
eb65c06b24
@ -22,6 +22,7 @@
|
||||
#include "ui/settingsdialog.h"
|
||||
#include "widgets/maclineedit.h"
|
||||
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QActionGroup>
|
||||
#include <QSignalMapper>
|
||||
@ -34,6 +35,7 @@ LibraryFilterWidget::LibraryFilterWidget(QWidget *parent)
|
||||
group_by_dialog_(new GroupByDialog)
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
connect(ui_->filter, SIGNAL(returnPressed()), SIGNAL(ReturnPressed()));
|
||||
|
||||
// Icons
|
||||
ui_->clear->setIcon(IconLoader::Load("edit-clear-locationbar-ltr"));
|
||||
@ -202,3 +204,24 @@ void LibraryFilterWidget::SetGroupByEnabled(bool enabled) {
|
||||
void LibraryFilterWidget::AddMenuAction(QAction* action) {
|
||||
library_menu_->addAction(action);
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::AppendAndFocus(const QString& text) {
|
||||
ui_->filter->setText(ui_->filter->text() + text);
|
||||
ui_->filter->setFocus();
|
||||
}
|
||||
|
||||
void LibraryFilterWidget::keyReleaseEvent(QKeyEvent* e) {
|
||||
switch (e->key()) {
|
||||
case Qt::Key_Up:
|
||||
emit UpPressed();
|
||||
e->accept();
|
||||
break;
|
||||
|
||||
case Qt::Key_Down:
|
||||
emit DownPressed();
|
||||
e->accept();
|
||||
break;
|
||||
}
|
||||
|
||||
QWidget::keyReleaseEvent(e);
|
||||
}
|
||||
|
@ -47,6 +47,17 @@ class LibraryFilterWidget : public QWidget {
|
||||
void SetSettingsGroup(const QString& group) { settings_group_ = group; }
|
||||
void SetLibraryModel(LibraryModel* model);
|
||||
|
||||
public slots:
|
||||
void AppendAndFocus(const QString& text);
|
||||
|
||||
signals:
|
||||
void UpPressed();
|
||||
void DownPressed();
|
||||
void ReturnPressed();
|
||||
|
||||
protected:
|
||||
void keyReleaseEvent(QKeyEvent* e);
|
||||
|
||||
private slots:
|
||||
void GroupingChanged(const LibraryModel::Grouping& g);
|
||||
void GroupByClicked(QAction* action);
|
||||
|
@ -87,8 +87,7 @@ LibraryView::LibraryView(QWidget* parent)
|
||||
library_(NULL),
|
||||
total_song_count_(-1),
|
||||
nomusic_(":nomusic.png"),
|
||||
context_menu_(NULL),
|
||||
is_in_keyboard_search_(false)
|
||||
context_menu_(NULL)
|
||||
{
|
||||
setItemDelegate(new LibraryItemDelegate(this));
|
||||
setAttribute(Qt::WA_MacShowFocusRect, false);
|
||||
@ -244,17 +243,8 @@ void LibraryView::AddToPlaylist() {
|
||||
emit AddToPlaylist(selectedIndexes());
|
||||
}
|
||||
|
||||
void LibraryView::keyboardSearch(const QString &search) {
|
||||
is_in_keyboard_search_ = true;
|
||||
QTreeView::keyboardSearch(search);
|
||||
is_in_keyboard_search_ = false;
|
||||
}
|
||||
|
||||
void LibraryView::scrollTo(const QModelIndex &index, ScrollHint hint) {
|
||||
if (is_in_keyboard_search_)
|
||||
QTreeView::scrollTo(index, QAbstractItemView::PositionAtTop);
|
||||
else
|
||||
QTreeView::scrollTo(index, hint);
|
||||
void LibraryView::keyboardSearch(const QString& search) {
|
||||
emit FocusFilterBox(search);
|
||||
}
|
||||
|
||||
void LibraryView::GetSelectedFileInfo(
|
||||
@ -351,3 +341,31 @@ void LibraryView::DeleteFinished(const SongList& songs_with_errors) {
|
||||
dialog->Show(OrganiseErrorDialog::Type_Delete, songs_with_errors);
|
||||
// It deletes itself when the user closes it
|
||||
}
|
||||
|
||||
void LibraryView::UpAndFocus() {
|
||||
setCurrentIndex(moveCursor(QAbstractItemView::MoveUp, Qt::NoModifier));
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void LibraryView::DownAndFocus() {
|
||||
setCurrentIndex(moveCursor(QAbstractItemView::MoveDown, Qt::NoModifier));
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void LibraryView::FilterReturnPressed() {
|
||||
if (!currentIndex().isValid()) {
|
||||
// Pick the first thing that isn't a divider
|
||||
for (int row=0 ; row<model()->rowCount() ; ++row) {
|
||||
QModelIndex idx(model()->index(row, 0));
|
||||
if (idx.data(LibraryModel::Role_Type) != LibraryItem::Type_Divider) {
|
||||
setCurrentIndex(idx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!currentIndex().isValid())
|
||||
return;
|
||||
|
||||
emit doubleClicked(currentIndex());
|
||||
}
|
||||
|
@ -50,16 +50,20 @@ class LibraryView : public AutoExpandingTreeView {
|
||||
|
||||
// QTreeView
|
||||
void keyboardSearch(const QString &search);
|
||||
void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
|
||||
|
||||
public slots:
|
||||
void TotalSongCountUpdated(int count);
|
||||
void ReloadSettings();
|
||||
|
||||
void UpAndFocus();
|
||||
void DownAndFocus();
|
||||
void FilterReturnPressed();
|
||||
|
||||
signals:
|
||||
void ShowConfigDialog();
|
||||
void Load(const QModelIndexList& indexes);
|
||||
void AddToPlaylist(const QModelIndexList& indexes);
|
||||
void FocusFilterBox(const QString& text);
|
||||
|
||||
protected:
|
||||
// QWidget
|
||||
@ -104,8 +108,6 @@ class LibraryView : public AutoExpandingTreeView {
|
||||
QAction* no_show_in_various_;
|
||||
|
||||
boost::scoped_ptr<OrganiseDialog> organise_dialog_;
|
||||
|
||||
bool is_in_keyboard_search_;
|
||||
};
|
||||
|
||||
#endif // LIBRARYVIEW_H
|
||||
|
@ -364,6 +364,7 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
|
||||
connect(ui_->library_view, SIGNAL(Load(QModelIndexList)), SLOT(LoadLibraryItemToPlaylist(QModelIndexList)));
|
||||
connect(ui_->library_view, SIGNAL(AddToPlaylist(QModelIndexList)), SLOT(AddLibraryItemToPlaylist(QModelIndexList)));
|
||||
connect(ui_->library_view, SIGNAL(ShowConfigDialog()), SLOT(ShowLibraryConfig()));
|
||||
connect(ui_->library_view, SIGNAL(FocusFilterBox(QString)), ui_->library_filter, SLOT(AppendAndFocus(QString)));
|
||||
connect(library_->model(), SIGNAL(TotalSongCountUpdated(int)), ui_->library_view, SLOT(TotalSongCountUpdated(int)));
|
||||
|
||||
connect(task_manager_, SIGNAL(PauseLibraryWatchers()), library_, SLOT(PauseWatcher()));
|
||||
@ -382,6 +383,9 @@ MainWindow::MainWindow(NetworkAccessManager* network, Engine::Type engine, QWidg
|
||||
ui_->library_filter->SetSettingsGroup(kSettingsGroup);
|
||||
ui_->library_filter->SetLibraryModel(library_->model());
|
||||
ui_->library_filter->AddMenuAction(library_config_action);
|
||||
connect(ui_->library_filter, SIGNAL(UpPressed()), ui_->library_view, SLOT(UpAndFocus()));
|
||||
connect(ui_->library_filter, SIGNAL(DownPressed()), ui_->library_view, SLOT(DownAndFocus()));
|
||||
connect(ui_->library_filter, SIGNAL(ReturnPressed()), ui_->library_view, SLOT(FilterReturnPressed()));
|
||||
|
||||
// Playlist menu
|
||||
playlist_play_pause_ = playlist_menu_->addAction(tr("Play"), this, SLOT(PlaylistPlay()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user