Qt: add right-click menu to delete playlist items

This commit is contained in:
Brad Parker 2018-07-28 22:34:00 -04:00
parent 978edc7acf
commit fea09f7382
6 changed files with 67 additions and 17 deletions

View File

@ -3666,3 +3666,5 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST_ITEM,
"「%1」というアイテムを削除しますか")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_CANNOT_ADD_TO_ALL_PLAYLISTS,
"まずひとつのプレイリストを選択してください。")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DELETE,
"削除")

View File

@ -4176,3 +4176,5 @@ MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_CONFIRM_DELETE_PLAYLIST_ITEM,
"Are you sure you want to delete the item \"%1\"?")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_CANNOT_ADD_TO_ALL_PLAYLISTS,
"Please choose a single playlist first.")
MSG_HASH(MENU_ENUM_LABEL_VALUE_QT_DELETE,
"Delete")

View File

@ -1949,6 +1949,7 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_QT_PLAYLIST_ENTRY_DATABASE,
MENU_ENUM_LABEL_VALUE_QT_FOR_THUMBNAILS,
MENU_ENUM_LABEL_VALUE_QT_CANNOT_ADD_TO_ALL_PLAYLISTS,
MENU_ENUM_LABEL_VALUE_QT_DELETE,
MENU_LABEL(MIDI_INPUT),
MENU_LABEL(MIDI_OUTPUT),

View File

@ -991,6 +991,7 @@ MainWindow::MainWindow(QWidget *parent) :
m_dirTree->setContextMenuPolicy(Qt::CustomContextMenu);
m_listWidget->setContextMenuPolicy(Qt::CustomContextMenu);
m_gridLayoutWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_searchLineEdit, SIGNAL(returnPressed()), this, SLOT(onSearchEnterPressed()));
connect(m_searchLineEdit, SIGNAL(textEdited(const QString&)), this, SLOT(onSearchLineEditEdited(const QString&)));
@ -1014,6 +1015,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(viewTypeIconsAction, SIGNAL(triggered()), this, SLOT(onIconViewClicked()));
connect(viewTypeListAction, SIGNAL(triggered()), this, SLOT(onListViewClicked()));
connect(m_gridLayoutWidget, SIGNAL(filesDropped(QStringList)), this, SLOT(onPlaylistFilesDropped(QStringList)));
connect(m_gridLayoutWidget, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onFileDropWidgetContextMenuRequested(const QPoint&)));
/* make sure these use an auto connection so it will be queued if called from a different thread (some facilities in RA log messages from other threads) */
connect(this, SIGNAL(gotLogMessage(const QString&)), this, SLOT(onGotLogMessage(const QString&)), Qt::AutoConnection);
@ -1444,6 +1446,30 @@ bool MainWindow::showMessageBox(QString msg, MessageBoxType msgType, Qt::WindowM
return true;
}
void MainWindow::onFileDropWidgetContextMenuRequested(const QPoint &pos)
{
QScopedPointer<QMenu> menu;
QScopedPointer<QAction> deleteAction;
QPointer<QAction> selectedAction;
QPoint cursorPos = QCursor::pos();
menu.reset(new QMenu(this));
deleteAction.reset(new QAction(QString(msg_hash_to_str(MENU_ENUM_LABEL_VALUE_QT_DELETE)), this));
menu->addAction(deleteAction.data());
selectedAction = menu->exec(cursorPos);
if (!selectedAction)
return;
if (selectedAction == deleteAction.data())
{
deleteCurrentPlaylistItem();
}
}
void MainWindow::onPlaylistWidgetContextMenuRequested(const QPoint&)
{
settings_t *settings = config_get_ptr();
@ -2408,37 +2434,51 @@ void MainWindow::onTableWidgetDeletePressed()
deleteCurrentPlaylistItem();
}
void MainWindow::deleteCurrentPlaylistItem()
QString MainWindow::getCurrentPlaylistPath()
{
QListWidgetItem *playlistItem = m_listWidget->currentItem();
QHash<QString, QString> contentHash;
QString playlistPath;
if (!playlistItem)
return playlistPath;
playlistPath = playlistItem->data(Qt::UserRole).toString();
return playlistPath;
}
QHash<QString, QString> MainWindow::getCurrentContentHash()
{
QTableWidgetItem *contentItem = m_tableWidget->currentItem();
QListWidgetItem *playlistItem = m_listWidget->currentItem();
QHash<QString, QString> contentHash;
QString playlistPath;
QByteArray playlistArray;
ViewType viewType = getCurrentViewType();
playlist_t *playlist = NULL;
const char *playlistData = NULL;
unsigned index = 0;
bool ok = false;
if (!playlistItem)
return;
playlistPath = playlistItem->data(Qt::UserRole).toString();
if (playlistPath.isEmpty())
return;
if (viewType == VIEW_TYPE_LIST)
{
if (!contentItem)
return;
return contentHash;
contentHash = contentItem->data(Qt::UserRole).value<QHash<QString, QString> >();
}
else if (viewType == VIEW_TYPE_ICONS)
contentHash = m_currentGridHash;
else
return contentHash;
}
void MainWindow::deleteCurrentPlaylistItem()
{
QString playlistPath = getCurrentPlaylistPath();
QByteArray playlistArray;
QHash<QString, QString> contentHash = getCurrentContentHash();
playlist_t *playlist = NULL;
const char *playlistData = NULL;
unsigned index = 0;
bool ok = false;
if (playlistPath.isEmpty())
return;
if (contentHash.isEmpty())

View File

@ -277,9 +277,11 @@ static void* ui_companion_qt_init(void)
widget = new FileDropWidget(mainwindow);
widget->setObjectName("tableWidget");
widget->setContextMenuPolicy(Qt::CustomContextMenu);
QObject::connect(widget, SIGNAL(filesDropped(QStringList)), mainwindow, SLOT(onPlaylistFilesDropped(QStringList)));
QObject::connect(widget, SIGNAL(deletePressed()), mainwindow, SLOT(deleteCurrentPlaylistItem()));
QObject::connect(widget, SIGNAL(customContextMenuRequested(const QPoint&)), mainwindow, SLOT(onFileDropWidgetContextMenuRequested(const QPoint&)));
layout = new QVBoxLayout();
layout->addWidget(mainwindow->contentTableWidget());

View File

@ -339,6 +339,8 @@ public:
void setAllPlaylistsGridMaxCount(int count);
PlaylistEntryDialog* playlistEntryDialog();
void addFilesToPlaylist(QStringList files);
QString getCurrentPlaylistPath();
QHash<QString, QString> getCurrentContentHash();
signals:
void thumbnailChanged(const QPixmap &pixmap);
@ -378,6 +380,7 @@ public slots:
void onListViewClicked();
void onTabWidgetIndexChanged(int index);
void deleteCurrentPlaylistItem();
void onFileDropWidgetContextMenuRequested(const QPoint &pos);
private slots:
void onLoadCoreClicked(const QStringList &extensionFilters = QStringList());