From 574efcde7fac7f84645dce460d47df57b110dd5e Mon Sep 17 00:00:00 2001 From: Crylia Date: Wed, 3 Apr 2024 11:36:34 +0200 Subject: [PATCH] added settings page and db manager --- CMakeLists.txt | 5 +++-- src/View/MainWidget.cpp | 14 +++++++++++++- src/View/MainWidget.h | 2 ++ .../Modules/PageNavModule/PageNavModule.cpp | 18 ++++++++++++++++-- src/View/Modules/PageNavModule/PageNavModule.h | 3 +++ src/View/Pages/Settings/SettingsPage.cpp | 13 +++++++++++++ src/View/Pages/Settings/SettingsPage.h | 18 ++++++++++++++++++ .../Widgets/PageNavigator/PageNavigator.cpp | 9 +++++++++ src/core/database/DatabaseManager.cpp | 13 +++++++++++++ src/core/database/DatabaseManager.h | 14 ++++++++++++++ 10 files changed, 104 insertions(+), 5 deletions(-) create mode 100644 src/View/Pages/Settings/SettingsPage.cpp create mode 100644 src/View/Pages/Settings/SettingsPage.h create mode 100644 src/core/database/DatabaseManager.cpp create mode 100644 src/core/database/DatabaseManager.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dadd71d..d74d2a1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,8 @@ set(CMAKE_AUTORCC ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Qml Svg Core) -find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Qml Svg Core) +find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Qml Svg Core Sql) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Qml Svg Core Sql) find_package(SDL2 QUIET) @@ -56,6 +56,7 @@ target_link_libraries(CryliaPlayer PRIVATE Qt${QT_VERSION_MAJOR}::Qml Qt${QT_VERSION_MAJOR}::Svg Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Sql ${SDL_LIBRARIES} ${SDL_MIXER_LIBRARY} PkgConfig::LIBAV diff --git a/src/View/MainWidget.cpp b/src/View/MainWidget.cpp index af96df7..ccab1df 100644 --- a/src/View/MainWidget.cpp +++ b/src/View/MainWidget.cpp @@ -18,10 +18,12 @@ void MainWidget::setupMainWidget( ) { stackedLayout->addWidget(homePage); stackedLayout->addWidget(playlistPage); stackedLayout->addWidget(localFolderPage); + stackedLayout->addWidget(settingsPage); pageManager.GetActivePage( )->setVisible(true); playlistPage->setVisible(false); localFolderPage->setVisible(false); + settingsPage->setVisible(false); hbox->addLayout(stackedLayout, 0); @@ -36,16 +38,25 @@ void MainWidget::setupMainWidget( ) { stackedLayout->itemAt(0)->widget( )->setVisible(true); stackedLayout->itemAt(1)->widget( )->setVisible(false); stackedLayout->itemAt(2)->widget( )->setVisible(false); + stackedLayout->itemAt(3)->widget( )->setVisible(false); } else if (page->GetName( ) == "playlist") { stackedLayout->itemAt(0)->widget( )->setVisible(false); stackedLayout->itemAt(1)->widget( )->setVisible(true); stackedLayout->itemAt(2)->widget( )->setVisible(false); + stackedLayout->itemAt(3)->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); + stackedLayout->itemAt(3)->widget( )->setVisible(false); + } + else if (page->GetName( ) == "settings") { + stackedLayout->itemAt(0)->widget( )->setVisible(false); + stackedLayout->itemAt(1)->widget( )->setVisible(false); + stackedLayout->itemAt(2)->widget( )->setVisible(false); + stackedLayout->itemAt(3)->widget( )->setVisible(true); } }); @@ -59,7 +70,8 @@ MainWidget::MainWidget(QWidget* parent) playlistNav(new PlaylistNavModule(this)), playlistPage(new PlaylistPage(this)), homePage(new HomePage(this)), - localFolderPage(new LocalFolderPage(this)) { + localFolderPage(new LocalFolderPage(this)), + settingsPage(new SettingsPage(this)) { pageManager.SetActivePage(homePage); setupMainWidget( ); } diff --git a/src/View/MainWidget.h b/src/View/MainWidget.h index ec9fe25..f54d0cb 100644 --- a/src/View/MainWidget.h +++ b/src/View/MainWidget.h @@ -12,6 +12,7 @@ #include "Pages/Playlist/PlaylistPage.h" #include "Pages/Home/HomePage.h" #include "Pages/LocalFolder/LocalFolderPage.h" +#include "Pages/Settings/SettingsPage.h" #include "../Controller/PageManager/PageManager.h" class MainWidget : public QWidget { @@ -24,6 +25,7 @@ class MainWidget : public QWidget { PlaylistPage* playlistPage; HomePage* homePage; LocalFolderPage* localFolderPage; + SettingsPage* settingsPage; FloatingControls* floatingControlls; diff --git a/src/View/Modules/PageNavModule/PageNavModule.cpp b/src/View/Modules/PageNavModule/PageNavModule.cpp index f695b93..3bebd8c 100755 --- a/src/View/Modules/PageNavModule/PageNavModule.cpp +++ b/src/View/Modules/PageNavModule/PageNavModule.cpp @@ -4,7 +4,8 @@ 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")) { + playlist(new PageNavigator(new PlaylistPage( ), "Playlist", ":icons/magnify.svg", "#CE93D8")), + settings(new PageNavigator(new SettingsPage( ), "Settings", ":icons/magnify.svg", "#C5E1A5")) { this->setStyleSheet(R"( background-color: #282828; @@ -13,31 +14,44 @@ PageNavModule::PageNavModule(QWidget* parent) : applyShadow(this); - this->setFixedSize(300, 180); + this->setFixedSize(300, 240); QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(home); + layout->addWidget(settings); layout->addWidget(localFiles); layout->addWidget(playlist); + home->select( ); + PageManager& pageManager = PageManager::getInstance( ); connect(home, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { home->select( ); localFiles->unselect( ); playlist->unselect( ); + settings->unselect( ); emit pageManager.ActivePageChanged(page); }); connect(localFiles, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { home->unselect( ); localFiles->select( ); playlist->unselect( ); + settings->unselect( ); emit pageManager.ActivePageChanged(page); }); connect(playlist, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { home->unselect( ); localFiles->unselect( ); playlist->select( ); + settings->unselect( ); + emit pageManager.ActivePageChanged(page); + }); + connect(settings, &PageNavigator::SelectedChanged, [&pageManager, this](Page* page) { + home->unselect( ); + localFiles->unselect( ); + playlist->unselect( ); + settings->select( ); emit pageManager.ActivePageChanged(page); }); } diff --git a/src/View/Modules/PageNavModule/PageNavModule.h b/src/View/Modules/PageNavModule/PageNavModule.h index 9ff9f77..8fce25a 100755 --- a/src/View/Modules/PageNavModule/PageNavModule.h +++ b/src/View/Modules/PageNavModule/PageNavModule.h @@ -3,12 +3,14 @@ #include #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 "../../Pages/Settings/SettingsPage.h" #include "../../../Controller/PageManager/PageManager.h" class PageNavModule : public QFrame { @@ -19,6 +21,7 @@ class PageNavModule : public QFrame { PageNavigator* home; PageNavigator* localFiles; PageNavigator* playlist; + PageNavigator* settings; public: PageNavModule(QWidget* parent = nullptr); diff --git a/src/View/Pages/Settings/SettingsPage.cpp b/src/View/Pages/Settings/SettingsPage.cpp new file mode 100644 index 0000000..b91c6a7 --- /dev/null +++ b/src/View/Pages/Settings/SettingsPage.cpp @@ -0,0 +1,13 @@ +#include "SettingsPage.h" + +SettingsPage::SettingsPage(QWidget* parent) :Page(parent) { + + setStyleSheet(R"( + background-color: #282828; + border-radius: 12px; + )"); + + applyShadow(this); +} + +SettingsPage::~SettingsPage( ) { } diff --git a/src/View/Pages/Settings/SettingsPage.h b/src/View/Pages/Settings/SettingsPage.h new file mode 100644 index 0000000..5d50173 --- /dev/null +++ b/src/View/Pages/Settings/SettingsPage.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include + +#include "../../Tools/SvgToPixmap.hpp" +#include "../Page.h" + +class SettingsPage : public Page { + Q_OBJECT +private: + +public: + SettingsPage(QWidget* parent = nullptr); + ~SettingsPage( ); + + std::string GetName( ) { return "settings"; } +}; diff --git a/src/View/Widgets/PageNavigator/PageNavigator.cpp b/src/View/Widgets/PageNavigator/PageNavigator.cpp index d48300b..260eda5 100644 --- a/src/View/Widgets/PageNavigator/PageNavigator.cpp +++ b/src/View/Widgets/PageNavigator/PageNavigator.cpp @@ -55,6 +55,9 @@ PageNavigator::PageNavigator(Page* page, QString text, QString icon, QString col connect(this, &QPushButton::clicked, [this]( ) { emit SelectedChanged(this->page); }); + + this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Preferred); + } void PageNavigator::unselect( ) { @@ -63,6 +66,9 @@ void PageNavigator::unselect( ) { border: 4px solid #414141; border-radius: 6px; } + #Text{ + color: #E0E0E0; + } )"); } @@ -72,6 +78,9 @@ void PageNavigator::select( ) { border: 4px solid )" + m_color + R"(; border-radius: 6px; } + #Text{ + color: #E0E0E0; + } )"); } diff --git a/src/core/database/DatabaseManager.cpp b/src/core/database/DatabaseManager.cpp new file mode 100644 index 0000000..0f77476 --- /dev/null +++ b/src/core/database/DatabaseManager.cpp @@ -0,0 +1,13 @@ +#include "DatabaseManager.h" + +DbManager::DbManager( ) : + m_db(QSqlDatabase::addDatabase("QSQLITE")) { + m_db.setDatabaseName(QString("../../../database/CryliaPlayerDB.sqlite3")); + + if (!m_db.open( )) { + std::cout << "Error: Could not open database" << std::endl; + } + +} + +DbManager::~DbManager( ) { } diff --git a/src/core/database/DatabaseManager.h b/src/core/database/DatabaseManager.h new file mode 100644 index 0000000..15ecc6c --- /dev/null +++ b/src/core/database/DatabaseManager.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include + +class DbManager { +private: + QSqlDatabase m_db; +public: + DbManager( ); + ~DbManager( ); +}; +