forked from SoftProjector/softprojector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediacontrol.cpp
150 lines (128 loc) · 3.63 KB
/
mediacontrol.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
/***************************************************************************
//
// softProjector - an open source media projection software
// Copyright (C) 2017 Vladislav Kobzar
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 3 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
***************************************************************************/
#include "mediacontrol.hpp"
#include "ui_mediacontrol.h"
MediaControl::MediaControl(QWidget *parent) :
QWidget(parent),
ui(new Ui::MediaControl)
{
ui->setupUi(this);
mPlayerState = QMediaPlayer::StoppedState;
mDuration = 0;
// Setup Icons
mPlayIcon = QIcon(":icons/icons/play.png");
mPauseIcon = QIcon(":icons/icons/pause.png");
mMuteIcon = QIcon(":icons/icons/speakerMute.png");
mUnmuteIcon = QIcon(":icons/icons/speaker.png");
}
MediaControl::~MediaControl()
{
delete ui;
}
void MediaControl::setVolume(int level)
{
ui->horizontalSliderVolume->setValue(level);
}
void MediaControl::updateTime(qint64 time)
{
ui->horizontalSliderTime->setValue(time/1000);
QString timeString;
if (time || mDuration)
{
int sec = time/1000;
int min = sec/60;
int hour = min/60;
int msec = time;
QTime playTime(hour%60, min%60, sec%60, msec%1000);
sec = mDuration / 1000;
min = sec / 60;
hour = min / 60;
msec = mDuration;
QTime stopTime(hour%60, min%60, sec%60, msec%1000);
QString timeFormat = "mm:ss";
if (hour > 0)
{
timeFormat = "h:mm:ss";
}
timeString = playTime.toString(timeFormat);
if (mDuration)
{
timeString += " / " + stopTime.toString(timeFormat);
}
}
ui->labelTime->setText(timeString);
}
void MediaControl::setMaximumTime(qint64 maxTime)
{
mDuration = maxTime;
ui->horizontalSliderTime->setMaximum(maxTime/1000);
}
void MediaControl::updatePlayerState(QMediaPlayer::State state)
{
mPlayerState = state;
switch (mPlayerState)
{
case QMediaPlayer::StoppedState:
case QMediaPlayer::PausedState:
ui->pushButtonPlayPause->setIcon(mPlayIcon);
break;
case QMediaPlayer::PlayingState:
ui->pushButtonPlayPause->setIcon(mPauseIcon);
break;
default:
ui->pushButtonPlayPause->setIcon(mPlayIcon);
break;
}
}
void MediaControl::on_pushButtonStop_clicked()
{
emit stop();
}
void MediaControl::on_pushButtonPlayPause_clicked()
{
if(QMediaPlayer::PlayingState == mPlayerState)
{
emit pause();
}
else
{
emit play();
}
}
void MediaControl::on_pushButtonMute_toggled(bool checked)
{
emit muted(checked);
ui->horizontalSliderVolume->setEnabled(!checked);
if(checked)
{
ui->pushButtonMute->setIcon(mMuteIcon);
}
else
{
ui->pushButtonMute->setIcon(mUnmuteIcon);
}
}
void MediaControl::on_horizontalSliderTime_sliderReleased()
{
emit timeChanged(ui->horizontalSliderTime->value() * 1000);
}
void MediaControl::on_horizontalSliderVolume_sliderMoved(int position)
{
emit volumeChanged(position);
}