aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-desktop/qmpplistwindow.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'qmidiplayer-desktop/qmpplistwindow.cpp')
-rw-r--r--qmidiplayer-desktop/qmpplistwindow.cpp58
1 files changed, 45 insertions, 13 deletions
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;