Add widget to seek through songs on an album
This commit is contained in:
42
src/components/tracklistWidget/tracklistwidget.cpp
Normal file
42
src/components/tracklistWidget/tracklistwidget.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#include "tracklistwidget.h"
|
||||
#include <QFileInfo>
|
||||
#include <QVBoxLayout>
|
||||
#include "src/data/cleanerScripts.h"
|
||||
|
||||
TrackListWidget::TrackListWidget(const QStringList& audioFiles, QWidget* parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
list_ = new QListWidget(this);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(this);
|
||||
layout->addWidget(list_);
|
||||
|
||||
int trackNum = 1;
|
||||
|
||||
for (const QString& f : audioFiles) {
|
||||
|
||||
// Extract just the filename
|
||||
QString fileName = QFileInfo(f).fileName();
|
||||
|
||||
// Run through your cleaner
|
||||
QString songTitle = cleanTrackTitle(fileName);
|
||||
|
||||
// Format display text: "1. Song Title"
|
||||
QString display = QString("%1. %2")
|
||||
.arg(trackNum++)
|
||||
.arg(songTitle);
|
||||
|
||||
list_->addItem(display);
|
||||
}
|
||||
|
||||
// Emit signal when clicked
|
||||
connect(list_, &QListWidget::itemClicked, this, [=](QListWidgetItem* item){
|
||||
int index = list_->row(item);
|
||||
emit trackSelected(index);
|
||||
});
|
||||
}
|
||||
|
||||
void TrackListWidget::setCurrentRow(int row)
|
||||
{
|
||||
list_->setCurrentRow(row);
|
||||
}
|
||||
23
src/components/tracklistWidget/tracklistwidget.h
Normal file
23
src/components/tracklistWidget/tracklistwidget.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef TRACKLISTWIDGET_H
|
||||
#define TRACKLISTWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QListWidget>
|
||||
|
||||
class TrackListWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TrackListWidget(const QStringList& audioFiles, QWidget* parent = nullptr);
|
||||
|
||||
void setCurrentRow(int row); // <-- THIS must be here
|
||||
|
||||
signals:
|
||||
void trackSelected(int index);
|
||||
|
||||
private:
|
||||
QListWidget* list_;
|
||||
};
|
||||
|
||||
#endif // TRACKLISTWIDGET_H
|
||||
Reference in New Issue
Block a user