Skip to content

Commit

Permalink
done with the page switcher for now, started creating the database
Browse files Browse the repository at this point in the history
  • Loading branch information
Crylia committed Apr 3, 2024
1 parent baea46d commit 8e64233
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 104 deletions.
File renamed without changes.
4 changes: 3 additions & 1 deletion src/Controller/MusicPlayer/MusicPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../core/SongQueue/SongQueue.h"
#include "../../core/song/song.h"


class MusicPlayer : public QObject {
Q_OBJECT
public:
Expand All @@ -17,7 +18,8 @@ class MusicPlayer : public QObject {
}

private:
MusicPlayer( ) : songQueue(new SongQueue( )), songHistory(new SongHistory<Song*>( )) { }
MusicPlayer( ) :
songQueue(new SongQueue( )), songHistory(new SongHistory<Song*>( )) { }

// 0 no shuffle, 1 shuffling
int shuffle = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/Controller/PageManager/PageManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "PageManager.h"

PageManager::~PageManager( ) { }
30 changes: 30 additions & 0 deletions src/Controller/PageManager/PageManager.h
Original file line number Diff line number Diff line change
@@ -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);
};
25 changes: 17 additions & 8 deletions src/View/MainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

void MainWidget::setupMainWidget( ) {
setContentsMargins(10, 10, 10, 10);

QOverlayout* ol = new QOverlayout(this);
setLayout(ol);

Expand All @@ -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);

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

Expand Down
7 changes: 6 additions & 1 deletion src/View/MainWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
35 changes: 24 additions & 11 deletions src/View/Modules/PageNavModule/PageNavModule.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "PageNavModule.h"

#include <QWidget>
#include <QFrame>

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;
Expand All @@ -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( ) { }
13 changes: 11 additions & 2 deletions src/View/Modules/PageNavModule/PageNavModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,27 @@
#include <QWidget>
#include <QVector>
#include <QFrame>

#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<PageNavigator> pages;
QVector<PageNavigator*>* pages;

PageNavigator* home;
PageNavigator* localFiles;
PageNavigator* playlist;

public:
PageNavModule(QWidget* parent = nullptr);
~PageNavModule( );

signals:
void SelectChanged(PageNavigator* pn);
void SelectChanged(Page* page);
};
3 changes: 1 addition & 2 deletions src/View/Pages/Home/HomePage.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "HomePage.h"

HomePage::HomePage(QWidget* parent)
: QFrame(parent) {
HomePage::HomePage(QWidget* parent) : Page(parent) {

setStyleSheet(R"(
background-color: #28FF28;
Expand Down
9 changes: 6 additions & 3 deletions src/View/Pages/Home/HomePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

#include <QWidget>
#include <QFrame>
#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"; }
};
13 changes: 13 additions & 0 deletions src/View/Pages/LocalFolder/LocalFolderPage.cpp
Original file line number Diff line number Diff line change
@@ -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( ) { }
17 changes: 17 additions & 0 deletions src/View/Pages/LocalFolder/LocalFolderPage.h
Original file line number Diff line number Diff line change
@@ -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 changes: 16 additions & 0 deletions src/View/Pages/Page.h
Original file line number Diff line number Diff line change
@@ -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;
};
3 changes: 1 addition & 2 deletions src/View/Pages/Playlist/PlaylistPage.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "PlaylistPage.h"

PlaylistPage::PlaylistPage(QWidget* parent)
: QFrame(parent) {
PlaylistPage::PlaylistPage(QWidget* parent) :Page(parent) {

setStyleSheet(R"(
background-color: #2828ff;
Expand Down
7 changes: 6 additions & 1 deletion src/View/Pages/Playlist/PlaylistPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@

#include <QWidget>
#include <QFrame>

#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"; }
};
25 changes: 7 additions & 18 deletions src/View/Widgets/PageNavigator/PageNavigator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "PageNavigator.h"
#include "SelectHandler.hpp"
#include "../../Tools/SvgToPixmap.hpp"
#include <iostream>

class SquareIcon : public QLabel {
public:
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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( ) {
Expand Down
Loading

0 comments on commit 8e64233

Please sign in to comment.