-
Notifications
You must be signed in to change notification settings - Fork 0
/
playlistselector.cpp
55 lines (45 loc) · 1.49 KB
/
playlistselector.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
#include <QStringListModel>
#include "playlistselector.hpp"
#include "ui_playlistselector.h"
PlaylistSelector::PlaylistSelector(QStringList playlistNames,
QAbstractItemView::SelectionMode selectionMode,
QWidget *parent)
: QWidget(parent)
, ui(new Ui::PlaylistSelector)
, m_playlistNames(playlistNames)
{
ui->setupUi(this);
auto *model = new QStringListModel(playlistNames, this);
ui->listView->setModel(model);
ui->listView->setEditTriggers(QListView::NoEditTriggers);
ui->listView->setSelectionMode(selectionMode);
ui->listView->setSelectionBehavior(QAbstractItemView::SelectItems);
connect(ui->listView, &QListView::doubleClicked, this, &PlaylistSelector::doubleClicked);
connect(ui->selectButton, &QPushButton::clicked, this, &PlaylistSelector::onSelectButtonClicked);
}
PlaylistSelector::~PlaylistSelector()
{
delete ui;
}
QStringList PlaylistSelector::getSelection() const
{
return m_selection;
}
void PlaylistSelector::closeEvent(QCloseEvent *event)
{
emit closed();
QWidget::closeEvent(event);
}
void PlaylistSelector::doubleClicked(const QModelIndex &index)
{
m_selection.append(index.data().toString());
close();
}
void PlaylistSelector::onSelectButtonClicked()
{
auto selectedIndexes = ui->listView->selectionModel()->selectedIndexes();
for (auto selectedIndex : selectedIndexes) {
m_selection << selectedIndex.data().toString();
}
close();
}