ready to properly implement floatingControll, SDL2 will be the backend until I figure out ffmpeg and another lib to play sound, SDL2_mixer errors on ubuntu based because its outdated?

This commit is contained in:
Crylia
2024-03-26 16:51:55 +01:00
parent 17c44f8a15
commit 864497656b
5 changed files with 28 additions and 75 deletions

View File

@@ -55,14 +55,4 @@ MainWidget::MainWidget(QWidget* parent)
setupMainWidget( ); setupMainWidget( );
} }
MainWidget::MainWidget(std::filesystem::path path, QWidget* parent)
: QWidget(parent),
pageNav(new PageNavModule(this)),
playlistNav(new PlaylistNavModule(this)),
playlistPage(new PlaylistPage(this)),
homePage(new HomePage(this)),
floatingControlls(new FloatingControls(this, path)) {
setupMainWidget( );
}
MainWidget::~MainWidget( ) { } MainWidget::~MainWidget( ) { }

View File

@@ -19,9 +19,4 @@ MainWindow::MainWindow(QWidget* parent)
setupMainWindow( ); setupMainWindow( );
} }
MainWindow::MainWindow(std::filesystem::path path, QWidget* parent)
: QMainWindow(parent), mainWidget(new MainWidget(path, this)) {
setupMainWindow( );
}
MainWindow::~MainWindow( ) { } MainWindow::~MainWindow( ) { }

View File

