-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolpanel.cpp
110 lines (93 loc) · 2.99 KB
/
controlpanel.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
#include "controlpanel.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QDebug>
controlPanel::controlPanel(QWidget *parent) :
QWidget(parent),
_playPauseButton(new QPushButton("Play/Pause")),
_nextButton(new QPushButton("Next")),
_previousButton(new QPushButton("Previous")),
_volumeSlider(new QSlider(Qt::Horizontal)),
_currentState(controlPanel::Paused)
{
_volumeSlider->setRange(0,100);
_volumeSlider->setValue(50);
QVBoxLayout * layout = new QVBoxLayout;
QHBoxLayout * buttonLayout = new QHBoxLayout;
QHBoxLayout * optionsLayout = new QHBoxLayout;
buttonLayout->addWidget(_previousButton);
buttonLayout->addWidget(_playPauseButton);
buttonLayout->addWidget(_nextButton);
optionsLayout->addWidget(_volumeSlider);
layout->addLayout(optionsLayout);
layout->addLayout(buttonLayout);
connect(_playPauseButton, SIGNAL(clicked()), this, SLOT(togglePlayPauseState()));
connect(_volumeSlider, SIGNAL(valueChanged(int)), this, SLOT(recieveNewVolumeSliderValue(int)));
this->setLayout(layout);
}
const QObject * controlPanel::widget(Widget widget)
{
if(widget == controlPanel::PlayPauseButton)
return _playPauseButton;
else if(widget == controlPanel::NextButton)
return _nextButton;
else if(widget == controlPanel::PreviousButton)
return _previousButton;
else return new QObject;
}
void controlPanel::setPlayButtonIcon(const QIcon &icon)
{
_playButtonIcon = icon;
if(_currentState == controlPanel::Paused)
{
_playPauseButton->setText("");
_playPauseButton->setIcon(icon);
}
}
void controlPanel::setPauseButtonIcon(const QIcon &icon)
{
_pauseButtonIcon = icon;
if(_currentState == controlPanel::Playing)
{
_playPauseButton->setText("");
_playPauseButton->setIcon(icon);
}
}
void controlPanel::setNextButtonIcon(const QIcon &icon)
{
_nextButton->setText("");
_nextButton->setIcon(icon);
}
void controlPanel::setPreviousButtonIcon(const QIcon &icon)
{
_previousButton->setText("");
_previousButton->setIcon(icon);
}
void controlPanel::togglePlayPauseState()
{
if(_currentState == controlPanel::Paused)
{
_currentState = controlPanel::Playing;
if(!_playButtonIcon.isNull())
_playPauseButton->setIcon(_pauseButtonIcon);
else
_playPauseButton->setIcon(QIcon());
}
else if(_currentState == controlPanel::Playing)
{
_currentState = controlPanel::Paused;
if(!_pauseButtonIcon.isNull())
_playPauseButton->setIcon(_playButtonIcon);
else
_playPauseButton->setIcon(QIcon());
}
}
void controlPanel::recieveNewVolumeSliderValue(int value)
{
emit volumeSliderValueChanged(value);
}
void controlPanel::setState(controlPanel::PlayPauseButtonState state)
{
if(state != _currentState)
togglePlayPauseState();
}