diff --git a/src/Controller/Pages/PageController.hpp b/database/CryliaPlayerDB.sqlite3 similarity index 100% rename from src/Controller/Pages/PageController.hpp rename to database/CryliaPlayerDB.sqlite3 diff --git a/src/Controller/MusicPlayer/MusicPlayer.h b/src/Controller/MusicPlayer/MusicPlayer.h index d454801..c9d84a2 100644 --- a/src/Controller/MusicPlayer/MusicPlayer.h +++ b/src/Controller/MusicPlayer/MusicPlayer.h @@ -8,6 +8,7 @@ #include "../../core/SongQueue/SongQueue.h" #include "../../core/song/song.h" + class MusicPlayer : public QObject { Q_OBJECT public: @@ -17,7 +18,8 @@ class MusicPlayer : public QObject { } private: - MusicPlayer( ) : songQueue(new SongQueue( )), songHistory(new SongHistory( )) { } + MusicPlayer( ) : + songQueue(new SongQueue( )), songHistory(new SongHistory( )) { } // 0 no shuffle, 1 shuffling int shuffle = 0; diff --git a/src/Controller/PageManager/PageManager.cpp b/src/Controller/PageManager/PageManager.cpp new file mode 100644 index 0000000..83fa314 --- /dev/null +++ b/src/Controller/PageManager/PageManager.cpp @@ -0,0 +1,3 @@ +#include "PageManager.h" + +PageManager::~PageManager( ) { } diff --git a/src/Controller/PageManager/PageManager.h b/src/Controller/PageManager/PageManager.h new file mode 100644 index 0000000..40f88f7 --- /dev/null +++ b/src/Controller/PageManager/PageManager.h @@ -0,0 +1,30 @@ +#pragma once + +#include + +#include "../../View/Pages/Page.h" + +class PageManager : public QObject { + Q_OBJECT +public: + static PageManager& getInstance( ) { + static PageManager instance; + return instance; + } + +private: + PageManager( ) { } + + Page* activePage = nullptr; +public: + ~PageManager( ); + + PageManager(PageManager const&) = delete; + void operator=(PageManager const&) = delete; + + void SetActivePage(Page* page) { activePage = page; } + Page* GetActivePage( ) { return activePage; } + +signals: + void ActivePageChanged(Page* page); +}; diff --git a/src/View/MainWidget.cpp b/src/View/MainWidget.cpp index 834e972..af96df7 100644 --- a/src/View/MainWidget.cpp +++ b/src/View/MainWidget.cpp @@ -2,7 +2,6 @@ void MainWidget::setupMainWidget( ) { setContentsMargins(10, 10, 10, 10); - QOverlayout* ol = new QOverlayout(this); setLayout(ol); @@ -16,11 +15,13 @@ void MainWidget::setupMainWidget( ) { vbox2->addWidget(playlistNav); hbox->addLayout(vbox2); QHBoxLayout* stackedLayout = new QHBoxLayout( ); - stackedLayout->addWidget(homePage); stackedLayout->addWidget(playlistPage); + stackedLayout->addWidget(localFolderPage); + pageManager.GetActivePage( )->setVisible(true); playlistPage->setVisible(false); + localFolderPage->setVisible(false); hbox->addLayout(stackedLayout, 0); @@ -30,18 +31,24 @@ void MainWidget::setupMainWidget( ) { ol->addItem(hbox); ol->addItem(vbox); - connect(pageNav, &PageNavModule::SelectChanged, [this, stackedLayout](PageNavigator* pn) { - if (pn->GetText( ).toStdString( ) == "Home") { - //stackedLayout->setCurrentIndex(0); + connect(&pageManager, &PageManager::ActivePageChanged, [this, stackedLayout](Page* page) { + if (page->GetName( ) == "home") { stackedLayout->itemAt(0)->widget( )->setVisible(true); stackedLayout->itemAt(1)->widget( )->setVisible(false); + stackedLayout->itemAt(2)->widget( )->setVisible(false); } - else if (pn->GetText( ).toStdString( ) == "Playlist") { - //stackedLayout->setCurrentIndex(1); + else if (page->GetName( ) == "playlist") { stackedLayout->itemAt(0)->widget( )->setVisible(false); stackedLayout->itemAt(1)->widget( )->setVisible(true); + stackedLayout->itemAt(2)->widget( )->setVisible(false); + } + else if (page->GetName( ) == "localFolder") { + stackedLayout->itemAt(0)->widget( )->setVisible(false); + stackedLayout->itemAt(1)->widget( )->setVisible(false); + stackedLayout->itemAt(2)->widget( )->setVisible(true); } }); + } void MainWidget::PageChangedAction( ) { } @@ -51,7 +58,9 @@ MainWidget::MainWidget(QWidget* parent) pageNav(new PageNavModule(this)), playlistNav(new PlaylistNavModule(this)), playlistPage(new PlaylistPage(this)), - homePage(new HomePage(this)) { + homePage(new HomePage(this)), + localFolderPage(new LocalFolderPage(this)) { + pageManager.SetActivePage(homePage); setupMainWidget( ); } diff --git a/src/View/MainWidget.h b/src/View/MainWidget.h index de7d766..ec9fe25 100644 --- a/src/View/MainWidget.h +++ b/src/View/MainWidget.h @@ -11,6 +11,8 @@ #include "Modules/PlaylistNavModule/PlaylistNavModule.h" #include "Pages/Playlist/PlaylistPage.h" #include "Pages/Home/HomePage.h" +#include "Pages/LocalFolder/LocalFolderPage.h" +#include "../Controller/PageManager/PageManager.h" class MainWidget : public QWidget { Q_OBJECT @@ -21,14 +23,17 @@ class MainWidget : public QWidget { PlaylistPage* playlistPage; HomePage* homePage; + LocalFolderPage* localFolderPage; FloatingControls* floatingControlls; + PageManager& pageManager = PageManager::getInstance( ); + void setupMainWidget( ); public: MainWidget(QWidget* parent = nullptr); - MainWidget(std::filesystem::path path, QWidget* parent = nullptr); + //MainWidget(std::filesystem::path path, QWidget* parent = nullptr); ~MainWidget( ); private slots: diff --git a/src/View/Modules/PageNavModule/PageNavModule.cpp b/src/View/Modules/PageNavModule/PageNavModule.cpp index 405f678..f695b93 100755 --- a/src/View/Modules/PageNavModule/PageNavModule.cpp +++ b/src/View/Modules/PageNavModule/PageNavModule.cpp @@ -1,9 +1,10 @@ #include "PageNavModule.h" -#include -#include - -PageNavModule::PageNavModule(QWidget* parent) :QFrame(parent) { +PageNavModule::PageNavModule(QWidget* parent) : + QFrame(parent), + home(new PageNavigator(new HomePage( ), "Home", ":icons/home-outline.svg", "#81D4FA")), + localFiles(new PageNavigator(new LocalFolderPage( ), "Local Files", ":icons/folder-outline.svg", "#FFE082")), + playlist(new PageNavigator(new PlaylistPage( ), "Playlist", ":icons/magnify.svg", "#CE93D8")) { this->setStyleSheet(R"( background-color: #282828; @@ -16,17 +17,29 @@ PageNavModule::PageNavModule(QWidget* parent) :QFrame(parent) { QVBoxLayout* layout = new QVBoxLayout(this); - PageNavigator* home = new PageNavigator("Home", ":icons/home-outline.svg", "#81D4FA"); - PageNavigator* localFiles = new PageNavigator("Local Files", ":icons/folder-outline.svg", "#FFE082"); - PageNavigator* playlist = new PageNavigator("Playlist", ":icons/magnify.svg", "#CE93D8"); - layout->addWidget(home); layout->addWidget(localFiles); layout->addWidget(playlist); - connect(home, &PageNavigator::SelectedChanged, this, &PageNavModule::SelectChanged); - connect(localFiles, &PageNavigator::SelectedChanged, this, &PageNavModule::SelectChanged); - connect(playlist, &PageNavigator::SelectedChanged, this, &PageNavModule::SelectChanged); + PageManager& pageManager = PageManager::getInstance( ); + connect(home, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { + home->select( ); + localFiles->unselect( ); + playlist->unselect( ); + emit pageManager.ActivePageChanged(page); + }); + connect(localFiles, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { + home->unselect( ); + localFiles->select( ); + playlist->unselect( ); + emit pageManager.ActivePageChanged(page); + }); + connect(playlist, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { + home->unselect( ); + localFiles->unselect( ); + playlist->select( ); + emit pageManager.ActivePageChanged(page); + }); } PageNavModule::~PageNavModule( ) { } diff --git a/src/View/Modules/PageNavModule/PageNavModule.h b/src/View/Modules/PageNavModule/PageNavModule.h index 2ca68f8..9ff9f77 100755 --- a/src/View/Modules/PageNavModule/PageNavModule.h +++ b/src/View/Modules/PageNavModule/PageNavModule.h @@ -3,18 +3,27 @@ #include #include #include + #include "../../Widgets/PageNavigator/PageNavigator.h" #include "../../Tools/SvgToPixmap.hpp" +#include "../../Pages/Home/HomePage.h" +#include "../../Pages/Playlist/PlaylistPage.h" +#include "../../Pages/LocalFolder/LocalFolderPage.h" +#include "../../../Controller/PageManager/PageManager.h" class PageNavModule : public QFrame { Q_OBJECT private: - QVector pages; + QVector* pages; + + PageNavigator* home; + PageNavigator* localFiles; + PageNavigator* playlist; public: PageNavModule(QWidget* parent = nullptr); ~PageNavModule( ); signals: - void SelectChanged(PageNavigator* pn); + void SelectChanged(Page* page); }; diff --git a/src/View/Pages/Home/HomePage.cpp b/src/View/Pages/Home/HomePage.cpp index 09e3926..500ebb8 100644 --- a/src/View/Pages/Home/HomePage.cpp +++ b/src/View/Pages/Home/HomePage.cpp @@ -1,7 +1,6 @@ #include "HomePage.h" -HomePage::HomePage(QWidget* parent) - : QFrame(parent) { +HomePage::HomePage(QWidget* parent) : Page(parent) { setStyleSheet(R"( background-color: #28FF28; diff --git a/src/View/Pages/Home/HomePage.h b/src/View/Pages/Home/HomePage.h index c29b873..17dc8e4 100644 --- a/src/View/Pages/Home/HomePage.h +++ b/src/View/Pages/Home/HomePage.h @@ -2,14 +2,17 @@ #include #include -#include "../../Tools/SvgToPixmap.hpp" +#include "../../Tools/SvgToPixmap.hpp" +#include "../Page.h" -class HomePage : public QFrame { +class HomePage : public Page { Q_OBJECT private: - /* data */ + public: HomePage(QWidget* parent = nullptr); ~HomePage( ); + + std::string GetName( ) { return "home"; } }; diff --git a/src/View/Pages/LocalFolder/LocalFolderPage.cpp b/src/View/Pages/LocalFolder/LocalFolderPage.cpp new file mode 100644 index 0000000..0efacaf --- /dev/null +++ b/src/View/Pages/LocalFolder/LocalFolderPage.cpp @@ -0,0 +1,13 @@ +#include "LocalFolderPage.h" + +LocalFolderPage::LocalFolderPage(QWidget* parent) : Page(parent) { + + setStyleSheet(R"( + background-color: #FF2828; + border-radius: 12px; + )"); + + applyShadow(this); +} + +LocalFolderPage::~LocalFolderPage( ) { } diff --git a/src/View/Pages/LocalFolder/LocalFolderPage.h b/src/View/Pages/LocalFolder/LocalFolderPage.h new file mode 100644 index 0000000..ac8cfed --- /dev/null +++ b/src/View/Pages/LocalFolder/LocalFolderPage.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include + +#include "../../Tools/SvgToPixmap.hpp" +#include "../Page.h" + +class LocalFolderPage : public Page { +private: + +public: + LocalFolderPage(QWidget* parent = nullptr); + ~LocalFolderPage( ); + + std::string GetName( ) { return "localFolder"; } +}; diff --git a/src/View/Pages/Page.h b/src/View/Pages/Page.h new file mode 100644 index 0000000..735d83a --- /dev/null +++ b/src/View/Pages/Page.h @@ -0,0 +1,16 @@ +#pragma once + +#include + +class Page : public QFrame { + + Q_OBJECT + +private: + +public: + Page(QWidget* parent = nullptr) :QFrame(parent) { } + virtual ~Page( ) { } + + virtual std::string GetName( ) = 0; +}; diff --git a/src/View/Pages/Playlist/PlaylistPage.cpp b/src/View/Pages/Playlist/PlaylistPage.cpp index 8992b70..a036a31 100755 --- a/src/View/Pages/Playlist/PlaylistPage.cpp +++ b/src/View/Pages/Playlist/PlaylistPage.cpp @@ -1,7 +1,6 @@ #include "PlaylistPage.h" -PlaylistPage::PlaylistPage(QWidget* parent) - : QFrame(parent) { +PlaylistPage::PlaylistPage(QWidget* parent) :Page(parent) { setStyleSheet(R"( background-color: #2828ff; diff --git a/src/View/Pages/Playlist/PlaylistPage.h b/src/View/Pages/Playlist/PlaylistPage.h index 17b07d4..29df22f 100755 --- a/src/View/Pages/Playlist/PlaylistPage.h +++ b/src/View/Pages/Playlist/PlaylistPage.h @@ -2,12 +2,17 @@ #include #include + #include "../../Tools/SvgToPixmap.hpp" +#include "../Page.h" -class PlaylistPage : public QFrame { +class PlaylistPage : public Page { Q_OBJECT private: + public: PlaylistPage(QWidget* parent = nullptr); ~PlaylistPage( ); + + std::string GetName( ) { return "playlist"; } }; diff --git a/src/View/Widgets/PageNavigator/PageNavigator.cpp b/src/View/Widgets/PageNavigator/PageNavigator.cpp index 110aa5b..168a9d0 100644 --- a/src/View/Widgets/PageNavigator/PageNavigator.cpp +++ b/src/View/Widgets/PageNavigator/PageNavigator.cpp @@ -1,6 +1,5 @@ #include "PageNavigator.h" -#include "SelectHandler.hpp" -#include "../../Tools/SvgToPixmap.hpp" +#include class SquareIcon : public QLabel { public: @@ -11,8 +10,8 @@ class SquareIcon : public QLabel { } }; -PageNavigator::PageNavigator(QString text, QString icon, QString color, QWidget* parent) - :m_text(new QLabel(text)), m_icon(new SquareIcon( )), m_color(color), m_iconPath(icon) { +PageNavigator::PageNavigator(Page* page, QString text, QString icon, QString color, QWidget* parent) + :page(page), m_text(new QLabel(text)), m_icon(new SquareIcon( )), m_color(color), m_iconPath(icon) { QSvgRenderer renderer(icon); @@ -40,6 +39,8 @@ PageNavigator::PageNavigator(QString text, QString icon, QString color, QWidget* } )"); + setCursor(Qt::PointingHandCursor); + QFont font = m_text->font( ); font.setPointSize(16); font.setWeight(QFont::Bold); @@ -48,21 +49,9 @@ PageNavigator::PageNavigator(QString text, QString icon, QString color, QWidget* QHBoxLayout* layout = new QHBoxLayout(this); layout->addWidget(m_icon, 0, Qt::AlignLeft); layout->addWidget(m_text, 1, Qt::AlignLeft); - - connect(this, &QPushButton::clicked, [this, parent]( ) { - SelectHandler* sh = SelectHandler::GetInstance( ); - - sh->setSelected(this); - emit SelectedChanged(this); + connect(this, &QPushButton::clicked, [this]( ) { + emit SelectedChanged(this->page); }); - - // Little hacky but thats how home is the default - if (text == "Home") { - SelectHandler* sh = SelectHandler::GetInstance( ); - - sh->setSelected(this); - emit SelectedChanged(this); - } } void PageNavigator::unselect( ) { diff --git a/src/View/Widgets/PageNavigator/PageNavigator.h b/src/View/Widgets/PageNavigator/PageNavigator.h index 63474fc..566b911 100644 --- a/src/View/Widgets/PageNavigator/PageNavigator.h +++ b/src/View/Widgets/PageNavigator/PageNavigator.h @@ -8,6 +8,9 @@ #include #include +#include "../../Tools/SvgToPixmap.hpp" +#include "../../Pages/Page.h" + class PageNavigator :public QPushButton { Q_OBJECT private: @@ -15,9 +18,10 @@ class PageNavigator :public QPushButton { QLabel* m_icon; QString m_iconPath; QString m_color; + Page* page; public: - PageNavigator(QString text, QString icon, QString color, QWidget* parent = nullptr); + PageNavigator(Page* page, QString text, QString icon, QString color, QWidget* parent = nullptr); void unselect( ); void select( ); @@ -25,5 +29,5 @@ class PageNavigator :public QPushButton { QString GetText( ); signals: - void SelectedChanged(PageNavigator* pn); + void SelectedChanged(Page* page); }; diff --git a/src/View/Widgets/PageNavigator/SelectHandler.hpp b/src/View/Widgets/PageNavigator/SelectHandler.hpp deleted file mode 100644 index a3933d1..0000000 --- a/src/View/Widgets/PageNavigator/SelectHandler.hpp +++ /dev/null @@ -1,53 +0,0 @@ -#pragma once - -#include "PageNavigator.h" - -/* - Singleton to handle PageNavigator widget selects -*/ -class SelectHandler { -public: - static SelectHandler* GetInstance( ); - - ~SelectHandler( ) { } - SelectHandler(const SelectHandler&) = delete; - void operator=(const SelectHandler&) = delete; - - void setSelected(PageNavigator* newSelected); - - PageNavigator* getSelected( ); - -private: - SelectHandler( ) { } - - static SelectHandler* instance; - - PageNavigator* selected = nullptr; -}; - -SelectHandler* SelectHandler::instance = nullptr; - -SelectHandler* SelectHandler::GetInstance( ) { - if (instance == nullptr) - instance = new SelectHandler( ); - return instance; -} - -void SelectHandler::setSelected(PageNavigator* newSelected) { - if (!newSelected && (newSelected == selected)) - return; - - if (this->selected == nullptr) { - this->selected = newSelected; - selected->select( ); - return; - } - - selected->unselect( ); - newSelected->select( ); - this->selected = newSelected; -} - -PageNavigator* SelectHandler::getSelected( ) { - return selected; -}