diff options
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r-- | qmidiplayer-desktop/qmpmainwindow.cpp | 8 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpplistwindow.cpp | 58 | ||||
-rw-r--r-- | qmidiplayer-desktop/qmpplistwindow.hpp | 8 |
3 files changed, 56 insertions, 18 deletions
diff --git a/qmidiplayer-desktop/qmpmainwindow.cpp b/qmidiplayer-desktop/qmpmainwindow.cpp index 456ae60..41c42c6 100644 --- a/qmidiplayer-desktop/qmpmainwindow.cpp +++ b/qmidiplayer-desktop/qmpmainwindow.cpp @@ -361,6 +361,8 @@ void qmpMainWindow::switchTrack(QString s, bool interrupt) QString fns = s; setWindowTitle(QUrl::fromLocalFile(fns).fileName().left(QUrl::fromLocalFile(fns).fileName().lastIndexOf('.')) + " - QMidiPlayer"); ui->lbFileName->setText(QUrl::fromLocalFile(fns).fileName().left(QUrl::fromLocalFile(fns).fileName().lastIndexOf('.'))); + if (plistw->getCurrentItem() != fns) + plistw->setCurrentItem(fns); onfnChanged(); if (!loadFile(fns)) return; @@ -687,7 +689,7 @@ void qmpMainWindow::on_pbNext_clicked() void qmpMainWindow::selectionChanged() { - switchTrack(plistw->getSelectedItem()); + switchTrack(plistw->getCurrentItem()); } void qmpMainWindow::on_lbFileName_customContextMenuRequested(const QPoint &pos) @@ -793,8 +795,8 @@ void qmpMainWindow::startRender() free(ifstr); #else fluidrenderer = new qmpFileRendererFluid( - plistw->getSelectedItem().toStdString().c_str(), - (plistw->getSelectedItem() + QString(".wav")).toStdString().c_str() + plistw->getCurrentItem().toStdString().c_str(), + (plistw->getCurrentItem() + QString(".wav")).toStdString().c_str() ); playerSetup(fluidrenderer); fluidrenderer->renderInit(); diff --git a/qmidiplayer-desktop/qmpplistwindow.cpp b/qmidiplayer-desktop/qmpplistwindow.cpp index 59bea38..3a1062e 100644 --- a/qmidiplayer-desktop/qmpplistwindow.cpp +++ b/qmidiplayer-desktop/qmpplistwindow.cpp @@ -262,7 +262,7 @@ QString qmpPlistWindow::getFirstItem(bool a) int id = 0; if (shuffle && !a) id = rand() % ui->lwFiles->count(); - ui->lwFiles->setCurrentRow(id); + setCurrentItem(ui->lwFiles->item(id)); return ui->lwFiles->item(id)->text(); } QString qmpPlistWindow::getLastItem(bool a) @@ -272,50 +272,72 @@ QString qmpPlistWindow::getLastItem(bool a) int id = ui->lwFiles->count() - 1; if (shuffle && !a) id = rand() % ui->lwFiles->count(); - ui->lwFiles->setCurrentRow(id); + setCurrentItem(ui->lwFiles->item(id)); return ui->lwFiles->item(id)->text(); } QString qmpPlistWindow::getNextItem() { - if (ui->lwFiles->count() == 0) + if (ui->lwFiles->count() == 0 || getCurrentItemIndex() == -1) return QString(); if (repeat == 1) - return ui->lwFiles->item(ui->lwFiles->currentRow())->text(); - int id = ui->lwFiles->currentRow(); + return ui->lwFiles->item(getCurrentItemIndex())->text(); + int id = getCurrentItemIndex(); ++id; id %= ui->lwFiles->count(); if (shuffle) id = rand() % ui->lwFiles->count(); - ui->lwFiles->setCurrentRow(id); + setCurrentItem(ui->lwFiles->item(id)); return ui->lwFiles->item(id)->text(); } QString qmpPlistWindow::getPrevItem() { - if (ui->lwFiles->count() == 0) + if (ui->lwFiles->count() == 0 || getCurrentItemIndex() == -1) return QString(); if (repeat == 1) return ui->lwFiles->item(ui->lwFiles->currentRow())->text(); - int id = ui->lwFiles->currentRow(); + int id = getCurrentItemIndex(); --id; id < 0 ? id += ui->lwFiles->count() : 0; if (shuffle) id = rand() % ui->lwFiles->count(); - ui->lwFiles->setCurrentRow(id); + setCurrentItem(ui->lwFiles->item(id)); return ui->lwFiles->item(id)->text(); } -QString qmpPlistWindow::getSelectedItem() +QString qmpPlistWindow::getCurrentItem() { - if (ui->lwFiles->count() == 0) + if (ui->lwFiles->count() == 0 || getCurrentItemIndex() == -1) return QString(); - return ui->lwFiles->item(ui->lwFiles->currentRow())->text(); + return ui->lwFiles->item(getCurrentItemIndex())->text(); } +void qmpPlistWindow::setCurrentItem(QString item) +{ + for (int i = 0; i < ui->lwFiles->count(); ++i) + { + if (ui->lwFiles->item(i)->text() == item) + ui->lwFiles->item(i)->setData(Qt::ItemDataRole::BackgroundRole, QBrush(QColor(160, 160, 160))); + else + ui->lwFiles->item(i)->setData(Qt::ItemDataRole::BackgroundRole, QVariant()); + } +} +void qmpPlistWindow::setCurrentItem(QListWidgetItem *item) +{ + for (int i = 0; i < ui->lwFiles->count(); ++i) + { + if (ui->lwFiles->item(i) == item) + ui->lwFiles->item(i)->setData(Qt::ItemDataRole::BackgroundRole, QBrush(QColor(160, 160, 160))); + else + ui->lwFiles->item(i)->setData(Qt::ItemDataRole::BackgroundRole, QVariant()); + } +} + int qmpPlistWindow::getRepeat() { return repeat; } -void qmpPlistWindow::on_lwFiles_itemDoubleClicked() +void qmpPlistWindow::on_lwFiles_itemDoubleClicked(QListWidgetItem *item) { + setCurrentItem(item); emit selectionChanging(); } @@ -376,6 +398,16 @@ void qmpPlistWindow::on_pbLoad_clicked() } delete plist; } + +int qmpPlistWindow::getCurrentItemIndex() +{ + for (int i = 0; i < ui->lwFiles->count(); ++i) + { + if (ui->lwFiles->item(i)->data(Qt::ItemDataRole::BackgroundRole).value<QBrush>().color() == QColor(160, 160, 160)) + return i; + } + return -1; +} qmpPlistFunc::qmpPlistFunc(qmpPlistWindow *par) { p = par; diff --git a/qmidiplayer-desktop/qmpplistwindow.hpp b/qmidiplayer-desktop/qmpplistwindow.hpp index 7d93345..3525f91 100644 --- a/qmidiplayer-desktop/qmpplistwindow.hpp +++ b/qmidiplayer-desktop/qmpplistwindow.hpp @@ -44,7 +44,9 @@ public: QString getLastItem(bool a = false); QString getNextItem(); QString getPrevItem(); - QString getSelectedItem(); + QString getCurrentItem(); + void setCurrentItem(QString item); + void setCurrentItem(QListWidgetItem *item); void emptyList(); void insertItem(QString i); void insertItems(QStringList il); @@ -59,7 +61,7 @@ private slots: void on_pbClear_clicked(); void on_pbRepeat_clicked(); void on_pbShuffle_clicked(); - void on_lwFiles_itemDoubleClicked(); + void on_lwFiles_itemDoubleClicked(QListWidgetItem *item); void on_pbSave_clicked(); void on_pbLoad_clicked(); @@ -68,6 +70,8 @@ private: Ui::qmpPlistWindow *ui; int shuffle, repeat; //rep 0=off 1=one 2=all qmpSettings *settings; + + int getCurrentItemIndex(); }; #endif // QMPPLISTWINDOW_H |