Skip to content

Commit

Permalink
ready to properly implement floatingControll, SDL2 will be the backen…
Browse files Browse the repository at this point in the history
…d until I figure out ffmpeg and another lib to play sound, SDL2_mixer errors on ubuntu based because its outdated?
  • Loading branch information
Crylia committed Mar 26, 2024
1 parent 17c44f8 commit 8644976
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 75 deletions.
10 changes: 0 additions & 10 deletions src/View/MainWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,4 @@ MainWidget::MainWidget(QWidget* parent)
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( ) { }
5 changes: 0 additions & 5 deletions src/View/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,4 @@ MainWindow::MainWindow(QWidget* parent)
setupMainWindow( );
}

MainWindow::MainWindow(std::filesystem::path path, QWidget* parent)
: QMainWindow(parent), mainWidget(new MainWidget(path, this)) {
setupMainWindow( );
}

MainWindow::~MainWindow( ) { }
68 changes: 13 additions & 55 deletions src/View/Modules/FloatingControls/FloatingControls.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
#include <iostream>

#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 {
ALL,
Expand Down Expand Up @@ -40,16 +29,15 @@ static QPushButton* makeSongControlButton(QString name, QSize size = QSize(36, 3
return button;
}
FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path) :
FloatingControls::FloatingControls(QWidget* parent) :
QFrame(parent),
volume(100),
albumArtPath("default.png"),
fullscreen(false), shuffle(false),
playPause(false),
songRepeat(NONE),
artist("Artist"),
songName("Song"),
song(Audio::getInstance( )) {
songName("Song") {
this->setFixedHeight(100);
this->setObjectName("main");
this->setStyleSheet(R"(
Expand Down Expand Up @@ -79,13 +67,13 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
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);
// Artist and Song name layout
QVBoxLayout* artistSongLayout = new QVBoxLayout( );
QLabel* artist = new QLabel(QString::fromStdString(song.GetArtist( )));
QLabel* artist = new QLabel("");
artist->setMinimumWidth(50);
connect(this, &FloatingControls::artistChanged, artist, &QLabel::setText);
artist->setObjectName("artist");
Expand All @@ -100,7 +88,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
QLabel* songName = new QLabel( );
songName->setMinimumWidth(50);
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);
songName->setObjectName("title");
Expand Down Expand Up @@ -133,26 +121,9 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
col = "#D7D7D7";
QPushButton* pb = makeSongControlButton(buttonNames[i], QSize(36, 36), col);
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);
}
Expand All @@ -163,12 +134,6 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
// Song timestamp
QLabel* songTimestamp = new QLabel("00:00");
songTimestamp->setText(
QTime(
0,
song.GetMusicPos( ) / 60,
song.GetMusicPos( ) % 60
).toString("mm:ss"));
songTimestamp->setObjectName("songTimestamp");
songTimestamp->setStyleSheet(R"(
QLabel#songTimestamp{
Expand All @@ -180,12 +145,6 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
// Song duration
QLabel* songDuration = new QLabel("00:00");
songDuration->setText(
QTime(
0,
song.GetMusicDuration( ) / 60,
song.GetMusicDuration( ) % 60
).toString("mm:ss"));
songDuration->setObjectName("songDuration");
songDuration->setStyleSheet(R"(
QLabel#songDuration{
Expand All @@ -197,8 +156,8 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
// Song duration slider
QSlider* songDurationSlider = new QSlider(Qt::Horizontal);
songDurationSlider->setObjectName("songDurationSlider");
songDurationSlider->setRange(0, song.GetMusicDuration( ));
songDurationSlider->setValue(song.GetMusicPos( ));
songDurationSlider->setRange(0, 100);
songDurationSlider->setValue(50);
songDurationSlider->setFixedHeight(28);
songDurationSlider->setStyleSheet(R"(
QSlider#songDurationSlider::groove:horizontal{
Expand All @@ -224,7 +183,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
songDurationSlider->setCursor(Qt::PointingHandCursor);
connect(songDurationSlider, &QSlider::sliderReleased, [this, songDurationSlider]( ) {
song.SetMusicPos(songDurationSlider->value( ));
});
songScrollerLayout->addWidget(songTimestamp);
Expand All @@ -234,7 +193,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
QTimer* timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, [this, songTimestamp, songDurationSlider]( ) {
int sec = song.GetMusicPos( );
int sec = 0;
songTimestamp->setText(
QTime(
Expand Down Expand Up @@ -269,7 +228,7 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
QSlider* VolumeSlider = new QSlider(Qt::Horizontal);
VolumeSlider->setObjectName("volumeSlider");
VolumeSlider->setRange(0, 128);
VolumeSlider->setValue(song.GetVolume( ));
VolumeSlider->setValue(50);
VolumeSlider->setFixedHeight(28);
VolumeSlider->setStyleSheet(R"(
QSlider#volumeSlider::groove:horizontal{
Expand All @@ -295,7 +254,6 @@ FloatingControls::FloatingControls(QWidget* parent, std::filesystem::path path)
VolumeSlider->setCursor(Qt::PointingHandCursor);
connect(VolumeSlider, &QSlider::valueChanged, [this, VolumeSlider]( ) {
song.SetVolume(VolumeSlider->value( ));
});
rightLayout->addWidget(VolumeSlider);
Expand Down
18 changes: 14 additions & 4 deletions src/View/Modules/FloatingControls/FloatingControls.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include "../../../core/audio/audio.h"
#include "../../../Controller/MusicPlayer/MusicPlayer.h"
#include "../../Tools/SvgToPixmap.hpp"

#include <QFrame>
Expand All @@ -9,6 +9,18 @@
#include <QObject>
#include <filesystem>
#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;

Expand Down Expand Up @@ -61,7 +73,7 @@ class FloatingControls : public QFrame {
return this->playPause;
}

FloatingControls(QWidget* parent = nullptr, std::filesystem::path path = std::filesystem::path( ));
FloatingControls(QWidget* parent = nullptr);
~FloatingControls( );

signals:
Expand All @@ -82,6 +94,4 @@ class FloatingControls : public QFrame {
QPixmap albumArt;
int songPos;
int songLength;

Audio& song;
};
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool CheckValidFile(std::filesystem::path path) {

int main(int argc, char* 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->show( );

Expand Down

0 comments on commit 8644976

Please sign in to comment.