Fix some remaining UI issues with global search:

- Add a "Configure global search" item to the context menu, and show the
    context menu when right clicking in the help screen as well.
  - Don't crash when nothing is selected.
  - Add Ctrl+F and Ctrl+L shortcuts to focus the search field.
  - Switch to the search tab when clicking one of the tags in Artist Info.
This commit is contained in:
David Sansome 2012-06-16 21:17:13 +01:00
parent b427fc8a24
commit 45a8b3af59
5 changed files with 71 additions and 14 deletions

View File

@ -62,7 +62,7 @@ GlobalSearchView::GlobalSearchView(Application* app, QWidget* parent)
ui_->setupUi(this);
ui_->search->installEventFilter(this);
ui_->results->installEventFilter(this);
ui_->results_stack->installEventFilter(this);
// Must be a queued connection to ensure the GlobalSearch handles it first.
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()), Qt::QueuedConnection);
@ -77,7 +77,7 @@ GlobalSearchView::GlobalSearchView(Application* app, QWidget* parent)
ui_->results->setStyleSheet("QTreeView::item{padding-top:1px;}");
// Show the help page initially
ui_->stack->setCurrentWidget(ui_->help_page);
ui_->results_stack->setCurrentWidget(ui_->help_page);
ui_->help_frame->setBackgroundRole(QPalette::Base);
QVBoxLayout* enabled_layout = new QVBoxLayout(ui_->enabled_list);
QVBoxLayout* disabled_layout = new QVBoxLayout(ui_->disabled_list);
@ -255,9 +255,9 @@ void GlobalSearchView::SwapModels() {
ui_->results->setModel(front_proxy_);
if (ui_->search->text().trimmed().isEmpty()) {
ui_->stack->setCurrentWidget(ui_->help_page);
ui_->results_stack->setCurrentWidget(ui_->help_page);
} else {
ui_->stack->setCurrentWidget(ui_->results_page);
ui_->results_stack->setCurrentWidget(ui_->results_page);
}
}
@ -315,6 +315,9 @@ void GlobalSearchView::ArtLoaded(int id, const QPixmap& pixmap) {
}
MimeData* GlobalSearchView::SelectedMimeData() {
if (!ui_->results->selectionModel())
return NULL;
// Get all selected model indexes
QModelIndexList indexes = ui_->results->selectionModel()->selectedRows();
if (indexes.isEmpty()) {
@ -349,7 +352,7 @@ bool GlobalSearchView::eventFilter(QObject* object, QEvent* event) {
if (SearchKeyEvent(static_cast<QKeyEvent*>(event))) {
return true;
}
} else if (object == ui_->results && event->type() == QEvent::ContextMenu) {
} else if (object == ui_->results_stack && event->type() == QEvent::ContextMenu) {
if (ResultsContextMenuEvent(static_cast<QContextMenuEvent*>(event))) {
return true;
}
@ -383,16 +386,28 @@ bool GlobalSearchView::SearchKeyEvent(QKeyEvent* event) {
bool GlobalSearchView::ResultsContextMenuEvent(QContextMenuEvent* event) {
if (!context_menu_) {
context_menu_ = new QMenu(this);
context_menu_->addAction(IconLoader::Load("media-playback-start"),
context_actions_ << context_menu_->addAction(IconLoader::Load("media-playback-start"),
tr("Append to current playlist"), this, SLOT(AddSelectedToPlaylist()));
context_menu_->addAction(IconLoader::Load("media-playback-start"),
context_actions_ << context_menu_->addAction(IconLoader::Load("media-playback-start"),
tr("Replace current playlist"), this, SLOT(LoadSelected()));
context_menu_->addAction(IconLoader::Load("document-new"),
context_actions_ << context_menu_->addAction(IconLoader::Load("document-new"),
tr("Open in new playlist"), this, SLOT(OpenSelectedInNewPlaylist()));
context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("go-next"),
context_actions_ << context_menu_->addAction(IconLoader::Load("go-next"),
tr("Queue track"), this, SLOT(AddSelectedToPlaylistEnqueue()));
context_menu_->addSeparator();
context_menu_->addAction(IconLoader::Load("configure"),
tr("Configure global search..."), this, SLOT(OpenSettingsDialog()));
}
const bool enable_context_actions =
ui_->results->selectionModel() &&
ui_->results->selectionModel()->hasSelection();
foreach (QAction* action, context_actions_) {
action->setEnabled(enable_context_actions);
}
context_menu_->popup(event->globalPos());
@ -406,18 +421,27 @@ void GlobalSearchView::AddSelectedToPlaylist() {
void GlobalSearchView::LoadSelected() {
MimeData* data = SelectedMimeData();
if (!data)
return;
data->clear_first_ = true;
emit AddToPlaylist(data);
}
void GlobalSearchView::AddSelectedToPlaylistEnqueue() {
MimeData* data = SelectedMimeData();
if (!data)
return;
data->enqueue_now_ = true;
emit AddToPlaylist(data);
}
void GlobalSearchView::OpenSelectedInNewPlaylist() {
MimeData* data = SelectedMimeData();
if (!data)
return;
data->open_in_new_playlist_ = true;
emit AddToPlaylist(data);
}
@ -428,6 +452,13 @@ void GlobalSearchView::showEvent(QShowEvent* e) {
update_suggestions_timer_->start();
}
QWidget::showEvent(e);
FocusSearchField();
}
void GlobalSearchView::FocusSearchField() {
ui_->search->set_focus();
ui_->search->selectAll();
}
void GlobalSearchView::hideEvent(QHideEvent* e) {
@ -439,3 +470,7 @@ void GlobalSearchView::FocusOnFilter(QKeyEvent* event) {
ui_->search->set_focus();
QApplication::sendEvent(ui_->search, event);
}
void GlobalSearchView::OpenSettingsDialog() {
app_->OpenSettingsDialogAtPage(SettingsDialog::Page_GlobalSearch);
}

View File

@ -59,10 +59,11 @@ public:
public slots:
void ReloadSettings();
void StartSearch(const QString& query);
void FocusSearchField();
void OpenSettingsDialog();
signals:
void AddToPlaylist(QMimeData* data);
void OpenSettingsAtPage(SettingsDialog::Page page);
private slots:
void UpdateSuggestions();
@ -91,6 +92,7 @@ private:
Ui_GlobalSearchView* ui_;
QMenu* context_menu_;
QList<QAction*> context_actions_;
int last_search_id_;

View File

@ -25,7 +25,7 @@
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stack">
<widget class="QStackedWidget" name="results_stack">
<property name="currentIndex">
<number>1</number>
</property>
@ -80,7 +80,7 @@
<x>0</x>
<y>0</y>
<width>435</width>
<height>604</height>
<height>605</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">

View File

@ -222,7 +222,6 @@ MainWindow::MainWindow(Application* app,
global_search_view_->ReloadSettings();
connect(global_search_view_, SIGNAL(AddToPlaylist(QMimeData*)), SLOT(AddToPlaylist(QMimeData*)));
connect(global_search_view_, SIGNAL(OpenSettingsAtPage(SettingsDialog::Page)), SLOT(OpenSettingsDialogAtPage(SettingsDialog::Page)));
// Add tabs to the fancy tab widget
ui_->tabs->AddTab(global_search_view_, IconLoader::Load("search"), tr("Search"));
@ -510,6 +509,15 @@ MainWindow::MainWindow(Application* app,
connect(app_->device_manager()->connected_devices_model(), SIGNAL(IsEmptyChanged(bool)),
playlist_copy_to_device_, SLOT(setDisabled(bool)));
// Global search shortcut
QAction* global_search_action = new QAction(this);
global_search_action->setShortcuts(QList<QKeySequence>()
<< QKeySequence("Ctrl+F")
<< QKeySequence("Ctrl+L"));
addAction(global_search_action);
connect(global_search_action, SIGNAL(triggered()),
SLOT(FocusGlobalSearchField()));
// Internet connections
connect(app_->internet_model(), SIGNAL(StreamError(QString)), SLOT(ShowErrorDialog(QString)));
connect(app_->internet_model(), SIGNAL(StreamMetadataFound(QUrl,Song)), app_->playlist_manager(), SLOT(SetActiveStreamMetadata(QUrl,Song)));
@ -2025,7 +2033,7 @@ void MainWindow::ConnectInfoView(SongInfoBase* view) {
connect(view, SIGNAL(ShowSettingsDialog()), SLOT(ShowSongInfoConfig()));
connect(view, SIGNAL(DoGlobalSearch(QString)),
global_search_view_, SLOT(StartSearch(QString)));
SLOT(DoGlobalSearch(QString)));
}
void MainWindow::AddSongInfoGenerator(smart_playlists::GeneratorPtr gen) {
@ -2236,3 +2244,13 @@ void MainWindow::ScrollToInternetIndex(const QModelIndex& index) {
void MainWindow::AddPodcast() {
app_->internet_model()->Service<PodcastService>()->AddPodcast();
}
void MainWindow::FocusGlobalSearchField() {
ui_->tabs->SetCurrentWidget(global_search_view_);
global_search_view_->FocusSearchField();
}
void MainWindow::DoGlobalSearch(const QString& query) {
FocusGlobalSearchField();
global_search_view_->StartSearch(query);
}

View File

@ -248,6 +248,8 @@ class MainWindow : public QMainWindow, public PlatformInterface {
void HandleNotificationPreview(OSD::Behaviour type, QString line1, QString line2);
void ScrollToInternetIndex(const QModelIndex& index);
void FocusGlobalSearchField();
void DoGlobalSearch(const QString& query);
private:
void ConnectInfoView(SongInfoBase* view);