-
Notifications
You must be signed in to change notification settings - Fork 0
/
SongListScreen.cpp
129 lines (97 loc) · 2.94 KB
/
SongListScreen.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
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
#include "SongListScreen.h"
#include "ui_SongListScreen.h"
#include <QScrollArea>
#include <QScrollBar>
#include <QGridLayout>
#include <QLabel>
#include <QDebug>
#include "PlaylistGroup.h"
SongListScreen::SongListScreen(QWidget *parent) :
QWidget(parent),
ui(new Ui::SongListScreen)
{
ui->setupUi(this);
playlist_ = new Playlist();
qDebug() << "Songlist init";
// Fake up a grid to scroll
QWidget *client = new QWidget(this);
client->setObjectName("client");
QGridLayout *gl = new QGridLayout(client);
// int ctr = 0;
// const int LENGTH = 3;
// for(int i = 0; i < LENGTH; ++i){
// PlaylistGroup* p = new PlaylistGroup("Playlist: " + QString::number(i));
// p->setFixedHeight(410);
// p->setFixedWidth(810);
// gl->addWidget(p, i, 0);
// gl->setSpacing(80);
// ++ctr;
// }
client->setLayout(gl);
// Put it into a scroll area
QScrollArea *area = new QScrollArea(this);
area->setObjectName("scroll");
area->setWidgetResizable(true);
area->setWidget(client);
area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// PlaylistGroup* p = new PlaylistGroup("Playlist: " + QString::number(1));
// p->update();
// p->setFixedHeight(410);
// p->setFixedWidth(810);
// gl->addWidget(p, 0, 0);
// gl->setSpacing(80);
// qDebug() << "after;size: " << gl->count();
// Make the scroll step the same width as the fixed widgets in the grid
area->horizontalScrollBar()->setSingleStep(client->width() / 24);
QVBoxLayout *layout = new QVBoxLayout(this);
QLabel* l = new QLabel("Select a song to play", this);
l->setStyleSheet("color:white;");
layout->addWidget(l);
layout->addWidget(area);
setLayout(layout);
client->setStyleSheet("background-color: black;");
// area->setStyleSheet("background-color:white;");
area->setAlignment(Qt::AlignCenter);
}
SongListScreen::~SongListScreen()
{
delete ui;
}
Playlist* SongListScreen::playlist()
{
return playlist_;
}
void SongListScreen::loadPlaylist()
{
if(playlist_== nullptr){
// playlist must first be loaded.
qDebug() << "null right now.";
return;
}
QGridLayout* g = static_cast<QGridLayout*>(grid());
clear(g); // remove current group.
PlaylistGroup* group = new PlaylistGroup(playlist_->title());
group->loadPlaylist(playlist_);
g->addWidget(group);
}
void SongListScreen::setPlaylist(Playlist* playlist)
{
playlist_ = playlist;
}
QLayout* SongListScreen::grid()
{
for(int i = 0, end = layout()->count(); i < end; ++i){
if(layout()->itemAt(i)->widget()->objectName() == "scroll"){
return layout()->itemAt(i)->widget()->findChild<QWidget *>("client")->layout();
}
}
return nullptr;
}
void SongListScreen::clear(QGridLayout *&g)
{
if (g != 0){
QLayoutItem *item;
while ((item = g->takeAt(0)) != 0)
g->removeItem (item);
}
}