blob: 65c01f8408c42c5bc143ab8b2ad72f361bc20e7f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
#include <cstdlib>
#include <ctime>
#include <QFileDialog>
#include "qmpplistwindow.hpp"
#include "ui_qmpplistwindow.h"
#include "qmpmainwindow.hpp"
qmpplistwindow::qmpplistwindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::qmpplistwindow)
{
ui->setupUi(this);
connect(this,SIGNAL(dialogClosing()),parent,SLOT(dialogClosed()));
connect(this,SIGNAL(selectionChanging()),parent,SLOT(selectionChanged()));
repeat=0;shuffle=0;
}
qmpplistwindow::~qmpplistwindow()
{
delete ui;
}
void qmpplistwindow::closeEvent(QCloseEvent *event)
{
setVisible(false);
emit dialogClosing();
event->accept();
}
void qmpplistwindow::on_pbAdd_clicked()
{
QStringList sl=QFileDialog::getOpenFileNames(this,"Add File","","Midi files (*.mid *.midi)");
for(int i=0;i<sl.size();++i)
{
ui->lwFiles->addItem(new QListWidgetItem(sl.at(i)));
}
}
void qmpplistwindow::on_pbAddFolder_clicked()
{
QFileDialog::getExistingDirectory(this,"Add Folder");
//...
}
void qmpplistwindow::on_pbRemove_clicked()
{
QList<QListWidgetItem*> sl=ui->lwFiles->selectedItems();
for(int i=0;i<sl.size();++i)
{
ui->lwFiles->removeItemWidget(sl.at(i));
delete sl.at(i);
}
}
void qmpplistwindow::on_pbClear_clicked()
{
while(ui->lwFiles->count()>0)
{
QListWidgetItem *d=ui->lwFiles->item(0);
ui->lwFiles->removeItemWidget(d);
delete d;
}
}
void qmpplistwindow::on_pbRepeat_clicked()
{
++repeat;repeat%=3;
switch(repeat)
{
case 0:
ui->pbRepeat->setIcon(QIcon(":/img/repeat-non.png"));
ui->pbRepeat->setText("Repeat Off");
break;
case 1:
ui->pbRepeat->setIcon(QIcon(":/img/repeat-one.png"));
ui->pbRepeat->setText("Repeat One");
break;
case 2:
ui->pbRepeat->setIcon(QIcon(":/img/repeat-all.png"));
ui->pbRepeat->setText("Repeat All");
break;
}
}
void qmpplistwindow::on_pbShuffle_clicked()
{
shuffle=1-shuffle;
switch(shuffle)
{
case 1:
ui->pbShuffle->setIcon(QIcon(":/img/shuffle.png"));
ui->pbShuffle->setText("Shuffle On");
break;
case 0:
default:
ui->pbShuffle->setIcon(QIcon(":/img/shuffle-off.png"));
ui->pbShuffle->setText("Shuffle Off");
break;
}
}
QString qmpplistwindow::getFirstItem()
{
if(ui->lwFiles->count()==0)return QString();
int id=0;
if(shuffle)id=rand()%ui->lwFiles->count();
ui->lwFiles->setCurrentRow(id);
return ui->lwFiles->item(id)->text();
}
QString qmpplistwindow::getNextItem()
{
if(ui->lwFiles->count()==0)return QString();
if(repeat==1)return ui->lwFiles->item(ui->lwFiles->currentRow())->text();
int id=ui->lwFiles->currentRow();++id;id%=ui->lwFiles->count();
if(shuffle)id=rand()%ui->lwFiles->count();
ui->lwFiles->setCurrentRow(id);
return ui->lwFiles->item(id)->text();
}
QString qmpplistwindow::getPrevItem()
{
if(ui->lwFiles->count()==0)return QString();
if(repeat==1)return ui->lwFiles->item(ui->lwFiles->currentRow())->text();
int id=ui->lwFiles->currentRow();--id;
id<0?id+=ui->lwFiles->count():0;
if(shuffle)id=rand()%ui->lwFiles->count();
ui->lwFiles->setCurrentRow(id);
return ui->lwFiles->item(id)->text();
}
QString qmpplistwindow::getSelectedItem()
{
if(ui->lwFiles->count()==0)return QString();
return ui->lwFiles->item(ui->lwFiles->currentRow())->text();
}
int qmpplistwindow::getRepeat(){return repeat;}
void qmpplistwindow::on_lwFiles_itemDoubleClicked()
{
emit selectionChanging();
}
|