done with the page switcher for now, started creating the database

This commit is contained in:
Crylia
2024-04-03 05:59:38 +02:00
parent baea46d3a7
commit 8e642336d2
18 changed files with 168 additions and 105 deletions

View File

@@ -8,6 +8,7 @@
#include "../../core/SongQueue/SongQueue.h" #include "../../core/SongQueue/SongQueue.h"
#include "../../core/song/song.h" #include "../../core/song/song.h"
class MusicPlayer : public QObject { class MusicPlayer : public QObject {
Q_OBJECT Q_OBJECT
public: public:
@@ -17,7 +18,8 @@ public:
} }
private: private:
MusicPlayer( ) : songQueue(new SongQueue( )), songHistory(new SongHistory<Song*>( )) { } MusicPlayer( ) :
songQueue(new SongQueue( )), songHistory(new SongHistory<Song*>( )) { }
// 0 no shuffle, 1 shuffling // 0 no shuffle, 1 shuffling
int shuffle = 0; int shuffle = 0;

View File

@@ -0,0 +1,3 @@
#include "PageManager.h"
PageManager::~PageManager( ) { }

View File

@@ -0,0 +1,30 @@
#pragma once
#include <QObject>
#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);
};

View File

@@ -2,7 +2,6 @@
void MainWidget::setupMainWidget( ) { void MainWidget::setupMainWidget( ) {
setContentsMargins(10, 10, 10, 10); setContentsMargins(10, 10, 10, 10);
QOverlayout* ol = new QOverlayout(this); QOverlayout* ol = new QOverlayout(this);
setLayout(ol); setLayout(ol);
@@ -16,11 +15,13 @@ void MainWidget::setupMainWidget( ) {
vbox2->addWidget(playlistNav); vbox2->addWidget(playlistNav);
hbox->addLayout(vbox2); hbox->addLayout(vbox2);
QHBoxLayout* stackedLayout = new QHBoxLayout( ); QHBoxLayout* stackedLayout = new QHBoxLayout( );
stackedLayout->addWidget(homePage); stackedLayout->addWidget(homePage);
stackedLayout->addWidget(playlistPage); stackedLayout->addWidget(playlistPage);
stackedLayout->addWidget(localFolderPage);
pageManager.GetActivePage( )->setVisible(true);
playlistPage->setVisible(false); playlistPage->setVisible(false);
localFolderPage->setVisible(false);
hbox->addLayout(stackedLayout, 0); hbox->addLayout(stackedLayout, 0);
@@ -30,18 +31,24 @@ void MainWidget::setupMainWidget( ) {
ol->addItem(hbox); ol->addItem(hbox);
ol->addItem(vbox); ol->addItem(vbox);
connect(pageNav, &PageNavModule::SelectChanged, [this, stackedLayout](PageNavigator* pn) { connect(&pageManager, &PageManager::ActivePageChanged, [this, stackedLayout](Page* page) {
if (pn->GetText( ).toStdString( ) == "Home") { if (page->GetName( ) == "home") {
//stackedLayout->setCurrentIndex(0);
stackedLayout->itemAt(0)->widget( )->setVisible(true); stackedLayout->itemAt(0)->widget( )->setVisible(true);
stackedLayout->itemAt(1)->widget( )->setVisible(false); stackedLayout->itemAt(1)->widget( )->setVisible(false);
stackedLayout->itemAt(2)->widget( )->setVisible(false);
} }
else if (pn->GetText( ).toStdString( ) == "Playlist") { else if (page->GetName( ) == "playlist") {
//stackedLayout->setCurrentIndex(1);
stackedLayout->itemAt(0)->widget( )->setVisible(false); stackedLayout->itemAt(0)->widget( )->setVisible(false);
stackedLayout->itemAt(1)->widget( )->setVisible(true); 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( ) { } void MainWidget::PageChangedAction( ) { }
@@ -51,7 +58,9 @@ MainWidget::MainWidget(QWidget* parent)
pageNav(new PageNavModule(this)), pageNav(new PageNavModule(this)),
playlistNav(new PlaylistNavModule(this)), playlistNav(new PlaylistNavModule(this)),
playlistPage(new PlaylistPage(this)), playlistPage(new PlaylistPage(this)),
homePage(new HomePage(this)) { homePage(new HomePage(this)),
localFolderPage(new LocalFolderPage(this)) {
pageManager.SetActivePage(homePage);
setupMainWidget( ); setupMainWidget( );
} }

View File

@@ -11,6 +11,8 @@
#include "Modules/PlaylistNavModule/PlaylistNavModule.h" #include "Modules/PlaylistNavModule/PlaylistNavModule.h"
#include "Pages/Playlist/PlaylistPage.h" #include "Pages/Playlist/PlaylistPage.h"
#include "Pages/Home/HomePage.h" #include "Pages/Home/HomePage.h"
#include "Pages/LocalFolder/LocalFolderPage.h"
#include "../Controller/PageManager/PageManager.h"
class MainWidget : public QWidget { class MainWidget : public QWidget {
Q_OBJECT Q_OBJECT
@@ -21,14 +23,17 @@ private:
PlaylistPage* playlistPage; PlaylistPage* playlistPage;
HomePage* homePage; HomePage* homePage;
LocalFolderPage* localFolderPage;
FloatingControls* floatingControlls; FloatingControls* floatingControlls;
PageManager& pageManager = PageManager::getInstance( );
void setupMainWidget( ); void setupMainWidget( );
public: public:
MainWidget(QWidget* parent = nullptr); MainWidget(QWidget* parent = nullptr);
MainWidget(std::filesystem::path path, QWidget* parent = nullptr); //MainWidget(std::filesystem::path path, QWidget* parent = nullptr);
~MainWidget( ); ~MainWidget( );
private slots: private slots:

View File

@@ -1,9 +1,10 @@
#include "PageNavModule.h" #include "PageNavModule.h"
#include <QWidget> PageNavModule::PageNavModule(QWidget* parent) :
#include <QFrame> QFrame(parent),
home(new PageNavigator(new HomePage( ), "Home", ":icons/home-outline.svg", "#81D4FA")),
PageNavModule::PageNavModule(QWidget* parent) :QFrame(parent) { 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"( this->setStyleSheet(R"(
background-color: #282828; background-color: #282828;
@@ -16,17 +17,29 @@ PageNavModule::PageNavModule(QWidget* parent) :QFrame(parent) {
QVBoxLayout* layout = new QVBoxLayout(this); 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(home);
layout->addWidget(localFiles); layout->addWidget(localFiles);
layout->addWidget(playlist); layout->addWidget(playlist);
connect(home, &PageNavigator::SelectedChanged, this, &PageNavModule::SelectChanged); PageManager& pageManager = PageManager::getInstance( );
connect(localFiles, &PageNavigator::SelectedChanged, this, &PageNavModule::SelectChanged); connect(home, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) {
connect(playlist, &PageNavigator::SelectedChanged, this, &PageNavModule::SelectChanged); 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( ) { } PageNavModule::~PageNavModule( ) { }

View File

@@ -3,18 +3,27 @@
#include <QWidget> #include <QWidget>
#include <QVector> #include <QVector>
#include <QFrame> #include <QFrame>
#include "../../Widgets/PageNavigator/PageNavigator.h" #include "../../Widgets/PageNavigator/PageNavigator.h"
#include "../../Tools/SvgToPixmap.hpp" #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 { class PageNavModule : public QFrame {
Q_OBJECT Q_OBJECT
private: private:
QVector<PageNavigator> pages; QVector<PageNavigator*>* pages;
PageNavigator* home;
PageNavigator* localFiles;
PageNavigator* playlist;
public: public:
PageNavModule(QWidget* parent = nullptr); PageNavModule(QWidget* parent = nullptr);
~PageNavModule( ); ~PageNavModule( );
signals: signals:
void SelectChanged(PageNavigator* pn); void SelectChanged(Page* page);
}; };

View File

@@ -1,7 +1,6 @@
#include "HomePage.h" #include "HomePage.h"
HomePage::HomePage(QWidget* parent) HomePage::HomePage(QWidget* parent) : Page(parent) {
: QFrame(parent) {
setStyleSheet(R"( setStyleSheet(R"(
background-color: #28FF28; background-color: #28FF28;

View File

@@ -2,14 +2,17 @@
#include <QWidget> #include <QWidget>
#include <QFrame> #include <QFrame>
#include "../../Tools/SvgToPixmap.hpp" #include "../../Tools/SvgToPixmap.hpp"
#include "../Page.h"
class HomePage : public Page {
class HomePage : public QFrame {
Q_OBJECT Q_OBJECT
private: private:
/* data */
public: public:
HomePage(QWidget* parent = nullptr); HomePage(QWidget* parent = nullptr);
~HomePage( ); ~HomePage( );
std::string GetName( ) { return "home"; }
}; };

View File

@@ -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( ) { }

View File

@@ -0,0 +1,17 @@
#pragma once
#include <QWidget>
#include <QFrame>
#include "../../Tools/SvgToPixmap.hpp"
#include "../Page.h"
class LocalFolderPage : public Page {
private:
public:
LocalFolderPage(QWidget* parent = nullptr);
~LocalFolderPage( );
std::string GetName( ) { return "localFolder"; }
};

16
src/View/Pages/Page.h Normal file
View File

@@ -0,0 +1,16 @@
#pragma once
#include <QFrame>
class Page : public QFrame {
Q_OBJECT
private:
public:
Page(QWidget* parent = nullptr) :QFrame(parent) { }
virtual ~Page( ) { }
virtual std::string GetName( ) = 0;
};

View File

@@ -1,7 +1,6 @@
#include "PlaylistPage.h" #include "PlaylistPage.h"
PlaylistPage::PlaylistPage(QWidget* parent) PlaylistPage::PlaylistPage(QWidget* parent) :Page(parent) {
: QFrame(parent) {
setStyleSheet(R"( setStyleSheet(R"(
background-color: #2828ff; background-color: #2828ff;

View File

@@ -2,12 +2,17 @@
#include <QWidget> #include <QWidget>
#include <QFrame> #include <QFrame>
#include "../../Tools/SvgToPixmap.hpp"
class PlaylistPage : public QFrame { #include "../../Tools/SvgToPixmap.hpp"
#include "../Page.h"
class PlaylistPage : public Page {
Q_OBJECT Q_OBJECT
private: private:
public: public:
PlaylistPage(QWidget* parent = nullptr); PlaylistPage(QWidget* parent = nullptr);
~PlaylistPage( ); ~PlaylistPage( );
std::string GetName( ) { return "playlist"; }
}; };

View File

@@ -1,6 +1,5 @@
#include "PageNavigator.h" #include "PageNavigator.h"
#include "SelectHandler.hpp" #include <iostream>
#include "../../Tools/SvgToPixmap.hpp"
class SquareIcon : public QLabel { class SquareIcon : public QLabel {
public: public:
@@ -11,8 +10,8 @@ public:
} }
}; };
PageNavigator::PageNavigator(QString text, QString icon, QString color, QWidget* parent) PageNavigator::PageNavigator(Page* page, QString text, QString icon, QString color, QWidget* parent)
:m_text(new QLabel(text)), m_icon(new SquareIcon( )), m_color(color), m_iconPath(icon) { :page(page), m_text(new QLabel(text)), m_icon(new SquareIcon( )), m_color(color), m_iconPath(icon) {
QSvgRenderer renderer(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( ); QFont font = m_text->font( );
font.setPointSize(16); font.setPointSize(16);
font.setWeight(QFont::Bold); font.setWeight(QFont::Bold);
@@ -48,21 +49,9 @@ PageNavigator::PageNavigator(QString text, QString icon, QString color, QWidget*
QHBoxLayout* layout = new QHBoxLayout(this); QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(m_icon, 0, Qt::AlignLeft); layout->addWidget(m_icon, 0, Qt::AlignLeft);
layout->addWidget(m_text, 1, Qt::AlignLeft); layout->addWidget(m_text, 1, Qt::AlignLeft);
connect(this, &QPushButton::clicked, [this]( ) {
connect(this, &QPushButton::clicked, [this, parent]( ) { emit SelectedChanged(this->page);
SelectHandler* sh = SelectHandler::GetInstance( );
sh->setSelected(this);
emit SelectedChanged(this);
}); });
// 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( ) { void PageNavigator::unselect( ) {

View File

@@ -8,6 +8,9 @@
#include <QColor> #include <QColor>
#include <QGraphicsColorizeEffect> #include <QGraphicsColorizeEffect>
#include "../../Tools/SvgToPixmap.hpp"
#include "../../Pages/Page.h"
class PageNavigator :public QPushButton { class PageNavigator :public QPushButton {
Q_OBJECT Q_OBJECT
private: private:
@@ -15,9 +18,10 @@ private:
QLabel* m_icon; QLabel* m_icon;
QString m_iconPath; QString m_iconPath;
QString m_color; QString m_color;
Page* page;
public: 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 unselect( );
void select( ); void select( );
@@ -25,5 +29,5 @@ public:
QString GetText( ); QString GetText( );
signals: signals:
void SelectedChanged(PageNavigator* pn); void SelectedChanged(Page* page);
}; };

View File

@@ -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;
}