Add volume slider, time played widget, and pause/play on album art click

This commit is contained in:
2025-11-19 23:30:03 -07:00
parent d4c1dbc8bd
commit 7494e5095d
18 changed files with 322 additions and 21 deletions

View File

@@ -80,3 +80,9 @@ void SpinningAlbumArt::updateRotation()
artLabel_->setPixmap(frame);
}
void SpinningAlbumArt::mousePressEvent(QMouseEvent* event)
{
emit artClicked();
QWidget::mousePressEvent(event);
}

View File

@@ -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

View 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");
}

View 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