Only show track actions if we have a selection

This commit is contained in:
craig.p.drummond
2014-08-22 15:48:07 +00:00
parent 92bf9eb257
commit aaca967af5
3 changed files with 61 additions and 21 deletions

View File

@@ -42,6 +42,7 @@
#include <QFile>
#include <QPainter>
#include <QApplication>
#include <QMenu>
#include <qglobal.h>
// Exported by QtGui
@@ -127,6 +128,8 @@ void PlayQueueGroupedView::paintEvent(QPaintEvent *e)
PlayQueueView::PlayQueueView(QWidget *parent)
: QStackedWidget(parent)
, contextMenu(0)
, selectContextMenu(0)
, mode(ItemView::Mode_Count)
, groupedView(0)
, treeView(0)
@@ -215,23 +218,25 @@ void PlayQueueView::setMode(ItemView::Mode m)
groupedView->setIndentation(0);
groupedView->setItemsExpandable(false);
groupedView->setExpandsOnDoubleClick(false);
groupedView->setContextMenuPolicy(Qt::ActionsContextMenu);
groupedView->setContextMenuPolicy(Qt::CustomContextMenu);
groupedView->installFilter(new KeyEventHandler(groupedView, removeFromAction));
addWidget(groupedView);
connect(groupedView, SIGNAL(itemsSelected(bool)), SIGNAL(itemsSelected(bool)));
connect(groupedView, SIGNAL(doubleClicked(const QModelIndex &)), SIGNAL(doubleClicked(const QModelIndex &)));
connect(groupedView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showMenu(QPoint)));
updatePalette();
}
break;
case ItemView::Mode_Table:
if (!treeView) {
treeView=new PlayQueueTreeView(this);
treeView->setContextMenuPolicy(Qt::ActionsContextMenu);
treeView->setContextMenuPolicy(Qt::CustomContextMenu);
treeView->installFilter(new KeyEventHandler(treeView, removeFromAction));
treeView->initHeader();
addWidget(treeView);
connect(treeView, SIGNAL(itemsSelected(bool)), SIGNAL(itemsSelected(bool)));
connect(treeView, SIGNAL(doubleClicked(const QModelIndex &)), SIGNAL(doubleClicked(const QModelIndex &)));
connect(treeView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showMenu(QPoint)));
updatePalette();
}
default:
@@ -314,9 +319,28 @@ QModelIndex PlayQueueView::indexAt(const QPoint &point)
return view()->indexAt(point);
}
void PlayQueueView::addAction(QAction *a)
void PlayQueueView::addAction(QAction *a, bool withSelectionOnly)
{
view()->addAction(a);
if (!contextMenu) {
contextMenu=new QMenu(this);
}
if (!selectContextMenu) {
selectContextMenu=new QMenu(this);
}
if (!withSelectionOnly) {
contextMenu->addAction(a);
}
selectContextMenu->addAction(a);
}
void PlayQueueView::addSeparator()
{
if (contextMenu) {
contextMenu->addSeparator();
}
if (selectContextMenu) {
selectContextMenu->addSeparator();
}
}
void PlayQueueView::setFocus()
@@ -488,6 +512,15 @@ void PlayQueueView::streamFetchStatus(const QString &msg)
msgOverlay->setText(msg);
}
void PlayQueueView::showMenu(const QPoint &p)
{
if (haveSelectedItems()) {
selectContextMenu->popup(view()->mapToGlobal(p));
} else {
contextMenu->popup(view()->mapToGlobal(p));
}
}
void PlayQueueView::drawBackdrop(QWidget *widget, const QSize &size)
{
if (BI_None==backgroundImageType) {