Skip to content

Commit

Permalink
fix: should auto load playlist when using file>open
Browse files Browse the repository at this point in the history
Also fixed a bunch of clang-tidy and clazy issues
  • Loading branch information
BLumia committed Oct 23, 2024
1 parent 87c996f commit 28e9219
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 23 deletions.
6 changes: 3 additions & 3 deletions widget/instrumentsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "player.h"

InstrumentsModel::InstrumentsModel(Player * player, QObject *parent)
: m_player(player)
, QStringListModel(parent)
: QStringListModel(parent)
, m_player(player)
{

}
Expand Down Expand Up @@ -39,7 +39,7 @@ bool InstrumentsModel::setData(const QModelIndex &index, const QVariant &value,

QVariant InstrumentsModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) return QVariant();
if (!index.isValid()) return {};

if (role == Qt::CheckStateRole) return m_mutedInstruments.contains(index) ? Qt::Unchecked : Qt::Checked;

Expand Down
8 changes: 4 additions & 4 deletions widget/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ int main(int argc, char *argv[])

QTranslator translator;
if (translator.load(QLocale(), QLatin1String("pineapple-tracker-player"), QLatin1String("_"), QLatin1String(":/i18n"))) {
app.installTranslator(&translator);
QApplication::installTranslator(&translator);
}

QCommandLineParser parser;
parser.addPositionalArgument("File list", QCoreApplication::translate("main", "File list."));
parser.addHelpOption();
parser.process(app);

QStringList urlStrList = parser.positionalArguments();
QList<QUrl> urlsToLoad = Util::convertToUrlList(urlStrList);
const QStringList urlStrList = parser.positionalArguments();
const QList<QUrl> urlsToLoad = Util::convertToUrlList(urlStrList);

MainWindow w;
w.show();

w.playFiles(urlsToLoad);

return app.exec();
return QApplication::exec();
}
13 changes: 6 additions & 7 deletions widget/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ MainWindow::MainWindow(QWidget *parent)
, m_player(new Player(this))
, m_playlistManager(new PlaylistManager(this))
, m_instrumentsModel(new InstrumentsModel(m_player, this))
, m_playlistFilderModel(new QSortFilterProxyModel(this))
, m_playlistFilterModel(new QSortFilterProxyModel(this))
{
ui->setupUi(this);
ui->plainTextEdit->setFont(Util::defaultMonoFont());
ui->instrumentsListView->setFont(Util::defaultMonoFont());
ui->instrumentsListView->setModel(m_instrumentsModel);
m_playlistFilderModel->setSourceModel(m_playlistManager->model());
ui->playlistView->setModel(m_playlistFilderModel);
m_playlistFilterModel->setSourceModel(m_playlistManager->model());
ui->playlistView->setModel(m_playlistFilterModel);
setWindowIcon(QIcon(":/icons/dist/pineapple-tracker-player.svg"));

m_playlistManager->setAutoLoadFilterSuffixes({"*.xm", "*.it", "*.mod", "*.s3m", "*.mptm"});
Expand Down Expand Up @@ -128,8 +128,7 @@ MainWindow::MainWindow(QWidget *parent)
this, "Select module file", {},
"Module Files (*.xm *.it *.mod *.s3m *.mptm)");
if (url.isValid()) {
m_player->load(url);
m_player->play();
playFiles({url});
}
});

Expand Down Expand Up @@ -205,7 +204,7 @@ void MainWindow::on_playlistBtn_clicked()

void MainWindow::on_playlistView_activated(const QModelIndex &index)
{
QModelIndex sourceIndex(m_playlistFilderModel->mapToSource(index));
QModelIndex sourceIndex(m_playlistFilterModel->mapToSource(index));
m_playlistManager->setCurrentIndex(sourceIndex);
playFiles({m_playlistManager->urlByIndex(sourceIndex)});
}
Expand Down Expand Up @@ -242,7 +241,7 @@ void MainWindow::on_actionAbout_triggered()

void MainWindow::on_filterEdit_textChanged(const QString &arg1)
{
m_playlistFilderModel->setFilterFixedString(arg1);
m_playlistFilterModel->setFilterFixedString(arg1);
}


Expand Down
6 changes: 3 additions & 3 deletions widget/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class MainWindow : public QMainWindow

Q_PROPERTY(RepeatMode repeatMode MEMBER m_repeatMode NOTIFY repeatModeChanged)

MainWindow(QWidget *parent = nullptr);
~MainWindow();
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow() override;

void playFiles(const QList<QUrl> &urls);

Expand All @@ -56,6 +56,6 @@ private slots:
Player * m_player = nullptr;
PlaylistManager * m_playlistManager = nullptr;
InstrumentsModel * m_instrumentsModel = nullptr;
QSortFilterProxyModel * m_playlistFilderModel = nullptr;
QSortFilterProxyModel * m_playlistFilterModel = nullptr;
RepeatMode m_repeatMode = Repeat;
};
6 changes: 2 additions & 4 deletions widget/trackerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ TrackerWidget::TrackerWidget(QWidget *parent)
}

TrackerWidget::~TrackerWidget()
{

}
= default;

void TrackerWidget::paintEvent(QPaintEvent *event)
{
Expand All @@ -34,7 +32,7 @@ void TrackerWidget::paintEvent(QPaintEvent *event)
const int offset = (i - curRow) * fontHeight;
QStringList curRow(patternContent().at(i));
std::transform(curRow.cbegin(), curRow.cend(), curRow.begin(),
[](const QString from) -> const QString { return from.first(3); });
[](const QString& from) -> QString { return from.first(3); });
painter.drawText(0, centerY + offset, width(), fontHeight,
Qt::AlignCenter, curRow.join(QStringLiteral(" ")));
}
Expand Down
4 changes: 2 additions & 2 deletions widget/trackerwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class TrackerWidget : public QWidget

public:
explicit TrackerWidget(QWidget *parent = nullptr);
~TrackerWidget();
~TrackerWidget() override;

QVector<QStringList> patternContent() { return m_patternContent.value(); }
QVector<QStringList> patternContent() const { return m_patternContent.value(); }
void setPatternContent(const QVector<QStringList> & content) { m_patternContent = content; }
QBindable<QVector<QStringList>> bindablePatternContent() { return &m_patternContent; }

Expand Down

0 comments on commit 28e9219

Please sign in to comment.