Skip to content

Commit

Permalink
did main work on the page selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Crylia committed Mar 20, 2024
1 parent eadcd5a commit a2872f6
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 1 deletion.
File renamed without changes
2 changes: 1 addition & 1 deletion assets/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<file>icons/songControl/volume-off.svg</file>
<file>icons/songControl/volume-medium.svg</file>
<file>icons/songControl/arrow-expand.svg</file>
<file>icons/songControl/home.svg</file>
<file>icons/home.svg</file>
<file>icons/songControl/magnify.svg</file>
</qresource>
</RCC>
11 changes: 11 additions & 0 deletions src/Public/Modules/PageNavigator/pages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ Pages::Pages(QWidget* parent) :QFrame(parent) {
)");

this->setFixedSize(300, 180);

QVBoxLayout* layout = new QVBoxLayout(this);

PageNavigator* home = new PageNavigator("Home", ":icons/home.svg");
PageNavigator* localFiles = new PageNavigator("Local Files", ":icons/home.svg");
PageNavigator* playlist = new PageNavigator("Playlist", ":icons/songControl/magnify.svg");


layout->addWidget(home);
layout->addWidget(localFiles);
layout->addWidget(playlist);
}

Pages::~Pages( ) { }
1 change: 1 addition & 0 deletions src/Public/Modules/PageNavigator/pages.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QWidget>
#include <QFrame>
#include "../../Widgets/PageNavigator/PageNavigator.h"

class Pages : public QFrame {

Expand Down
3 changes: 3 additions & 0 deletions src/Public/Modules/PlaylistNavigator/PlaylistWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ PlaylistWidget::PlaylistWidget(QWidget* parent) : QFrame(parent) {

this->setFixedWidth(300);

QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->addSpacing(10);

}

PlaylistWidget::~PlaylistWidget( ) { }
1 change: 1 addition & 0 deletions src/Public/Modules/PlaylistNavigator/PlaylistWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QWidget>
#include <QFrame>
#include <QLayout>

class PlaylistWidget : public QFrame {

Expand Down
16 changes: 16 additions & 0 deletions src/Public/Tools/SvgToPixmap.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <QPixmap>
#include <QString>
#include <QSvgRenderer>
#include <QPainter>

static QPixmap RenderSvg(QString path, int w, int h) {
QSvgRenderer renderer(path);
QPixmap pixmap(w, h);
pixmap.fill(Qt::transparent);
QPainter painter(&pixmap);
renderer.render(&painter);

return pixmap;
}
54 changes: 54 additions & 0 deletions src/Public/Widgets/PageNavigator/PageNavigator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "PageNavigator.h"
#include "SelectHandler.hpp"

PageNavigator::PageNavigator(QString text, QString icon, QWidget* parent)
:m_text(new QLabel(text)), m_icon(new QLabel( )) {

m_icon->setPixmap(icon);

setObjectName("PageNavigator");
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
setStyleSheet(R"(
#PageNavigator{
border: 4px solid #414141;
border-radius: 8px;
color: #E0E0E0;
}
)");

QFont font = m_text->font( );
font.setPointSize(16);
font.setWeight(QFont::Bold);
m_text->setFont(font);

QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(m_icon, 0, Qt::AlignLeft);
layout->addWidget(m_text, 1, Qt::AlignLeft);

connect(this, &QPushButton::clicked, [this]( ) {
SelectHandler* sh = SelectHandler::GetInstance( );

sh->setSelected(this);
});

}

void PageNavigator::unselect( ) {
setStyleSheet(R"(
#PageNavigator{
border: 4px solid #414141;
border-radius: 6px;
color: #E0E0E0;
}
)");
}

void PageNavigator::select( ) {
setStyleSheet(R"(
#PageNavigator{
border: 4px solid #81D4FA;
border-radius: 6px;
color: #E0E0E0;
}
)");
}
20 changes: 20 additions & 0 deletions src/Public/Widgets/PageNavigator/PageNavigator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <QWidget>
#include <QLabel>
#include <QLayout>
#include <QFont>
#include <QPushButton>

class PageNavigator :public QPushButton {
Q_OBJECT
private:
QLabel* m_text;
QLabel* m_icon;

public:
PageNavigator(QString text, QString icon, QWidget* parent = nullptr);

void unselect( );
void select( );
};
54 changes: 54 additions & 0 deletions src/Public/Widgets/PageNavigator/SelectHandler.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#pragma once

#include <QWidget>
#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;
newSelected->select( );
return;
}

selected->unselect( );
newSelected->select( );
this->selected = newSelected;
}

PageNavigator* SelectHandler::getSelected( ) {
return selected;
}

0 comments on commit a2872f6

Please sign in to comment.