-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathplaycontrols.cpp
172 lines (141 loc) · 4.33 KB
/
playcontrols.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
/*
* Copyright (C) 2013-2015 Atmel Corporation.
*
* This file is licensed under the terms of the Atmel LIMITED License Agreement
* as written in the COPYING file that is delivered in the project root directory.
*
* DISCLAIMER: THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
* See the COPYING license file for more details.
*/
#include "playcontrols.h"
#include "ui_playcontrols.h"
PlayControls::PlayControls(QWidget *parent, bool small_screen) :
QWidget(parent),
ui(new Ui::PlayControls),
_onPlay(false),
_onMute(false),
_totalDuration(0),
_duration("unknown"),
_currentPosition(0),
_allowSeek(true),
_smallScreen(small_screen)
{
ui->setupUi(this);
autoFillBackground();
// Frameless and always on top
setWindowFlags(Qt::Widget | Qt::FramelessWindowHint);
setLayout(ui->layout);
// connect signals
connect(ui->volumeControl, SIGNAL(sliderMoved(int)), this, SIGNAL(setVolume(int)));
connect(ui->mediaPosition, SIGNAL(sliderMoved(int)), this, SIGNAL(positionChanged(int)));
connect(ui->optionsButtonn, SIGNAL(clicked()), this, SIGNAL(showOptions()));
if(!_smallScreen)
ui->positioLabel->hide();
#if !defined PLANA && !defined PLAND
ui->mediaPosition->hide();
ui->positioLabel->hide();
#endif
#if !defined PLANA && !defined PLANC
ui->muteButton->hide();
ui->volumeControl->hide();
#endif
#ifdef PLANC
ui->cpuUsage->hide();
#endif
}
PlayControls::~PlayControls()
{
delete ui;
}
/* Set Play/pause state */
void PlayControls::on_PlayPause_clicked()
{
if(_onPlay) emit pause(); // Pipeline is playing
else emit play(_onMute, ui->volumeControl->value()); // Pipeline is paused
}
/* Set Mute/unmute state */
void PlayControls::on_muteButton_clicked()
{
emit setMute(!_onMute);
if(_onMute){ // Unmute
ui->muteButton->setIcon(QIcon(MUTE_IMG));
}
else{ // mute
ui->muteButton->setIcon(QIcon(UNMUTE_IMG));
}
_onMute = !_onMute;
}
/* Update media duration */
void PlayControls::durationChanged(qint64 duration){
_totalDuration = duration;
ui->mediaPosition->setMaximum(_totalDuration);
// Calculate time
_duration = secondsToString(_totalDuration);
updatePositionLabel(_currentPosition);
}
/* Update media position */
void PlayControls::positionChanged(qint64 position){
_currentPosition = position;
ui->mediaPosition->setValue(_currentPosition);
// Update position label
updatePositionLabel(_currentPosition);
}
/* Update media position label */
void PlayControls::updatePositionLabel(int position){
if(_smallScreen)
ui->positioLabel->setText(secondsToString(position) + "/" + _duration);
}
/* Forma seconds as hh:mm:ss */
QString PlayControls::secondsToString(int seconds){
int h = seconds / 3600;
int m = (seconds % 3600) / 60;
int s = seconds - h*3600 - m * 60;
return (QString::number(h) + ":" + QString::number(m) + ":" + QString::number(s));
}
/* Full screen request */
void PlayControls::on_fullScreenButtonn_clicked()
{
emit setFullScreen();
}
/* Update CPU usage widget */
void PlayControls::setCPUusage(int usage){
ui->cpuUsage->setValue(usage);
}
/* Change play buton icon according to play state */
void PlayControls::setPlayIcon(bool state){
if(state){ // Video to play state
ui->PlayPause->setIcon(QIcon(PAUSE_IMG)); // Pause image
}
else{ // Video to pause
ui->PlayPause->setIcon(QIcon(PLAY_IMG)); // Pause image
}
}
/* Update the _onPlay flag and play button icon */
void PlayControls::setPlayState(int state){
if(state < 2){
_onPlay =state;
this->setPlayIcon(state);
ui->mediaPosition->setEnabled(_onPlay && _allowSeek); // Enable/Disable seeking
}else{
_onPlay = 0;
this->setPlayIcon(0);
ui->muteButton->setIcon(QIcon(MUTE_IMG));
_onMute = false;
ui->mediaPosition->setEnabled(_onPlay && _allowSeek); // Enable/Disable seeking
}
}
/* Seek */
void PlayControls::allowSeek(bool allow){
_allowSeek = allow;
}
/* Volume controls enable/disable*/
void PlayControls::enableVolumeControl(bool enable){
ui->muteButton->setEnabled(enable);
ui->volumeControl->setEnabled(enable);
}
int PlayControls::getCurrentVolume() {
return ui->volumeControl->value();
}
bool PlayControls::getCurrentMute() {
return _onMute;
}