@@ -1,18 +1,7 @@
#include <iostream> #include <iostream>
#include "FloatingControls.h" #include "FloatingControls.h"
#include <QGraphicsDropShadowEffect>
#include <QGraphicsBlurEffect>
#include <QLayout>
#include <QWidget>
#include <QLabel>
#include <string>
#include <QPixmap>
#include <QtSvg>
#include <QSvgRenderer>
#include <QPainter>
#include <QMainWindow>
#include <QApplication>
enum Repeat : short { enum Repeat : short {
ALL, ALL,
@@ -40,7 +29,7 @@ static QPushButton* makeSongControlButton(QString name, QSize size = QSize(36, 3
return button; return button;
} }
FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path) : FloatingControls::FloatingControls(QWidget* parent) :
QFrame(parent), QFrame(parent),
volume(100), volume(100),
albumArtPath("default.png"), albumArtPath("default.png"),
@@ -48,8 +37,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
playPause(false), playPause(false),
songRepeat(NONE), songRepeat(NONE),
artist("Artist"), artist("Artist"),
songName("Song"), songName("Song") {
song(Audio::getInstance( )) {
this->setFixedHeight(100); this->setFixedHeight(100);
this->setObjectName("main"); this->setObjectName("main");
this->setStyleSheet(R"( this->setStyleSheet(R"(
@@ -79,13 +67,13 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
border-radius: 8px; border-radius: 8px;
} }
)"); )");
//! Change later to the actual album art when the controls are done
albumArt->setPixmap(song.GetAlbumCover( ).scaled(QSize(64, 64), Qt::IgnoreAspectRatio)); //albumArt->setPixmap();
leftLayout->addWidget(albumArt); leftLayout->addWidget(albumArt);
// Artist and Song name layout // Artist and Song name layout
QVBoxLayout* artistSongLayout = new QVBoxLayout( ); QVBoxLayout* artistSongLayout = new QVBoxLayout( );
QLabel* artist = new QLabel(QString::fromStdString(song.GetArtist( ))); QLabel* artist = new QLabel("");
artist->setMinimumWidth(50); artist->setMinimumWidth(50);
connect(this, &FloatingControls::artistChanged, artist, &QLabel::setText); connect(this, &FloatingControls::artistChanged, artist, &QLabel::setText);
artist->setObjectName("artist"); artist->setObjectName("artist");
@@ -100,7 +88,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
QLabel* songName = new QLabel( ); QLabel* songName = new QLabel( );
songName->setMinimumWidth(50); songName->setMinimumWidth(50);
QFontMetrics metrics(songName->font( )); QFontMetrics metrics(songName->font( ));
songName->setText(metrics.elidedText(QString::fromStdString(song.GetTitle( )), Qt::ElideRight, songName->width( ))); songName->setText(metrics.elidedText("", Qt::ElideRight, songName->width( )));
connect(this, &FloatingControls::songNameChanged, songName, &QLabel::setText); connect(this, &FloatingControls::songNameChanged, songName, &QLabel::setText);
songName->setObjectName("title"); songName->setObjectName("title");
@@ -133,26 +121,9 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
col = "#D7D7D7"; col = "#D7D7D7";
QPushButton* pb = makeSongControlButton(buttonNames[i], QSize(36, 36), col); QPushButton* pb = makeSongControlButton(buttonNames[i], QSize(36, 36), col);
if (buttonNames[i] == "play") { if (buttonNames[i] == "play") {
//TODO Change later
QObject::connect(pb, &QPushButton::clicked, [pb, this]( ) {
if (!song.IsMusicPlaying( )) {
song.StartMusic( );
pb->setIcon(RenderSvg(":/icons/pause.svg", 36, 36));
return;
}
if (GetPlayPause( )) {
song.ResumeMusic( );
pb->setIcon(RenderSvg(":/icons/pause.svg", 36, 36));
}
else {
song.PauseMusic( );
pb->setIcon(RenderSvg(":/icons/play.svg", 36, 36));
}
togglePlayPause( );
});
} }
songControlsLayout->addWidget(pb); songControlsLayout->addWidget(pb);
} }
@@ -163,12 +134,6 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
// Song timestamp // Song timestamp
QLabel* songTimestamp = new QLabel("00:00"); QLabel* songTimestamp = new QLabel("00:00");
songTimestamp->setText(
QTime(
0,
song.GetMusicPos( ) / 60,
song.GetMusicPos( ) % 60
).toString("mm:ss"));
songTimestamp->setObjectName("songTimestamp"); songTimestamp->setObjectName("songTimestamp");
songTimestamp->setStyleSheet(R"( songTimestamp->setStyleSheet(R"(
QLabel#songTimestamp{ QLabel#songTimestamp{
@@ -180,12 +145,6 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
// Song duration // Song duration
QLabel* songDuration = new QLabel("00:00"); QLabel* songDuration = new QLabel("00:00");
songDuration->setText(
QTime(
0,
song.GetMusicDuration( ) / 60,
song.GetMusicDuration( ) % 60
).toString("mm:ss"));
songDuration->setObjectName("songDuration"); songDuration->setObjectName("songDuration");
songDuration->setStyleSheet(R"( songDuration->setStyleSheet(R"(
QLabel#songDuration{ QLabel#songDuration{
@@ -197,8 +156,8 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
// Song duration slider // Song duration slider
QSlider* songDurationSlider = new QSlider(Qt::Horizontal); QSlider* songDurationSlider = new QSlider(Qt::Horizontal);
songDurationSlider->setObjectName("songDurationSlider"); songDurationSlider->setObjectName("songDurationSlider");
songDurationSlider->setRange(0, song.GetMusicDuration( )); songDurationSlider->setRange(0, 100);
songDurationSlider->setValue(song.GetMusicPos( )); songDurationSlider->setValue(50);
songDurationSlider->setFixedHeight(28); songDurationSlider->setFixedHeight(28);
songDurationSlider->setStyleSheet(R"( songDurationSlider->setStyleSheet(R"(
QSlider#songDurationSlider::groove:horizontal{ QSlider#songDurationSlider::groove:horizontal{
@@ -224,7 +183,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
songDurationSlider->setCursor(Qt::PointingHandCursor); songDurationSlider->setCursor(Qt::PointingHandCursor);
connect(songDurationSlider, &QSlider::sliderReleased, [this, songDurationSlider]( ) { connect(songDurationSlider, &QSlider::sliderReleased, [this, songDurationSlider]( ) {
song.SetMusicPos(songDurationSlider->value( ));
}); });
songScrollerLayout->addWidget(songTimestamp); songScrollerLayout->addWidget(songTimestamp);
@@ -234,7 +193,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
QTimer* timer = new QTimer(this); QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this, songTimestamp, songDurationSlider]( ) { connect(timer, &QTimer::timeout, this, [this, songTimestamp, songDurationSlider]( ) {
int sec = song.GetMusicPos( ); int sec = 0;
songTimestamp->setText( songTimestamp->setText(
QTime( QTime(
@@ -269,7 +228,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
QSlider* VolumeSlider = new QSlider(Qt::Horizontal); QSlider* VolumeSlider = new QSlider(Qt::Horizontal);
VolumeSlider->setObjectName("volumeSlider"); VolumeSlider->setObjectName("volumeSlider");
VolumeSlider->setRange(0, 128); VolumeSlider->setRange(0, 128);
VolumeSlider->setValue(song.GetVolume( )); VolumeSlider->setValue(50);
VolumeSlider->setFixedHeight(28); VolumeSlider->setFixedHeight(28);
VolumeSlider->setStyleSheet(R"( VolumeSlider->setStyleSheet(R"(
QSlider#volumeSlider::groove:horizontal{ QSlider#volumeSlider::groove:horizontal{
@@ -295,7 +254,6 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
VolumeSlider->setCursor(Qt::PointingHandCursor); VolumeSlider->setCursor(Qt::PointingHandCursor);
connect(VolumeSlider, &QSlider::valueChanged, [this, VolumeSlider]( ) { connect(VolumeSlider, &QSlider::valueChanged, [this, VolumeSlider]( ) {
song.SetVolume(VolumeSlider->value( ));
}); });
rightLayout->addWidget(VolumeSlider); rightLayout->addWidget(VolumeSlider);

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
#include "../../../core/audio/audio.h" #include "../../../Controller/MusicPlayer/MusicPlayer.h"
#include "../../Tools/SvgToPixmap.hpp" #include "../../Tools/SvgToPixmap.hpp"
#include <QFrame> #include <QFrame>
@@ -9,6 +9,18 @@
#include <QObject> #include <QObject>
#include <filesystem> #include <filesystem>
#include <QStackedLayout> #include <QStackedLayout>
#include <QGraphicsDropShadowEffect>
#include <QGraphicsBlurEffect>
#include <QLayout>
#include <QWidget>
#include <QLabel>
#include <string>
#include <QPixmap>
#include <QtSvg>
#include <QSvgRenderer>
#include <QPainter>
#include <QMainWindow>
#include <QApplication>
enum Repeat : short; enum Repeat : short;
@@ -61,7 +73,7 @@ public:
return this->playPause; return this->playPause;
} }
FloatingControls(QWidget* parent = nullptr, std::filesystem::path path = std::filesystem::path( )); FloatingControls(QWidget* parent = nullptr);
~FloatingControls( ); ~FloatingControls( );
signals: signals:
@@ -82,6 +94,4 @@ private:
QPixmap albumArt; QPixmap albumArt;
int songPos; int songPos;
int songLength; int songLength;
Audio& song;
}; };

View File

@@ -20,7 +20,7 @@ bool CheckValidFile(std::filesystem::path path) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
MainWindow* w = argc > 1 && CheckValidFile(std::filesystem::path(argv[1])) ? new MainWindow(std::filesystem::path(argv[1])) : new MainWindow( ); MainWindow* w = argc > 1 && CheckValidFile(std::filesystem::path(argv[1])) ? new MainWindow(/*std::filesystem::path(argv[1])*/) : new MainWindow( );
w->setMinimumHeight(600); w->setMinimumHeight(600);
w->show( ); w->show( );