-
Notifications
You must be signed in to change notification settings - Fork 0
/
QPlaylist.cpp
59 lines (43 loc) · 1.48 KB
/
QPlaylist.cpp
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
#include "QPlaylist.h"
#define title "Song List"
QPlaylist::QPlaylist(QWidget* parent, Qt::WindowFlags flags): QDockWidget(title, parent, flags)
{
setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
//Demo playlist
playlist = new QListWidget();
// playlist->addItem(new QListWidgetItem("Song 1"));
// playlist->addItem(new QListWidgetItem("Song 2"));
// playlist->addItem(new QListWidgetItem("Song 5"));
// playlist->addItem(new QListWidgetItem("Song 4"));
// playlist->addItem(new QListWidgetItem("Song 3"));
this->setWidget(playlist);
playlist->installEventFilter(this);
playlist->viewport()->installEventFilter(this);
}
void QPlaylist::clearPlaylist()
{
playlist->clear();
}
void QPlaylist::pushSong(QString songName)
{
playlist->addItem(new QListWidgetItem(songName));
}
void QPlaylist::setSongSelected(int row)
{
playlist->setCurrentRow(row);
}
bool QPlaylist::eventFilter(QObject* o, QEvent* e)
{
bool ret = false;
if( o == this->playlist &&( e->type() == QEvent::KeyPress || e->type() == QEvent::KeyRelease ) )
{
ret = true;
}
else if( o == this->playlist->viewport() && ( e->type() == QEvent::MouseButtonPress || e->type() == QEvent::MouseButtonRelease || e->type() == QEvent::MouseButtonDblClick || e->type() == QEvent::MouseMove || e->type() == QEvent::MouseTrackingChange ) )
{
ret = true;
}
return ret;
}
#include "QPlaylist.moc"