diff --git a/modules/gui/qt/maininterface/mainui.cpp b/modules/gui/qt/maininterface/mainui.cpp index 4487bb3ada8a1ea728c34e7aa1af4fd22a1d206a..fabe21af88a70a0dc9db30caca4d343a98c7c6b3 100644 --- a/modules/gui/qt/maininterface/mainui.cpp +++ b/modules/gui/qt/maininterface/mainui.cpp @@ -347,14 +347,6 @@ void MainUI::registerQMLTypes() registerAnonymousType<MLArtist>(uri, versionMajor); registerAnonymousType<MLAlbumTrack>(uri, versionMajor); - qmlRegisterType<AlbumContextMenu>( uri, versionMajor, versionMinor, "AlbumContextMenu" ); - qmlRegisterType<ArtistContextMenu>( uri, versionMajor, versionMinor, "ArtistContextMenu" ); - qmlRegisterType<GenreContextMenu>( uri, versionMajor, versionMinor, "GenreContextMenu" ); - qmlRegisterType<AlbumTrackContextMenu>( uri, versionMajor, versionMinor, "AlbumTrackContextMenu" ); - qmlRegisterType<URLContextMenu>( uri, versionMajor, versionMinor, "URLContextMenu" ); - qmlRegisterType<VideoContextMenu>( uri, versionMajor, versionMinor, "VideoContextMenu" ); - qmlRegisterType<VideoGroupsContextMenu>( uri, versionMajor, versionMinor, "VideoGroupsContextMenu" ); - qmlRegisterType<VideoFoldersContextMenu>( uri, versionMajor, versionMinor, "VideoFoldersContextMenu" ); qmlRegisterType<PlaylistListContextMenu>( uri, versionMajor, versionMinor, "PlaylistListContextMenu" ); qmlRegisterType<PlaylistMediaContextMenu>( uri, versionMajor, versionMinor, "PlaylistMediaContextMenu" ); diff --git a/modules/gui/qt/menus/qml_menu_wrapper.cpp b/modules/gui/qt/menus/qml_menu_wrapper.cpp index 3adfe455c7d41a2398402413b37101fa20802e64..448693b62298eac83c6e9eacbf3baeaad85b3ee5 100644 --- a/modules/gui/qt/menus/qml_menu_wrapper.cpp +++ b/modules/gui/qt/menus/qml_menu_wrapper.cpp @@ -18,16 +18,8 @@ #include "qml_menu_wrapper.hpp" #include "menus.hpp" #include "medialibrary/medialib.hpp" -#include "medialibrary/mlvideomodel.hpp" -#include "medialibrary/mlvideogroupsmodel.hpp" -#include "medialibrary/mlvideofoldersmodel.hpp" #include "medialibrary/mlplaylistlistmodel.hpp" #include "medialibrary/mlplaylistmodel.hpp" -#include "medialibrary/mlalbummodel.hpp" -#include "medialibrary/mlartistmodel.hpp" -#include "medialibrary/mlgenremodel.hpp" -#include "medialibrary/mlalbumtrackmodel.hpp" -#include "medialibrary/mlurlmodel.hpp" #include "medialibrary/mlbookmarkmodel.hpp" #include "network/networkdevicemodel.hpp" #include "network/networkmediamodel.hpp" @@ -36,6 +28,7 @@ #include "dialogs/dialogs_provider.hpp" // Qt includes +#include <QPainter> #include <QSignalMapper> #include <QScreen> @@ -589,275 +582,6 @@ void QmlAudioMenu::beforePopup(QMenu * menu) /* override */ }); } -BaseMedialibMenu::BaseMedialibMenu(QObject* parent) - : QObject(parent) -{} - -void BaseMedialibMenu::medialibAudioContextMenu(MediaLib* ml, const QVariantList& mlId, const QPoint& pos, const QVariantMap& options) -{ - m_menu = std::make_unique<QMenu>(); - QAction* action; - - action = m_menu->addAction( qtr("Add and play") ); - connect(action, &QAction::triggered, [ml, mlId]( ) { - ml->addAndPlay(mlId); - }); - - action = m_menu->addAction( qtr("Enqueue") ); - connect(action, &QAction::triggered, [ml, mlId]( ) { - ml->addToPlaylist(mlId); - }); - - action = m_menu->addAction( qtr("Add to playlist") ); - connect(action, &QAction::triggered, [mlId]( ) { - DialogsProvider::getInstance()->playlistsDialog(mlId); - }); - - if (options.contains("information") && options["information"].type() == QVariant::Int) { - - action = m_menu->addAction( qtr("Information") ); - QSignalMapper* sigmapper = new QSignalMapper(m_menu.get()); - connect(action, &QAction::triggered, sigmapper, QOverload<>::of(&QSignalMapper::map)); - sigmapper->setMapping(action, options["information"].toInt()); - connect(sigmapper, QSIGNALMAPPER_MAPPEDINT_SIGNAL, - this, &BaseMedialibMenu::showMediaInformation); - } - m_menu->popup(pos); -} - -AlbumContextMenu::AlbumContextMenu(QObject* parent) - : BaseMedialibMenu(parent) -{} - -void AlbumContextMenu::popup(const QModelIndexList& selected, QPoint pos, QVariantMap options) -{ - BaseMedialibMenu::popup(m_model, MLAlbumModel::ALBUM_ID, selected, pos, options); -} - - -ArtistContextMenu::ArtistContextMenu(QObject* parent) - : BaseMedialibMenu(parent) -{} - -void ArtistContextMenu::popup(const QModelIndexList &selected, QPoint pos, QVariantMap options) -{ - BaseMedialibMenu::popup(m_model, MLArtistModel::ARTIST_ID, selected, pos, options); -} - -GenreContextMenu::GenreContextMenu(QObject* parent) - : BaseMedialibMenu(parent) -{} - -void GenreContextMenu::popup(const QModelIndexList& selected, QPoint pos, QVariantMap options) -{ - BaseMedialibMenu::popup(m_model, MLGenreModel::GENRE_ID, selected, pos, options); -} - -AlbumTrackContextMenu::AlbumTrackContextMenu(QObject* parent) - : BaseMedialibMenu(parent) -{} - -void AlbumTrackContextMenu::popup(const QModelIndexList &selected, QPoint pos, QVariantMap options) -{ - BaseMedialibMenu::popup(m_model, MLAlbumTrackModel::TRACK_ID, selected, pos, options); -} - -URLContextMenu::URLContextMenu(QObject* parent) - : BaseMedialibMenu(parent) -{} - -void URLContextMenu::popup(const QModelIndexList &selected, QPoint pos, QVariantMap options) -{ - BaseMedialibMenu::popup(m_model, MLUrlModel::URL_ID, selected, pos, options); -} - - -VideoContextMenu::VideoContextMenu(QObject* parent) - : QObject(parent) -{} - - -void VideoContextMenu::popup(const QModelIndexList& selected, QPoint pos, QVariantMap options) -{ - if (!m_model) - return; - - m_menu = std::make_unique<QMenu>(); - QAction* action; - - MediaLib* ml= m_model->ml(); - - QVariantList itemIdList; - for (const QModelIndex& modelIndex : selected) - itemIdList.push_back(m_model->data(modelIndex, MLVideoModel::VIDEO_ID)); - - action = m_menu->addAction( qtr("Add and play") ); - - connect(action, &QAction::triggered, [ml, itemIdList, options]( ) { - ml->addAndPlay(itemIdList, options["player-options"].toStringList()); - }); - - action = m_menu->addAction( qtr("Enqueue") ); - connect(action, &QAction::triggered, [ml, itemIdList]( ) { - ml->addToPlaylist(itemIdList); - }); - - action = m_menu->addAction( qtr("Add to playlist") ); - connect(action, &QAction::triggered, [itemIdList]( ) { - DialogsProvider::getInstance()->playlistsDialog(itemIdList); - }); - - action = m_menu->addAction( qtr("Play as audio") ); - connect(action, &QAction::triggered, [ml, itemIdList, options]( ) { - QStringList list = options["player-options"].toStringList(); - list.prepend(":no-video"); - ml->addAndPlay(itemIdList, list); - }); - - if (options.contains("information") && options["information"].type() == QVariant::Int) { - action = m_menu->addAction( qtr("Information") ); - QSignalMapper* sigmapper = new QSignalMapper(m_menu.get()); - connect(action, &QAction::triggered, sigmapper, QOverload<>::of(&QSignalMapper::map)); - sigmapper->setMapping(action, options["information"].toInt()); - connect(sigmapper, QSIGNALMAPPER_MAPPEDINT_SIGNAL, - this, &VideoContextMenu::showMediaInformation); - } - - m_menu->popup(pos); -} - -//================================================================================================= -// VideoGroupsContextMenu -//================================================================================================= - -VideoGroupsContextMenu::VideoGroupsContextMenu(QObject * parent) : QObject(parent) {} - -void VideoGroupsContextMenu::popup(const QModelIndexList & selected, QPoint pos, - QVariantMap options) -{ - if (m_model == nullptr) - return; - - QVariantList ids; - - for (const QModelIndex & index : selected) - ids.push_back(m_model->data(index, MLVideoModel::VIDEO_ID)); - - m_menu = std::make_unique<QMenu>(); - - MediaLib * ml = m_model->ml(); - - QAction * action = m_menu->addAction(qtr("Add and play")); - - connect(action, &QAction::triggered, [ml, ids, options]() - { - ml->addAndPlay(ids, options["player-options"].toStringList()); - }); - - action = m_menu->addAction(qtr("Enqueue")); - - connect(action, &QAction::triggered, [ml, ids]() - { - ml->addToPlaylist(ids); - }); - - action = m_menu->addAction(qtr("Add to playlist")); - - connect(action, &QAction::triggered, [ids]() - { - DialogsProvider::getInstance()->playlistsDialog(ids); - }); - - action = m_menu->addAction(qtr("Play as audio")); - - connect(action, &QAction::triggered, [ml, ids, options]() - { - QStringList list = options["player-options"].toStringList(); - - list.prepend(":no-video"); - - ml->addAndPlay(ids, list); - }); - - // NOTE: At the moment informations are only available for single video(s). - if (selected.count() == 1 - && - m_model->data(selected.first(), MLVideoGroupsModel::GROUP_IS_VIDEO) == true - && - options.contains("information") && options["information"].type() == QVariant::Int) - { - action = m_menu->addAction(qtr("Information")); - - QSignalMapper * mapper = new QSignalMapper(m_menu.get()); - - mapper->setMapping(action, options["information"].toInt()); - - connect(action, &QAction::triggered, mapper, QOverload<>::of(&QSignalMapper::map)); - - connect(mapper, QSIGNALMAPPER_MAPPEDINT_SIGNAL, - this, &VideoGroupsContextMenu::showMediaInformation); - } - - m_menu->popup(pos); -} - -// VideoFoldersContextMenu - -VideoFoldersContextMenu::VideoFoldersContextMenu(QObject * parent) - : QObject(parent) -{} - - -void VideoFoldersContextMenu::popup(const QModelIndexList & selected, QPoint pos, - QVariantMap options) -{ - if (m_model == nullptr) - return; - - QVariantList ids; - - for (const QModelIndex & index : selected) - ids.push_back(m_model->data(index, MLVideoFoldersModel::FOLDER_ID)); - - m_menu = std::make_unique<QMenu>(); - - MediaLib * ml = m_model->ml(); - - QAction * action = m_menu->addAction(qtr("Add and play")); - - connect(action, &QAction::triggered, [ml, ids, options]() - { - ml->addAndPlay(ids, options["player-options"].toStringList()); - }); - - action = m_menu->addAction(qtr("Enqueue")); - - connect(action, &QAction::triggered, [ml, ids]() - { - ml->addToPlaylist(ids); - }); - - action = m_menu->addAction(qtr("Add to playlist")); - - connect(action, &QAction::triggered, [ids]() - { - DialogsProvider::getInstance()->playlistsDialog(ids); - }); - - action = m_menu->addAction(qtr("Play as audio")); - - connect(action, &QAction::triggered, [ml, ids, options]() - { - QStringList list = options["player-options"].toStringList(); - - list.prepend(":no-video"); - - ml->addAndPlay(ids, list); - }); - - m_menu->popup(pos); -} - //================================================================================================= // PlaylistListContextMenu //================================================================================================= diff --git a/modules/gui/qt/menus/qml_menu_wrapper.hpp b/modules/gui/qt/menus/qml_menu_wrapper.hpp index 64f9cfd65a4cae8b5dbce02036b22aa292676fb2..8020bd6e7ed472fbfe1d98789e2d3525a9225864 100644 --- a/modules/gui/qt/menus/qml_menu_wrapper.hpp +++ b/modules/gui/qt/menus/qml_menu_wrapper.hpp @@ -27,14 +27,6 @@ #include "maininterface/mainctx.hpp" class MediaLib; -class MLAlbumModel; -class MLGenreModel; -class MLArtistModel; -class MLAlbumTrackModel; -class MLUrlModel; -class MLVideoModel; -class MLVideoGroupsModel; -class MLVideoFoldersModel; class MLPlaylistListModel; class MLPlaylistModel; class NetworkDeviceModel; @@ -293,143 +285,6 @@ protected: // QmlTrackMenu implementation void beforePopup(QMenu * menu) override; }; -class BaseMedialibMenu : public QObject -{ - Q_OBJECT -public: - BaseMedialibMenu(QObject* parent = nullptr); -signals: - void showMediaInformation(int index); - -protected: - void medialibAudioContextMenu(MediaLib* ml, const QVariantList& mlId, const QPoint& pos, const QVariantMap& options); - - template<typename ModelType> - void popup(ModelType* model, typename ModelType::Roles role, const QModelIndexList &selected, const QPoint& pos, const QVariantMap& options) { - if (!model) - return; - - MediaLib* ml= model->ml(); - if (!ml) - return; - - QVariantList itemIdList; - for (const QModelIndex& modelIndex : selected) - itemIdList.push_back(model->data(modelIndex, role)); - medialibAudioContextMenu(ml, itemIdList, pos, options); - } - -private: - std::unique_ptr<QMenu> m_menu; -}; - -class AlbumContextMenu : public BaseMedialibMenu { - Q_OBJECT - SIMPLE_MENU_PROPERTY(MLAlbumModel*, model, nullptr) -public: - AlbumContextMenu(QObject* parent = nullptr); -public slots: - void popup(const QModelIndexList& selected, QPoint pos, QVariantMap options = {}); -}; - - -class ArtistContextMenu : public BaseMedialibMenu { - Q_OBJECT - SIMPLE_MENU_PROPERTY(MLArtistModel*, model, nullptr) -public: - ArtistContextMenu(QObject* parent = nullptr); -public slots: - void popup(const QModelIndexList& selected, QPoint pos, QVariantMap options = {}); -}; - - -class GenreContextMenu : public BaseMedialibMenu { - Q_OBJECT - SIMPLE_MENU_PROPERTY(MLGenreModel*, model, nullptr) -public: - GenreContextMenu(QObject* parent = nullptr); -public slots: - void popup(const QModelIndexList& selected, QPoint pos, QVariantMap options = {}); -}; - - -class AlbumTrackContextMenu : public BaseMedialibMenu { - Q_OBJECT - SIMPLE_MENU_PROPERTY(MLAlbumTrackModel*, model, nullptr) -public: - AlbumTrackContextMenu(QObject* parent = nullptr); -public slots: - void popup(const QModelIndexList& selected, QPoint pos, QVariantMap options = {}); -}; - -class URLContextMenu : public BaseMedialibMenu { - Q_OBJECT - SIMPLE_MENU_PROPERTY(MLUrlModel*, model, nullptr) -public: - URLContextMenu(QObject* parent = nullptr); -public slots: - void popup(const QModelIndexList& selected, QPoint pos, QVariantMap options = {}); -}; - -class VideoContextMenu : public QObject { - Q_OBJECT - SIMPLE_MENU_PROPERTY(MLVideoModel*, model, nullptr) -public: - VideoContextMenu(QObject* parent = nullptr); - -public slots: - void popup(const QModelIndexList& selected, QPoint pos, QVariantMap options = {} ); -signals: - void showMediaInformation(int index); -private: - std::unique_ptr<QMenu> m_menu; -}; - -//------------------------------------------------------------------------------------------------- -// Groups -//------------------------------------------------------------------------------------------------- - -class VideoGroupsContextMenu : public QObject { - Q_OBJECT - - SIMPLE_MENU_PROPERTY(MLVideoGroupsModel *, model, nullptr) - -public: - VideoGroupsContextMenu(QObject * parent = nullptr); - -public slots: - void popup(const QModelIndexList & selected, QPoint pos, QVariantMap options = {}); - -signals: - void showMediaInformation(int index); - -private: - std::unique_ptr<QMenu> m_menu; -}; - -// Folders - -class VideoFoldersContextMenu : public QObject { - Q_OBJECT - - SIMPLE_MENU_PROPERTY(MLVideoFoldersModel *, model, nullptr) - -public: - VideoFoldersContextMenu(QObject * parent = nullptr); - -public slots: - void popup(const QModelIndexList & selected, QPoint pos, QVariantMap options = {}); - -signals: - // FIXME: This signal is required for VideoAll Connections. - void showMediaInformation(int index); - -private: - std::unique_ptr<QMenu> m_menu; -}; - -//------------------------------------------------------------------------------------------------- - class PlaylistListContextMenu : public QObject { Q_OBJECT SIMPLE_MENU_PROPERTY(MLPlaylistListModel *, model, nullptr)