From 4c819b1cb92edd45a0474f012a99ab18bea2b59c Mon Sep 17 00:00:00 2001 From: David Sansome Date: Tue, 27 Sep 2011 22:38:14 +0100 Subject: [PATCH] Add a "Replace and play now" shortcut to the global search menu. --- src/globalsearch/globalsearchwidget.cpp | 34 +++++++++++++++++-------- src/globalsearch/globalsearchwidget.h | 2 ++ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/globalsearch/globalsearchwidget.cpp b/src/globalsearch/globalsearchwidget.cpp index 7ec3be84c..1e861c2d9 100644 --- a/src/globalsearch/globalsearchwidget.cpp +++ b/src/globalsearch/globalsearchwidget.cpp @@ -79,22 +79,26 @@ GlobalSearchWidget::GlobalSearchWidget(QWidget* parent) ui_->search->installEventFilter(this); // Actions - add_ = new QAction(tr("Add to playlist"), this); - add_and_play_ = new QAction(tr("Add and play now"), this); - add_and_queue_ = new QAction(tr("Queue track"), this); - replace_ = new QAction(tr("Replace current playlist"), this); + add_ = new QAction(tr("Add to playlist"), this); + add_and_play_ = new QAction(tr("Add and play now"), this); + add_and_queue_ = new QAction(tr("Queue track"), this); + replace_ = new QAction(tr("Replace current playlist"), this); + replace_and_play_ = new QAction(tr("Replace and play now"), this); add_->setShortcut(QKeySequence(Qt::Key_Return)); add_and_play_->setShortcut(QKeySequence(Qt::CTRL | Qt::Key_Return)); add_and_queue_->setShortcut(QKeySequence(Qt::SHIFT | Qt::Key_Return)); replace_->setShortcut(QKeySequence(Qt::ALT | Qt::Key_Return)); + replace_and_play_->setShortcut(QKeySequence(Qt::ALT | Qt::CTRL | Qt::Key_Return)); - connect(add_, SIGNAL(triggered()), SLOT(AddCurrent())); - connect(add_and_play_, SIGNAL(triggered()), SLOT(AddAndPlayCurrent())); - connect(add_and_queue_, SIGNAL(triggered()), SLOT(AddAndQueueCurrent())); - connect(replace_, SIGNAL(triggered()), SLOT(ReplaceCurrent())); + connect(add_, SIGNAL(triggered()), SLOT(AddCurrent())); + connect(add_and_play_, SIGNAL(triggered()), SLOT(AddAndPlayCurrent())); + connect(add_and_queue_, SIGNAL(triggered()), SLOT(AddAndQueueCurrent())); + connect(replace_, SIGNAL(triggered()), SLOT(ReplaceCurrent())); + connect(replace_and_play_, SIGNAL(triggered()), SLOT(ReplaceAndPlayCurrent())); - actions_ << add_ << add_and_play_ << add_and_queue_ << replace_; + actions_ << add_ << add_and_play_ << add_and_queue_ << replace_ + << replace_and_play_; // Load style sheets StyleSheetLoader* style_loader = new StyleSheetLoader(this); @@ -391,7 +395,9 @@ bool GlobalSearchWidget::EventFilterPopup(QObject*, QEvent* e) { case Qt::Key_Return: case Qt::Key_Enter: // Handle the QActions here - they don't activate when the tooltip is showing - if (ke->modifiers() & Qt::AltModifier) + if (ke->modifiers() & Qt::AltModifier && ke->modifiers() & Qt::ControlModifier) + replace_and_play_->trigger(); + else if (ke->modifiers() & Qt::AltModifier) replace_->trigger(); else if (ke->modifiers() & Qt::ControlModifier) add_and_play_->trigger(); @@ -481,6 +487,10 @@ void GlobalSearchWidget::ReplaceCurrent() { LoadTracks(replace_); } +void GlobalSearchWidget::ReplaceAndPlayCurrent() { + LoadTracks(replace_and_play_); +} + void GlobalSearchWidget::LoadTracks(QAction* trigger) { QModelIndex index = view_->currentIndex(); if (!index.isValid()) @@ -523,6 +533,10 @@ void GlobalSearchWidget::TracksLoaded(int id, MimeData* mime_data) { mime_data->enqueue_now_ = true; } else if (trigger == replace_) { mime_data->clear_first_= true; + } else if (trigger == replace_and_play_) { + mime_data->clear_first_ = true; + mime_data->override_user_settings_ = true; + mime_data->play_now_ = true; } } diff --git a/src/globalsearch/globalsearchwidget.h b/src/globalsearch/globalsearchwidget.h index 18082bccb..c355a6d05 100644 --- a/src/globalsearch/globalsearchwidget.h +++ b/src/globalsearch/globalsearchwidget.h @@ -85,6 +85,7 @@ private slots: void AddAndPlayCurrent(); void AddAndQueueCurrent(); void ReplaceCurrent(); + void ReplaceAndPlayCurrent(); void HidePopup(); void UpdateTooltip(); @@ -136,6 +137,7 @@ private: QAction* add_and_play_; QAction* add_and_queue_; QAction* replace_; + QAction* replace_and_play_; QList actions_; };