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 setFocusPolicy(Qt::WheelFocus);
35 m_VideoWidget.setFocusPolicy(Qt::WheelFocus);
36 m_VideoWidget.installEventFilter(
this);
38 m_paStart = m_ToolBar.addAction(
39 QIcon::fromTheme(
"media-playback-start"), tr(
"Start"));
40 m_paStart->setCheckable(
true);
41 check = connect(m_paStart, SIGNAL(toggled(
bool)),
42 this, SLOT(slotStart(
bool)));
45 m_paPause = m_ToolBar.addAction(
46 QIcon::fromTheme(
"media-playback-pause"), tr(
"pause"));
47 m_paPause->setCheckable(
true);
48 m_paPause->setEnabled(
false);
50 m_ToolBar.addSeparator();
51 m_ToolBar.addAction(QIcon::fromTheme(
"media-seek-backward"), tr(
"Backward"),
53 qDebug(log) <<
"Backward action";
54 emit sigChangePosition(m_pbVideo.value() - 1000);
57 m_pbVideo.setRange(0, 0);
58 m_pbVideo.setValue(0);
59 m_pbVideo.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred);
60 check = connect(&m_pbVideo, &QSlider::sliderPressed,
65 check = connect(&m_pbVideo, &QSlider::sliderReleased,
68 emit sigChangePosition(m_pbVideo.value());
71 m_ToolBar.addWidget(&m_pbVideo);
73 m_ToolBar.addAction(QIcon::fromTheme(
"media-seek-forward"), tr(
"Forward"),
75 qDebug(log) <<
"Forward action";
76 emit sigChangePosition(m_pbVideo.value() + 1000);
79 m_ToolBar.addSeparator();
80 m_pLabel =
new QLabel(&m_ToolBar);
81 m_pLabel->setText(
"00:00:00 / 00:00:00");
82 m_ToolBar.addWidget(m_pLabel);
83 m_ToolBar.addSeparator();
85 m_paScreenShot = m_ToolBar.addAction(
86 QIcon::fromTheme(
"camera-photo"), tr(
"ScreenShot"));
87 m_paScreenShot->setEnabled(
false);
90 m_paRecordPause = m_ToolBar.addAction(
91 QIcon::fromTheme(
"media-playback-pause"), tr(
"Record pause"));
92 m_paRecordPause->setCheckable(
true);
93 m_paRecordPause->setEnabled(
false);
95 m_paRecord = m_ToolBar.addAction(
96 QIcon::fromTheme(
"media-record"), tr(
"Record"));
97 m_paRecord->setCheckable(
true);
98 m_paRecord->setEnabled(
false);
99 check = connect(m_paRecord, &QAction::toggled,
this, [&](
bool checked){
100 m_paRecordPause->setEnabled(checked);
101 m_paRecordPause->setChecked(
false);
106 m_paSettings = m_ToolBar.addAction(
107 QIcon::fromTheme(
"system-settings"), tr(
"Settings"));
109 m_paMuted = m_ToolBar.addAction(
110 QIcon::fromTheme(
"audio-volume-medium"), tr(
"Audio"));
111 m_paMuted->setCheckable(
true);
112 check = connect(m_paMuted, SIGNAL(toggled(
bool)),
113 this, SLOT(slotAudioMuted(
bool)));
116 m_pbVolume.setRange(0, 100);
117 m_pbVolume.setValue(0);
118 m_pbVolume.setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
119 m_paVolume = m_ToolBar.addWidget(&m_pbVolume);
120 check = connect(&m_pbVolume, SIGNAL(sliderMoved(
int)),
121 this, SLOT(slotAduioVolume(
int)));
125CFrmPlayer::~CFrmPlayer()
127 qDebug(log) << Q_FUNC_INFO;
130QVideoSink *CFrmPlayer::videoSink()
132 return m_VideoWidget.videoSink();
137 if(!pParameter || m_pParameter == pParameter)
140 m_pParameter = pParameter;
142 m_paMuted->setChecked(m_pParameter->GetAudioOutputMuted());
143 m_pbVolume.setValue(m_pParameter->GetAudioOutputVolume());
147void CFrmPlayer::slotAudioMuted(
bool bMuted)
153 m_paMuted->setIcon(QIcon::fromTheme(
"audio-volume-muted"));
154 m_paMuted->setText(tr(
"Muted"));
156 m_paMuted->setIcon(QIcon::fromTheme(
"audio-volume-medium"));
157 m_paMuted->setText(tr(
"Audio"));
159 m_pParameter->SetAudioOutputMuted(bMuted);
160 m_paVolume->setEnabled(!bMuted);
163void CFrmPlayer::slotAduioVolume(
int volume)
165 qDebug(log) <<
"Volume:" << volume;
168 m_pParameter->SetAudioOutputVolume(volume);
171void CFrmPlayer::slotPositionChanged(qint64 pos, qint64 duration)
173 qint64 currentInfo = pos / 1000;
174 qint64 dur = duration / 1000;
177 if (currentInfo || dur) {
178 QTime currentTime((currentInfo / 3600) % 60,
179 (currentInfo / 60) % 60,
181 (currentInfo * 1000) % 1000);
182 QTime totalTime((dur / 3600) % 60,
185 (dur * 1000) % 1000);
186 QString format =
"mm:ss";
189 szStr = currentTime.toString(format)
190 +
" / " + totalTime.toString(format);
191 m_pLabel->setText(szStr);
192 m_pbVideo.setRange(0, duration);
194 m_pbVideo.setValue(pos);
198void CFrmPlayer::resizeEvent(QResizeEvent *event)
200 qDebug(log) <<
"CFrmPlayer::resizeEvent()" << event;
201 QSize s =
event->size();
203 QWidget::resizeEvent(event);
206void CFrmPlayer::focusInEvent(QFocusEvent *event)
208 qDebug(log) << Q_FUNC_INFO <<
event <<
this;
212void CFrmPlayer::focusOutEvent(QFocusEvent *event)
214 qDebug(log) << Q_FUNC_INFO <<
event <<
this;
217int CFrmPlayer::AdjustCompone(
const QSize &s)
219 m_VideoWidget.move(0, 0);
220 QRect rect(0, 0, s.width(), s.height() - m_ToolBar.frameGeometry().height());
221 m_VideoWidget.setGeometry(rect);
223 int top = s.height() - m_ToolBar.frameGeometry().height();
224 m_ToolBar.move(left, top);
225 m_ToolBar.resize(s.width(), m_ToolBar.height());
229void CFrmPlayer::slotStart(
bool bStart)
231 QAction* p = qobject_cast<QAction*>(sender());
234 p->setIcon(QIcon::fromTheme(
"media-playback-stop"));
235 p->setText(tr(
"Stop"));
236 m_paPause->setEnabled(
true);
237 m_paPause->setChecked(
false);
238 m_paScreenShot->setEnabled(
true);
240 m_paRecord->setEnabled(
true);
241 m_paRecord->setChecked(
false);
242 m_paRecordPause->setEnabled(
true);
243 m_paRecordPause->setChecked(
false);
246 p->setIcon(QIcon::fromTheme(
"media-playback-start"));
247 p->setText(tr(
"Start"));
248 m_paPause->setEnabled(
false);
249 m_paPause->setChecked(
false);
250 m_paScreenShot->setEnabled(
false);
252 m_paRecord->setEnabled(
false);
253 m_paRecord->setChecked(
false);
254 m_paRecordPause->setEnabled(
false);
255 m_paRecordPause->setChecked(
false);
260bool CFrmPlayer::eventFilter(QObject *watched, QEvent *event)
263 if(&m_VideoWidget == watched)
265 switch(event->type()){
266 case QEvent::MouseMove:
267 qDebug(log) <<
"Mouse move";
269 case QEvent::MouseButtonRelease:
270 m_paPause->trigger();
272 case QEvent::MouseButtonDblClick: {
273 m_VideoWidget.setFullScreen(!m_VideoWidget.isFullScreen());
274 if(!m_VideoWidget.isFullScreen()) {
280 case QEvent::KeyRelease:
282 QKeyEvent* k = (QKeyEvent*)(event);
286 if(m_VideoWidget.isFullScreen()) {
287 m_VideoWidget.setFullScreen(
false);
294 m_paPause->trigger();
301 case QEvent::FocusIn:
void sigViewerFocusIn(QWidget *pView)
The view is focus.