diff --git a/widget/mainwindow.cpp b/widget/mainwindow.cpp index f2f1296..ea9ca1e 100644 --- a/widget/mainwindow.cpp +++ b/widget/mainwindow.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -24,12 +25,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)) { ui->setupUi(this); ui->plainTextEdit->setFont(Util::defaultMonoFont()); ui->instrumentsListView->setFont(Util::defaultMonoFont()); ui->instrumentsListView->setModel(m_instrumentsModel); - ui->playlistView->setModel(m_playlistManager->model()); + m_playlistFilderModel->setSourceModel(m_playlistManager->model()); + ui->playlistView->setModel(m_playlistFilderModel); setWindowIcon(QIcon(":/icons/dist/pineapple-tracker-player.svg")); m_playlistManager->setAutoLoadFilterSuffixes({"*.xm", "*.it", "*.mod", "*.s3m", "*.mptm"}); @@ -43,8 +46,8 @@ MainWindow::MainWindow(QWidget *parent) }); connect(m_player, &Player::fileLoaded, this, [this](){ - ui->horizontalSlider->setMaximum(m_player->totalOrders() - 1); - ui->horizontalSlider->setValue(m_player->currentOrder()); + ui->playbackSlider->setMaximum(m_player->totalOrders() - 1); + ui->playbackSlider->setValue(m_player->currentOrder()); ui->songTitle->setText(m_player->title()); const QString & artist = m_player->artist(); ui->label_4->setText(artist.isEmpty() ? m_player->tracker() : (m_player->artist() + " (" + m_player->tracker() + ")") ); @@ -58,8 +61,8 @@ MainWindow::MainWindow(QWidget *parent) }); connect(m_player, &Player::currentOrderChanged, this, [this](){ - QSignalBlocker sb(ui->horizontalSlider); - ui->horizontalSlider->setValue(m_player->currentOrder()); + QSignalBlocker sb(ui->playbackSlider); + ui->playbackSlider->setValue(m_player->currentOrder()); }); connect(m_player, &Player::currentRowChanged, this, [this](){ @@ -70,13 +73,30 @@ MainWindow::MainWindow(QWidget *parent) )); }); - connect(ui->horizontalSlider, &QSlider::valueChanged, this, [this](int value){ - m_player->seek(ui->horizontalSlider->value()); + connect(m_player, &Player::gainChanged, this, [this](){ + // only update the icon of the mute button here. + int32_t gain = m_player->gain(); + QString iconText; + if (gain < ui->volumeSlider->minimum()) { + // muted + iconText = "audio-volume-muted"; + } else if (gain <= -1000) { + iconText = "audio-volume-low"; + } else if (gain <= 0) { + iconText = "audio-volume-medium"; + } else { + iconText = "audio-volume-high"; + } + ui->muteButton->setIcon(QIcon::fromTheme(iconText)); + }); + + connect(ui->playbackSlider, &QSlider::valueChanged, this, [this](int value){ + m_player->seek(ui->playbackSlider->value()); QToolTip::showText(QCursor::pos(), QString::number(value), nullptr); }); - connect(ui->horizontalSlider_2, &QSlider::sliderMoved, this, [this](int value){ - m_player->setGain(ui->horizontalSlider_2->value()); + connect(ui->volumeSlider, &QSlider::sliderMoved, this, [this](int value){ + m_player->setGain(ui->volumeSlider->value()); QToolTip::showText(QCursor::pos(), QString("%1 dB").arg(value / 100.f), nullptr); }); @@ -149,8 +169,9 @@ void MainWindow::on_playlistBtn_clicked() void MainWindow::on_playlistView_activated(const QModelIndex &index) { - m_playlistManager->setCurrentIndex(index); - playFiles({m_playlistManager->urlByIndex(index)}); + QModelIndex sourceIndex(m_playlistFilderModel->mapToSource(index)); + m_playlistManager->setCurrentIndex(sourceIndex); + playFiles({m_playlistManager->urlByIndex(sourceIndex)}); } @@ -182,3 +203,22 @@ void MainWindow::on_actionAbout_triggered() infoBox.exec(); } + +void MainWindow::on_filterEdit_textChanged(const QString &arg1) +{ + m_playlistFilderModel->setFilterFixedString(arg1); +} + + +void MainWindow::on_muteButton_clicked() +{ + if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) { + m_player->setGain(0); + ui->volumeSlider->setValue(0); + return; + } + + bool isMuted = m_player->gain() < ui->volumeSlider->minimum(); + m_player->setGain(isMuted ? ui->volumeSlider->value() : std::numeric_limits::min()); +} + diff --git a/widget/mainwindow.h b/widget/mainwindow.h index e4abfc7..6656cd8 100644 --- a/widget/mainwindow.h +++ b/widget/mainwindow.h @@ -6,6 +6,7 @@ QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } class QDragEnterEvent; class QDropEvent; +class QSortFilterProxyModel; QT_END_NAMESPACE class Player; @@ -30,12 +31,14 @@ private slots: void on_messageBtn_clicked(); void on_playlistBtn_clicked(); void on_playlistView_activated(const QModelIndex &index); - void on_actionAbout_triggered(); + void on_filterEdit_textChanged(const QString &arg1); + void on_muteButton_clicked(); private: Ui::MainWindow *ui; Player * m_player = nullptr; PlaylistManager * m_playlistManager = nullptr; InstrumentsModel * m_instrumentsModel = nullptr; + QSortFilterProxyModel * m_playlistFilderModel = nullptr; }; diff --git a/widget/mainwindow.ui b/widget/mainwindow.ui index 46e2d62..f4eaf51 100644 --- a/widget/mainwindow.ui +++ b/widget/mainwindow.ui @@ -33,14 +33,14 @@ - + Qt::Orientation::Horizontal - + @@ -62,7 +62,20 @@ - + + + + + + + + + true + + + + + 90 @@ -70,7 +83,7 @@ - -1500 + -2000 1000 @@ -109,9 +122,15 @@ Playlist + + true + true + + buttonGroup + @@ -119,9 +138,18 @@ Message + + true + + + true + true + + buttonGroup + @@ -129,9 +157,15 @@ Instruments + + true + true + + buttonGroup + @@ -181,6 +215,16 @@ + + + + Type to filter by keyword + + + true + + + @@ -252,4 +296,7 @@ + + +