5#include <QLoggingCategory>
11static Q_LOGGING_CATEGORY(log,
"FrmPlayer")
18 , m_paRecordPause(
nullptr)
24 , m_pbVideo(Qt::Horizontal,
this)
25 , m_pbVolume(Qt::Horizontal,
this)
27 , m_pParameter(
nullptr)
32 qDebug(log) << Q_FUNC_INFO;
34 m_VideoWidget.installEventFilter(
this);
36 m_paStart = m_ToolBar.addAction(
37 QIcon::fromTheme(
"media-playback-start"), tr(
"Start"));
38 m_paStart->setCheckable(
true);
39 check = connect(m_paStart, SIGNAL(toggled(
bool)),
40 this, SLOT(slotStart(
bool)));
43 m_paPause = m_ToolBar.addAction(
44 QIcon::fromTheme(
"media-playback-pause"), tr(
"pause"));
45 m_paPause->setCheckable(
true);
46 m_paPause->setEnabled(
false);
48 m_ToolBar.addSeparator();
49 m_ToolBar.addAction(QIcon::fromTheme(
"media-seek-backward"), tr(
"Backward"),
51 qDebug(log) <<
"Backward action";
52 emit sigChangePosition(m_pbVideo.value() - 1000);
55 m_pbVideo.setRange(0, 0);
56 m_pbVideo.setValue(0);
57 m_pbVideo.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
58 check = connect(&m_pbVideo, &QSlider::sliderPressed,
63 check = connect(&m_pbVideo, &QSlider::sliderReleased,
66 emit sigChangePosition(m_pbVideo.value());
69 m_ToolBar.addWidget(&m_pbVideo);
71 m_ToolBar.addAction(QIcon::fromTheme(
"media-seek-forward"), tr(
"Forward"),
73 qDebug(log) <<
"Forward action";
74 emit sigChangePosition(m_pbVideo.value() + 1000);
77 m_ToolBar.addSeparator();
78 m_pLabel =
new QLabel(&m_ToolBar);
79 m_pLabel->setText(
"00:00:00 / 00:00:00");
80 m_ToolBar.addWidget(m_pLabel);
81 m_ToolBar.addSeparator();
83 m_paScreenShot = m_ToolBar.addAction(
84 QIcon::fromTheme(
"camera-photo"), tr(
"ScreenShot"));
85 m_paScreenShot->setEnabled(
false);
88 m_paRecord = m_ToolBar.addAction(
89 QIcon::fromTheme(
"media-record"), tr(
"Record"));
90 m_paRecord->setCheckable(
true);
91 m_paRecord->setEnabled(
false);
92 check = connect(m_paRecord, &QAction::toggled,
this, [&](
bool checked){
93 m_paRecordPause->setEnabled(checked);
95 m_paRecordPause->setChecked(
false);
98 m_paRecordPause = m_ToolBar.addAction(
99 QIcon::fromTheme(
"media-playback-pause"), tr(
"Record pause"));
100 m_paRecordPause->setCheckable(
true);
101 m_paRecordPause->setEnabled(
false);
104 m_paSettings = m_ToolBar.addAction(
105 QIcon::fromTheme(
"system-settings"), tr(
"Settings"));
107 m_paMuted = m_ToolBar.addAction(
108 QIcon::fromTheme(
"audio-volume-medium"), tr(
"Audio"));
109 m_paMuted->setCheckable(
true);
110 check = connect(m_paMuted, SIGNAL(toggled(
bool)),
111 this, SLOT(slotAudioMuted(
bool)));
114 m_pbVolume.setRange(0, 100);
115 m_pbVolume.setValue(0);
116 m_pbVolume.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
117 m_paVolume = m_ToolBar.addWidget(&m_pbVolume);
118 check = connect(&m_pbVolume, SIGNAL(sliderMoved(
int)),
119 this, SLOT(slotAduioVolume(
int)));
123CFrmPlayer::~CFrmPlayer()
125 qDebug(log) << Q_FUNC_INFO;
128QVideoSink *CFrmPlayer::videoSink()
130 return m_VideoWidget.videoSink();
135 if(!pParameter || m_pParameter == pParameter)
138 m_pParameter = pParameter;
140 m_paMuted->setChecked(m_pParameter->GetAudioOutputMuted());
141 m_pbVolume.setValue(m_pParameter->GetAudioOutputVolume());
145void CFrmPlayer::slotAudioMuted(
bool bMuted)
151 m_paMuted->setIcon(QIcon::fromTheme(
"audio-volume-muted"));
152 m_paMuted->setText(tr(
"Muted"));
154 m_paMuted->setIcon(QIcon::fromTheme(
"audio-volume-medium"));
155 m_paMuted->setText(tr(
"Audio"));
157 m_pParameter->SetAudioOutputMuted(bMuted);
158 m_paVolume->setEnabled(!bMuted);
161void CFrmPlayer::slotAduioVolume(
int volume)
163 qDebug(log) <<
"Volume:" << volume;
166 m_pParameter->SetAudioOutputVolume(volume);
169void CFrmPlayer::slotPositionChanged(qint64 pos, qint64 duration)
171 qint64 currentInfo = pos / 1000;
172 qint64 dur = duration / 1000;
175 if (currentInfo || dur) {
176 QTime currentTime((currentInfo / 3600) % 60,
177 (currentInfo / 60) % 60,
179 (currentInfo * 1000) % 1000);
180 QTime totalTime((dur / 3600) % 60,
183 (dur * 1000) % 1000);
184 QString format =
"mm:ss";
187 szStr = currentTime.toString(format)
188 +
" / " + totalTime.toString(format);
189 m_pLabel->setText(szStr);
190 m_pbVideo.setRange(0, duration);
192 m_pbVideo.setValue(pos);
196void CFrmPlayer::resizeEvent(QResizeEvent *event)
198 qDebug(log) <<
"CFrmPlayer::resizeEvent()" << event;
199 QSize s =
event->size();
201 QWidget::resizeEvent(event);
204int CFrmPlayer::AdjustCompone(
const QSize &s)
206 m_VideoWidget.move(0, 0);
207 QRect rect(0, 0, s.width(), s.height() - m_ToolBar.frameGeometry().height());
208 m_VideoWidget.setGeometry(rect);
210 int top = s.height() - m_ToolBar.frameGeometry().height();
211 m_ToolBar.move(left, top);
212 m_ToolBar.resize(s.width(), m_ToolBar.height());
216void CFrmPlayer::slotStart(
bool bStart)
218 QAction* p = qobject_cast<QAction*>(sender());
221 p->setIcon(QIcon::fromTheme(
"media-playback-stop"));
222 p->setText(tr(
"Stop"));
223 m_paPause->setEnabled(
true);
224 m_paPause->setChecked(
false);
225 m_paScreenShot->setEnabled(
true);
227 m_paRecord->setEnabled(
true);
228 m_paRecord->setChecked(
false);
229 m_paRecordPause->setEnabled(
true);
230 m_paRecordPause->setChecked(
false);
233 p->setIcon(QIcon::fromTheme(
"media-playback-start"));
234 p->setText(tr(
"Start"));
235 m_paPause->setEnabled(
false);
236 m_paPause->setChecked(
false);
237 m_paScreenShot->setEnabled(
false);
239 m_paRecord->setEnabled(
false);
240 m_paRecord->setChecked(
false);
241 m_paRecordPause->setEnabled(
false);
242 m_paRecordPause->setChecked(
false);
247bool CFrmPlayer::eventFilter(QObject *watched, QEvent *event)
250 if(&m_VideoWidget == watched)
252 switch(event->type()){
253 case QEvent::MouseMove:
254 qDebug(log) <<
"Mouse move";
256 case QEvent::MouseButtonRelease:
257 m_paPause->trigger();
259 case QEvent::MouseButtonDblClick: {
260 m_VideoWidget.setFullScreen(!m_VideoWidget.isFullScreen());
261 if(!m_VideoWidget.isFullScreen()) {
267 case QEvent::KeyRelease:
269 QKeyEvent* k = (QKeyEvent*)(event);
273 if(m_VideoWidget.isFullScreen()) {
274 m_VideoWidget.setFullScreen(
false);
281 m_paPause->trigger();