From fea09f73821b4244c74e0018c68f285f8edd9dfc Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Sat, 28 Jul 2018 22:34:00 -0400 Subject: [PATCH] Qt: add right-click menu to delete playlist items --- intl/msg_hash_ja.h | 2 + intl/msg_hash_us.h | 2 + msg_hash.h | 1 + ui/drivers/qt/ui_qt_window.cpp | 74 ++++++++++++++++++++++++++-------- ui/drivers/ui_qt.cpp | 2 + ui/drivers/ui_qt.h | 3 ++ 6 files changed, 67 insertions(+), 17 deletions(-) diff --git a/intl/msg_hash_ja.h b/intl/msg_hash_ja.h index 258976db24..db13fada11 100644 --- a/intl/msg_hash_ja.h +++ b/intl/msg_hash_ja.h @@ -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, + "削除") diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 09d0cb4ebe..0cb7e9c4e6 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -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") diff --git a/msg_hash.h b/msg_hash.h index d0ba76205e..e947239b99 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -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), diff --git a/ui/drivers/qt/ui_qt_window.cpp b/ui/drivers/qt/ui_qt_window.cpp index af33cb03aa..c35ef80bbf 100644 --- a/ui/drivers/qt/ui_qt_window.cpp +++ b/ui/drivers/qt/ui_qt_window.cpp @@ -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 menu; + QScopedPointer deleteAction; + QPointer 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 contentHash; + QString playlistPath; + + if (!playlistItem) + return playlistPath; + + playlistPath = playlistItem->data(Qt::UserRole).toString(); + + return playlistPath; +} + +QHash MainWindow::getCurrentContentHash() { QTableWidgetItem *contentItem = m_tableWidget->currentItem(); QListWidgetItem *playlistItem = m_listWidget->currentItem(); QHash 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 >(); } else if (viewType == VIEW_TYPE_ICONS) contentHash = m_currentGridHash; - else + + return contentHash; +} + +void MainWindow::deleteCurrentPlaylistItem() +{ + QString playlistPath = getCurrentPlaylistPath(); + QByteArray playlistArray; + QHash contentHash = getCurrentContentHash(); + playlist_t *playlist = NULL; + const char *playlistData = NULL; + unsigned index = 0; + bool ok = false; + + if (playlistPath.isEmpty()) return; if (contentHash.isEmpty()) diff --git a/ui/drivers/ui_qt.cpp b/ui/drivers/ui_qt.cpp index 150ad432ec..415e056fca 100644 --- a/ui/drivers/ui_qt.cpp +++ b/ui/drivers/ui_qt.cpp @@ -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()); diff --git a/ui/drivers/ui_qt.h b/ui/drivers/ui_qt.h index 3fcbb8a979..056066ce03 100644 --- a/ui/drivers/ui_qt.h +++ b/ui/drivers/ui_qt.h @@ -339,6 +339,8 @@ public: void setAllPlaylistsGridMaxCount(int count); PlaylistEntryDialog* playlistEntryDialog(); void addFilesToPlaylist(QStringList files); + QString getCurrentPlaylistPath(); + QHash 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());