-
Notifications
You must be signed in to change notification settings - Fork 0
/
QStationsList.cpp
56 lines (41 loc) · 1.56 KB
/
QStationsList.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
#include "QStationsList.h"
#include <QListWidget>
#include <qlayout.h>
#include <QDockWidget>
#define title "Stations List"
QStationsList::QStationsList(QWidget* parent, Qt::WindowFlags flags): QDockWidget(title, parent, flags)
{
setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable);
}
void QStationsList::setStations(std::vector< PandoraStation > stations)
{
this->stations = stations;
stationList = new QListWidget();
stationList->setSortingEnabled(true);
//TODO: Make custom QLIstWidgetItem class to have custom sorting
// QuickMixes and Genre Stations at top.
for(std::vector<PandoraStation>::size_type i = 0; i != stations.size(); i++){
stationList->addItem(new QListWidgetItem(stations[i].toString()));
}
this->setWidget(stationList);
connect(stationList, SIGNAL(itemActivated(QListWidgetItem*)), SLOT(onNewStationSelect()));
}
void QStationsList::onNewStationSelect()
{
if(stationList->currentRow() == -1){
//NO ITEM SELECTED, sanity check
std::cout << "No station selected" << std::endl;
}else{
for(std::vector<PandoraStation>::size_type i = 0; i != stations.size(); i++){
QListWidgetItem* selectedItem = stationList->currentItem();
if(selectedItem->text() == stations[i].toString()){
//std::cout << "You selected: " << stations[i].toString() << std::endl;
this->selectedStation = &stations[i];
break;
}
}
}
std::cout << "Station Change" << std::endl;
}
#include "QStationsList.moc"