This repository was archived by the owner on May 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.cpp
More file actions
115 lines (97 loc) · 3.36 KB
/
controls.cpp
File metadata and controls
115 lines (97 loc) · 3.36 KB
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
#include "controls.h"
#include "ui_controls.h"
#include <QMouseEvent>
//#include <QDebug>
// controls constructor
// starts up all stuff
Controls::Controls(QWidget *parent):
AbstractControl(parent), ui(new Ui::Controls){
ui->setupUi(this);
// when the user releases the slider, tells qt a
// new position was chosen
connect(ui->horizontalSliderPosition,SIGNAL(sliderReleased()),
this,SLOT(onSliderReleased()));
// duration records total music time to be played
duration=1;
// the horizontal slider is initially disabled, since no music has
// been loaded
ui->horizontalSliderPosition->setDisabled(true);
// we want no focus on some widgets
// (qt may draw a rectangle on them in such case)
ui->pushButtonPlayPause->setFocusPolicy(Qt::NoFocus);
ui->pushButtonNext->setFocusPolicy(Qt::NoFocus);
ui->pushButtonPrev->setFocusPolicy(Qt::NoFocus);
ui->horizontalSliderVolume->setFocusPolicy(Qt::NoFocus);
// nice red colors to lcdnumbers
ui->lcdNumberElapsed->setStyleSheet(QString("QLCDNumber{color:red;}"));
ui->lcdNumberDuration->setStyleSheet(QString("QLCDNumber{color:red;}"));
playIcon = QIcon(":/resources/play.svg");
pauseIcon = QIcon(":/resources/pause.svg");
}
// put the trash on the trash
Controls::~Controls(){
delete ui;
}
// deals with slider release events
void Controls::onSliderReleased(){
// when the user releases the slider, the component tells qt
// the new position in percentual values
//
// we should not care about ajust lcdnumber here
// wait until player tell us the stream position has changed
emit elapsedSelected(ui->horizontalSliderPosition->value()*duration/100);
}
// the folowing method is (almost) self-explained
void Controls::onPlayPauseClicked(void){
emit playPause();
}
// the folowing method is (almost) self-explained
void Controls::onPrevClicked(){
emit prev();
}
// the folowing method is (almost) self-explained
void Controls::onNextClicked(){
emit next();
}
// tells current volume
void Controls::onVolumeChanged(int value){
// if slider is not down it means someone else
// is selecting the current volume
if(!ui->horizontalSliderVolume->isSliderDown()){
ui->horizontalSliderVolume->setValue(value);
}
else{
// if slider is down the user is
// selecting the volume in this component
emit volumeSelected(value);
}
}
// music duration has changed (current media has changed)
void Controls::onDurationChanged(qint64 value){
ui->horizontalSliderPosition->setEnabled(true);
duration = value;
// display the new duration in lcdnumber
ui->lcdNumberDuration->display(QTime(0,0).addMSecs(value).toString(QString("hh:mm:ss")));
}
// player state has changed...
void Controls::onPlayerStateChanged(bool state){
if(state == true){
// if playing, display pause icon
ui->pushButtonPlayPause->setIcon(pauseIcon);
}
else{
// if paused, display play icon (duh!)
ui->pushButtonPlayPause->setIcon(playIcon);
}
}
// elapsed time has changed
void Controls::onElapsedChanged(qint64 value){
// adjust the elapsed time on lcdnumber
ui->lcdNumberElapsed->display(QTime(0,0).addMSecs(value).toString(QString("hh:mm:ss")));
// if slider is not down, it means someone else is changing
// elapsed time
if(!ui->horizontalSliderPosition->isSliderDown()){
// position slider in the new elapsed time
ui->horizontalSliderPosition->setValue(100*value/duration);
}
}