-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.cpp
188 lines (145 loc) · 5.67 KB
/
setup.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#ifndef SETUP_H
#define SETUP_H
#include "mainwindow.h"
#include <QHBoxLayout>
void MainWindow::setupButtons()
{
QHBoxLayout * buttons = new QHBoxLayout;
buttons->addWidget(_prevButton);
buttons->addWidget(_playButton);
buttons->addWidget(_nextButton);
//Setup signals
connect(_prevButton, SIGNAL(clicked()), this, SLOT(_prevButtonIsPressed()));
connect(_playButton, SIGNAL(clicked()), this, SLOT(_playButtonIsPressed()));
connect(_nextButton, SIGNAL(clicked()), this, SLOT(_nextButtonIsPressed()));
//Setup icons
_prevButton->setIcon(_prevButtonIcon);
_prevButton->setIconSize(QSize(_prevButton->height(),_prevButton->height()));
_playButton->setIcon(_playButtonPlayIcon);
_playButton->setIconSize(QSize(_playButton->height(),_playButton->height()));
_nextButton->setIcon(_nextButtonIcon);
_nextButton->setIconSize(QSize(_nextButton->height(),_nextButton->height()));
_mainLayout->addLayout(buttons);
}
void MainWindow::setupMenus()
{
createActions();
createMenus();
#ifdef __ANDROID__
QHBoxLayout * androidButtonLayout = new QHBoxLayout(this);
QPushButton * androidAddButton = new QPushButton("Add Music", this);
//QPushButton * androidExitButton = new QPushButton("Exit", this);
connect(androidAddButton, SIGNAL(clicked()), this, SLOT(addMedia()));
//connect(androidExitButton, SIGNAL(clicked()), this, SLOT(exit()));
androidButtonLayout->addWidget(androidAddButton);
//androidButtonLayout->addWidget(androidExitButton);
_mainLayout->addLayout(androidButtonLayout);
#endif
}
void MainWindow::setupMetadataLabel()
{
QHBoxLayout * metadata = new QHBoxLayout;
metadata->addWidget(_fileMetadata);
_mainLayout->addLayout(metadata);
}
void MainWindow::setupProgressBar()
{
QHBoxLayout * progBar = new QHBoxLayout;
progBar->addWidget(_progressBar);
_progressBar->setValue(0);
_progressBar->setTextVisible(false);
connect(_currentPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(playbackPositionChanged(qint64)));
connect(_currentPlayer, SIGNAL(durationChanged(qint64)),this, SLOT(durationHasChanged(qint64)));
_mainLayout->addLayout(progBar);
}
void MainWindow::setupPlaylistViewConnections(const QListWidget * playlistView)
{
connect
(
playlistView,
SIGNAL(itemDoubleClicked(QListWidgetItem*)),
this,
SLOT(playlistItemHasBeenClicked(QListWidgetItem*))
);
connect
(
playlistView,
SIGNAL(itemActivated(QListWidgetItem*)),
this,
SLOT(resetPlaylistViewFunctionality(QListWidgetItem*))
);
connect
(
playlistView,
SIGNAL(itemClicked(QListWidgetItem*)),
this,
SLOT(resetPlaylistViewFunctionality(QListWidgetItem*))
);
connect
(
playlistView,
SIGNAL(itemPressed(QListWidgetItem*)),
this,
SLOT(resetPlaylistViewFunctionality(QListWidgetItem*))
);
}
void MainWindow::setupPlaylistTabs()
{
_playlistViews->push_back(_currentPlaylistView);
setupPlaylistViewConnections(_playlistViews->at(_playlistViews->count()-1));
_playlistTabs->addTab(_currentPlaylistView, "Playlist");
_playlistTabs->setTabsClosable(true);
connect(_playlistTabs,SIGNAL(tabCloseRequested(int)),this,SLOT(_tabCloseRequested(int)));
connect(_playlistTabs,SIGNAL(currentChanged(int)),this,SLOT(_currentTabIndexHasChanged(int)));
_players->push_back(_currentPlayer);
_currentPlayer->setPlaylist(new QMediaPlaylist);
_mainLayout->addWidget(_playlistTabs);
}
void MainWindow::setupOptionDash()
{
QHBoxLayout * optionDash = new QHBoxLayout;
optionDash->addWidget(_newPlaylistTabButton);
optionDash->addStretch();
optionDash->addWidget(_shuffleButton);
optionDash->addStretch();
optionDash->addWidget(_loopCheckbox);
optionDash->addStretch();
optionDash->addWidget(_volumeLabel);
optionDash->addWidget(_volumeSlider);
connect(_newPlaylistTabButton,SIGNAL(clicked()),this,SLOT(_newPlaylistTabButtonIsPressed()));
connect(_shuffleButton,SIGNAL(clicked()),this,SLOT(_shuffleButtonHasBeenPressed()));
_loopCheckbox->setText("Loop");
connect(_loopCheckbox, SIGNAL(stateChanged(int)), this, SLOT(_loopCheckboxStateHasChanged(int)));
_shuffleButton->setText("Shuffle");
_volumeLabel->setText(tr("<b>Volume:</b>"));
_volumeSlider->setRange(0,100);
_volumeSlider->setSliderPosition(_currentPlayer->volume());
connect(_volumeSlider,SIGNAL(valueChanged(int)),this,SLOT(_volumeSliderValueChanged()));
_mainLayout->addLayout(optionDash);
}
void MainWindow::setup()
{
setupMenus();
setupPlaylistTabs();
setupProgressBar();
setupMetadataLabel();
setupOptionDash();
setupButtons();
#ifdef __ANDROID__
QList<QMediaContent> * myContent = new QList<QMediaContent>;
QStringList * audioFiles = getAllMusicFiles(QStandardPaths::locate(QStandardPaths::MusicLocation, "", QStandardPaths::LocateDirectory));
for(int i = 0; i < audioFiles->count(); i++)
myContent->push_back(QMediaContent(QUrl::fromLocalFile(audioFiles->at(i))));
_currentPlayer->setPlaylist(new QMediaPlaylist);
_currentPlayer->playlist()->addMedia(*myContent);
_currentPlayer->playlist()->setCurrentIndex(0);
_currentPlayer->playlist()->shuffle();
_currentPlayer->setVolume(100);
_loopCheckbox->setMinimumWidth(120);
_volumeSlider->hide();
_volumeLabel->hide();
this->setMaximumSize(this->width(), this->height());
refreshPlaylistView();
#endif
}
#endif // SETUP_H