aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop
diff options
context:
space:
mode:
authorGravatar Chris Xiong <chirs241097@gmail.com> 2020-08-05 00:19:31 +0800
committerGravatar Chris Xiong <chirs241097@gmail.com> 2020-08-05 00:19:31 +0800
commita3b10c29c5041a4706bd2e4badf25c3269909aa6 (patch)
treec81039121419cda080aa2aee700a49ced6694421 /qmidiplayer-desktop
parentdb54b5d51d5269c2e17964e0e9842f4a2f210673 (diff)
downloadQMidiPlayer-a3b10c29c5041a4706bd2e4badf25c3269909aa6.tar.xz
I can still code!
Next / Prev track is now selected based on the current track being played rather than the selected track in the playlist window. Also fixed stupid a mistype.
Diffstat (limited to 'qmidiplayer-desktop')
-rw-r--r--qmidiplayer-desktop/qmpmainwindow.cpp8
-rw-r--r--qmidiplayer-desktop/qmpplistwindow.cpp58
-rw-r--r--qmidiplayer-desktop/qmpplistwindow.hpp8
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