Add volume slider, time played widget, and pause/play on album art click
This commit is contained in:
@@ -80,3 +80,9 @@ void SpinningAlbumArt::updateRotation()
|
||||
|
||||
artLabel_->setPixmap(frame);
|
||||
}
|
||||
|
||||
void SpinningAlbumArt::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
emit artClicked();
|
||||
QWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QTimer>
|
||||
#include <QMouseEvent>
|
||||
|
||||
class SpinningAlbumArt : public QWidget
|
||||
{
|
||||
@@ -16,9 +17,15 @@ public slots:
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
signals:
|
||||
void artClicked();
|
||||
|
||||
private slots:
|
||||
void updateRotation();
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent* event) override;
|
||||
|
||||
private:
|
||||
QPixmap discArt_; // circular-masked album image
|
||||
QLabel* artLabel_; // widget that displays the spinning frame
|
||||
|
||||
47
src/components/timePlayedWidget/timePlayedWidget.cpp
Normal file
47
src/components/timePlayedWidget/timePlayedWidget.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include "timePlayedWidget.h"
|
||||
|
||||
TimePlayedWidget::TimePlayedWidget(QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
label_ = new QLabel("00:00 / 00:00", this);
|
||||
label_->setAlignment(Qt::AlignCenter);
|
||||
label_->setStyleSheet("font-size: 12px; color: #666;");
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->setContentsMargins(0, 0, 0, 0);
|
||||
layout->addWidget(label_);
|
||||
}
|
||||
|
||||
QString TimePlayedWidget::formatTime(qint64 ms) const
|
||||
{
|
||||
int sec = ms / 1000;
|
||||
int min = sec / 60;
|
||||
int s = sec % 60;
|
||||
|
||||
return QString("%1:%2")
|
||||
.arg(min, 2, 10, QChar('0'))
|
||||
.arg(s, 2, 10, QChar('0'));
|
||||
}
|
||||
|
||||
void TimePlayedWidget::setDuration(qint64 ms)
|
||||
{
|
||||
duration_ = ms;
|
||||
}
|
||||
|
||||
void TimePlayedWidget::setPosition(qint64 ms)
|
||||
{
|
||||
if (duration_ > 0)
|
||||
{
|
||||
label_->setText(
|
||||
QString("%1 / %2")
|
||||
.arg(formatTime(ms))
|
||||
.arg(formatTime(duration_))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void TimePlayedWidget::reset()
|
||||
{
|
||||
duration_ = 0;
|
||||
label_->setText("00:00 / 00:00");
|
||||
}
|
||||
27
src/components/timePlayedWidget/timePlayedWidget.h
Normal file
27
src/components/timePlayedWidget/timePlayedWidget.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef TIMEPLAYEDWIDGET_H
|
||||
#define TIMEPLAYEDWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
class TimePlayedWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TimePlayedWidget(QWidget* parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void setDuration(qint64 ms);
|
||||
void setPosition(qint64 ms);
|
||||
void reset();
|
||||
|
||||
private:
|
||||
QLabel* label_;
|
||||
qint64 duration_ = 0;
|
||||
|
||||
QString formatTime(qint64 ms) const;
|
||||
};
|
||||
|
||||
#endif // TIMEPLAYEDWIDGET_H
|
||||
@@ -22,6 +22,17 @@ PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
|
||||
trackLabel_->setStyleSheet("font-size: 14px; font-weight: 500;");
|
||||
layout->addWidget(trackLabel_);
|
||||
|
||||
// Time played in Song Indicator
|
||||
timeIndicator_ = new TimePlayedWidget(this);
|
||||
layout->addWidget(timeIndicator_);
|
||||
|
||||
// Volume slider (NEW)
|
||||
volumeSlider_ = new QSlider(Qt::Horizontal);
|
||||
volumeSlider_->setRange(0, 100);
|
||||
volumeSlider_->setValue(80);
|
||||
volumeSlider_->setStyleSheet("margin: 0 12px;");
|
||||
layout->addWidget(volumeSlider_);
|
||||
|
||||
// Track list widget
|
||||
trackList_ = new TrackListWidget(item_.audioFiles, this);
|
||||
layout->addWidget(trackList_);
|
||||
@@ -31,6 +42,10 @@ PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
|
||||
audio_ = new QAudioOutput(this);
|
||||
player_->setAudioOutput(audio_);
|
||||
|
||||
audio_->setVolume(0.8f); // match slider
|
||||
connect(volumeSlider_, &QSlider::valueChanged, this,
|
||||
[this](int v){ audio_->setVolume(v / 100.0); });
|
||||
|
||||
// Spin album art based on playback
|
||||
connect(player_, &QMediaPlayer::playbackStateChanged, this,
|
||||
[this](QMediaPlayer::PlaybackState st){
|
||||
@@ -40,6 +55,24 @@ PlayerWindow::PlayerWindow(const AlbumData& item, QWidget* parent)
|
||||
spinningArt_->stop();
|
||||
});
|
||||
|
||||
// Get song duration and played time
|
||||
connect(player_, &QMediaPlayer::durationChanged,
|
||||
timeIndicator_, &TimePlayedWidget::setDuration);
|
||||
|
||||
connect(player_, &QMediaPlayer::positionChanged,
|
||||
timeIndicator_, &TimePlayedWidget::setPosition);
|
||||
|
||||
// Pause/Play on album art click
|
||||
connect(spinningArt_, &SpinningAlbumArt::artClicked, this, [this]() {
|
||||
if (player_->playbackState() == QMediaPlayer::PlayingState) {
|
||||
player_->pause();
|
||||
spinningArt_->stop();
|
||||
} else {
|
||||
player_->play();
|
||||
spinningArt_->start();
|
||||
}
|
||||
});
|
||||
|
||||
// When a track finishes, auto-play next
|
||||
connect(player_, &QMediaPlayer::mediaStatusChanged, this,
|
||||
[this](QMediaPlayer::MediaStatus st){
|
||||
|
||||
@@ -9,10 +9,13 @@
|
||||
#include "src/data/albumInformation.h"
|
||||
#include "src/components/spinningalbumart/spinningAlbumArt.h"
|
||||
#include "src/components/tracklistWidget/tracklistwidget.h"
|
||||
#include "src/components/timePlayedWidget/timePlayedWidget.h"
|
||||
|
||||
class PlayerWindow : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
QSlider* volumeSlider_;
|
||||
TimePlayedWidget* timeIndicator_;
|
||||
|
||||
public:
|
||||
explicit PlayerWindow(const AlbumData& item, QWidget* parent = nullptr);
|
||||
|
||||
Reference in New Issue
Block a user