From 15fd5112de543e0268d7093b8f6ad02e8f2f42fb Mon Sep 17 00:00:00 2001 From: "Gary R. Van Sickle" Date: Fri, 15 Dec 2017 00:06:35 -0600 Subject: [PATCH] Initial commit of MDINowPlayingView. Hooked up and working. --- CMakeLists.txt | 2 +- gui/MDINowPlayingView.cpp | 25 +++++++++++++++++++ gui/MDINowPlayingView.h | 35 +++++++++++++++++++++++++++ gui/MDIPlaylistView.h | 4 +++ gui/MDITreeViewBase.h | 9 +++++++ gui/MainWindow.cpp | 51 +++++++++++++++++++++++++++++---------- gui/MainWindow.h | 2 ++ 7 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 gui/MDINowPlayingView.cpp create mode 100644 gui/MDINowPlayingView.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 69e08e45..158b2d30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -323,7 +323,7 @@ set(SOURCE_FILES gui/settings/SettingsDialog.cpp gui/settings/SettingsDialogPageBase.cpp gui/settings/SettingsDialogPageBase.h gui/settings/SDPageAppearance.cpp gui/settings/SDPageAppearance.h - gui/settings/SettingsDialogSideWidget.cpp gui/settings/SDPageLibrary.cpp gui/settings/SDPageLibrary.h) + gui/settings/SettingsDialogSideWidget.cpp gui/settings/SDPageLibrary.cpp gui/settings/SDPageLibrary.h gui/MDINowPlayingView.cpp gui/MDINowPlayingView.h) # This function sets up the variable META_FILES_TO_INCLUDE to the extra files # needed for a windows build (essentially just the configured .rc file). diff --git a/gui/MDINowPlayingView.cpp b/gui/MDINowPlayingView.cpp new file mode 100644 index 00000000..ed79a97c --- /dev/null +++ b/gui/MDINowPlayingView.cpp @@ -0,0 +1,25 @@ +/* + * Copyright 2017 Gary R. Van Sickle (grvs@users.sourceforge.net). + * + * This file is part of AwesomeMediaLibraryManager. + * + * AwesomeMediaLibraryManager is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AwesomeMediaLibraryManager is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AwesomeMediaLibraryManager. If not, see . + */ + +#include "MDINowPlayingView.h" + +MDINowPlayingView::MDINowPlayingView(QWidget *parent) : MDIPlaylistView(parent) +{ + +} diff --git a/gui/MDINowPlayingView.h b/gui/MDINowPlayingView.h new file mode 100644 index 00000000..933c5b6a --- /dev/null +++ b/gui/MDINowPlayingView.h @@ -0,0 +1,35 @@ +/* + * Copyright 2017 Gary R. Van Sickle (grvs@users.sourceforge.net). + * + * This file is part of AwesomeMediaLibraryManager. + * + * AwesomeMediaLibraryManager is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * AwesomeMediaLibraryManager is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with AwesomeMediaLibraryManager. If not, see . + */ + +#ifndef AWESOMEMEDIALIBRARYMANAGER_MDINOWPLAYINGVIEW_H +#define AWESOMEMEDIALIBRARYMANAGER_MDINOWPLAYINGVIEW_H + + +#include "MDIPlaylistView.h" + +class MDINowPlayingView : public MDIPlaylistView +{ + Q_OBJECT + +public: + MDINowPlayingView(QWidget *parent); +}; + + +#endif //AWESOMEMEDIALIBRARYMANAGER_MDINOWPLAYINGVIEW_H diff --git a/gui/MDIPlaylistView.h b/gui/MDIPlaylistView.h index 07792128..8cb9a58a 100644 --- a/gui/MDIPlaylistView.h +++ b/gui/MDIPlaylistView.h @@ -50,6 +50,10 @@ public slots: void next(); void previous(); + /** + * Slot which appends the incoming library entry and starts playing it. + * Intended for use primarily on the single "Now Playing" playlist. + */ void onSendToNowPlaying(std::shared_ptr); protected: diff --git a/gui/MDITreeViewBase.h b/gui/MDITreeViewBase.h index 2f22ded6..0786ed38 100644 --- a/gui/MDITreeViewBase.h +++ b/gui/MDITreeViewBase.h @@ -45,7 +45,10 @@ class MDITreeViewBase : public QTreeView bool saveAs(); bool saveFile(QUrl save_url, QString filter); + /// Returns the current basename of this window's backing file. QString userFriendlyCurrentFile() const; + + /// Returns the full URL of this window's backing file. QUrl getCurrentUrl() const; protected: @@ -55,6 +58,7 @@ class MDITreeViewBase : public QTreeView bool m_isUntitled = true; /// Protected function which is used to set the view's filename properties on a save or load. + /// Called by loadFile() and saveFile(). void setCurrentFile(QUrl url); virtual void closeEvent(QCloseEvent* event) override; @@ -99,6 +103,11 @@ protected slots: /// Return True if you handle it, False if you don't. virtual bool onBlankAreaToolTip(QHelpEvent* event); + /** + * Called by closeEvent(). If document shows as modified, pops up a "Do you want to save?" box, + * then calls save() or not depending on the user's choice. + * @return false if file was modified and user cancelled, true otherwise. + */ virtual bool maybeSave(); /** diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 81bb78d2..5a5111ee 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -459,6 +459,9 @@ void MainWindow::connectLibraryViewAndMainWindow(MDILibraryView *lv) void MainWindow::connectNowPlayingViewAndMainWindow(MDIPlaylistView* plv) { connect(this, &MainWindow::sendToNowPlaying, plv, &MDIPlaylistView::onSendToNowPlaying); + + connectPlayerAndPlaylistView(&m_player, plv); + connectPlayerControlsAndPlaylistView(m_controls, plv); } void MainWindow::updateConnections() @@ -473,26 +476,23 @@ void MainWindow::updateConnections() if(childIsLibrary != nullptr) { auto connection_handle = connect(activeMdiChild()->selectionModel(), &QItemSelectionModel::selectionChanged, - m_metadataDockWidget, &MetadataDockWidget::playlistSelectionChanged, - Qt::ConnectionType(Qt::AutoConnection | Qt::UniqueConnection)); - if(!connection_handle) + m_metadataDockWidget, &MetadataDockWidget::playlistSelectionChanged, + Qt::ConnectionType(Qt::AutoConnection | Qt::UniqueConnection)); + if (!connection_handle) { qDebug() << "Connection failed: already connected?"; } - connection_handle = connect(childIsLibrary, &MDILibraryView::playTrackNowSignal, - this, &MainWindow::onPlayTrackNowSignal, Qt::ConnectionType(Qt::AutoConnection | Qt::UniqueConnection)); - if(!connection_handle) + connection_handle = connect(childIsLibrary, + &MDILibraryView::playTrackNowSignal, + this, + &MainWindow::onPlayTrackNowSignal, + Qt::ConnectionType(Qt::AutoConnection | Qt::UniqueConnection)); + if (!connection_handle) { qDebug() << "Connection failed: already connected?"; } } - - if(childIsPlaylist != nullptr) - { - connectPlayerAndPlaylistView(&m_player, childIsPlaylist); - connectPlayerControlsAndPlaylistView(m_controls, childIsPlaylist); - } } } @@ -779,7 +779,7 @@ void MainWindow::onStartup() changeIconTheme(QIcon::themeName()); // Create the "Now Playing" playlist. - auto wins = createMdiChildPlaylist(); + auto wins = createMdiNowPlayingView(); m_now_playing_playlist_view = wins.first; QMdiSubWindow* mdisubwindow = wins.second; @@ -1031,6 +1031,31 @@ std::pair MainWindow::createMdiChildPlaylist() return std::make_pair(child, mdisubwindow); } +std::pair MainWindow::createMdiNowPlayingView() +{ + // Create a new "Now Playing" playlist model. + auto new_playlist_model = new PlaylistModel(this); + + // TODO REMOVE + m_playlist_models.push_back(new_playlist_model); + m_now_playing_playlist_model = new_playlist_model; + + MDINowPlayingView* child = new MDINowPlayingView(this); + child->setModel(new_playlist_model); + auto mdisubwindow = m_mdi_area->addSubWindow(child); + + // child.undoAvailable.connect(editUndoAct.setEnabled) + // child.redoAvailable.connect(redoAct.setEnabled) + // child.copyAvailable.connect(cutAct.setEnabled) + // child.copyAvailable.connect(copyAct.setEnabled) + + // Connect signals. + //child.cursorPositionChanged.connect(cursorPosChanged) + + // Add the new playlist to the collection doc widget. + m_libraryDockWidget->addPlaylist(new PlaylistItem(child)); + return std::make_pair(child, mdisubwindow); +} // Top-level "saveAs" action handler for "Save playlist as..." void MainWindow::savePlaylistAs() diff --git a/gui/MainWindow.h b/gui/MainWindow.h index 1146cfc8..b3154e55 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -22,6 +22,7 @@ #include "MDIPlaylistView.h" #include "MDITreeViewBase.h" #include "PlayerControls.h" +#include "MDINowPlayingView.h" #include #include @@ -144,6 +145,7 @@ private slots: MDITreeViewBase* activeMdiChild(); QMdiSubWindow* findSubWindow(QUrl url); std::pair createMdiChildPlaylist(); + std::pair createMdiNowPlayingView(); QSharedPointer openLibraryModelOnUrl(QUrl url); void openMDILibraryViewOnModel(LibraryModel* libmodel);