From 6d25c63f29103f53fc151de0f2dfa91fdb852093 Mon Sep 17 00:00:00 2001 From: aqua Date: Sun, 8 Jan 2023 13:22:41 +0200 Subject: Initial commit --- src/fsview.cpp | 50 +++++++++++++++++++++++++++ src/fsview.hpp | 30 ++++++++++++++++ src/main.cpp | 15 ++++++++ src/maindialog.cpp | 44 +++++++++++++++++++++++ src/maindialog.hpp | 29 ++++++++++++++++ src/maindialog.ui | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 268 insertions(+) create mode 100644 src/fsview.cpp create mode 100644 src/fsview.hpp create mode 100644 src/main.cpp create mode 100644 src/maindialog.cpp create mode 100644 src/maindialog.hpp create mode 100644 src/maindialog.ui (limited to 'src') diff --git a/src/fsview.cpp b/src/fsview.cpp new file mode 100644 index 0000000..3e9495e --- /dev/null +++ b/src/fsview.cpp @@ -0,0 +1,50 @@ +/* ============================================================ + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2023 aqua + * ============================================================ */ + +#include "fsview.hpp" +#include +#include + +FSView::FSView(QWidget *parent) : QTreeView(parent), model{new QFileSystemModel} +{ + setModel(model); + setRootPath(QDir::homePath()); + + connect(this, &QWidget::customContextMenuRequested, this, &FSView::contextMenu); + setContextMenuPolicy(Qt::CustomContextMenu); +} + +FSView::~FSView() { delete model; } + +void FSView::setRootPath(const QString &path) +{ + model->setRootPath(path); + setRootIndex(model->index(path)); +} + +void FSView::contextMenu(const QPoint &pos) +{ + const auto idx = indexAt(pos); + if (idx.isValid()) { + QMenu menu; + + if (model->isDir(idx)) { + menu.addAction(tr("Set as root"), this, [this, idx]() { + const auto path = model->filePath(idx); + qDebug() << "set root path" << path; + model->setRootPath(path); + setRootIndex(idx); + }); + } + else { + menu.addAction(tr("Add to Playlist"), this, [this, idx]() { + const auto url = QUrl::fromLocalFile(model->filePath(idx)); + emit addLocalFile(url); + }); + } + + menu.exec(mapToGlobal(pos)); + } +} diff --git a/src/fsview.hpp b/src/fsview.hpp new file mode 100644 index 0000000..eea61c7 --- /dev/null +++ b/src/fsview.hpp @@ -0,0 +1,30 @@ +/* ============================================================ + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2023 aqua + * ============================================================ */ + +#pragma once + +#include +#include + +class QFileSystemModel; +class FSView : public QTreeView { + Q_OBJECT + +public: + FSView(QWidget *parent = nullptr); + ~FSView(); + +signals: + void addLocalFile(const QUrl &url); + +public slots: + void setRootPath(const QString &path); + +private slots: + void contextMenu(const QPoint &pos); + +private: + QFileSystemModel *model; +}; diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..1fedca7 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,15 @@ +/* ============================================================ + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2023 aqua + * ============================================================ */ + +#include "maindialog.hpp" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainDialog w; + w.show(); + return a.exec(); +} diff --git a/src/maindialog.cpp b/src/maindialog.cpp new file mode 100644 index 0000000..ee6fdd7 --- /dev/null +++ b/src/maindialog.cpp @@ -0,0 +1,44 @@ +/* ============================================================ + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2023 aqua + * ============================================================ */ + +#include "maindialog.hpp" +#include "playlist.hpp" +#include "playlistmodel.hpp" +#include "ui_maindialog.h" +#include +#include +#include + +MainDialog::MainDialog(QWidget *parent) + : QDialog(parent), ui(new Ui::MainDialog), + m_playlist(new Playlist(this)), m_player{new QMediaPlayer(this)}, m_audioSink{new QAudioOutput(this)} +{ + m_player->setAudioOutput(m_audioSink); + m_audioSink->setVolume(50); + + ui->setupUi(this); + ui->playlist->setModel(m_playlist->model()); + + connect(ui->fsSetRoot, &QPushButton::clicked, this, [this]() { + const auto root = QFileDialog::getExistingDirectory(this, tr("Set Root"), QDir::homePath()); + if (!root.isEmpty()) ui->fsView->setRootPath(root); + }); + + connect(m_player, &QMediaPlayer::durationChanged, ui->progress, &QSlider::setMaximum); + connect(m_player, &QMediaPlayer::positionChanged, ui->progress, &QSlider::setValue); + + connect(ui->fsView, &FSView::addLocalFile, m_playlist, &Playlist::appendUrl); + connect(ui->open, &QPushButton::clicked, this, [this]() { + const auto filelist = QFileDialog::getOpenFileUrls(this, tr("Open Files")); + m_playlist->appendList(filelist); + }); + connect(ui->playlist, &QListView::activated, this, [this](const QModelIndex &index) { + const auto url = m_playlist->model()->data(index, Qt::DisplayRole).toUrl(); + m_player->setSource(url); + m_player->play(); + }); +} + +MainDialog::~MainDialog() { delete ui; } diff --git a/src/maindialog.hpp b/src/maindialog.hpp new file mode 100644 index 0000000..db22b2e --- /dev/null +++ b/src/maindialog.hpp @@ -0,0 +1,29 @@ +/* ============================================================ + * SPDX-License-Identifier: GPL-3.0-only + * Copyright (C) 2023 aqua + * ============================================================ */ + +#pragma once + +#include + +namespace Ui { +class MainDialog; +} +class Playlist; +class QMediaPlayer; +class QAudioOutput; +class MainDialog : public QDialog { + Q_OBJECT + +public: + MainDialog(QWidget *parent = nullptr); + ~MainDialog(); + +private: + Ui::MainDialog *ui; + Playlist *m_playlist; + + QMediaPlayer *m_player; + QAudioOutput *m_audioSink; +}; diff --git a/src/maindialog.ui b/src/maindialog.ui new file mode 100644 index 0000000..c2cb900 --- /dev/null +++ b/src/maindialog.ui @@ -0,0 +1,100 @@ + + + MainDialog + + + + 0 + 0 + 800 + 600 + + + + MainDialog + + + + + + + + 1 + + + + Tab 1 + + + + + Tab 2 + + + + + + Set Root + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + + + + + + + + Open + + + + + + + Play + + + + + + + Stop + + + + + + + + + + FSView + QTreeView +
src/fsview.hpp
+
+
+ + +
-- cgit v1.2.1