7#include <QDesktopServices>
8#include <QLoggingCategory>
11#include "BackendDesktop.h"
14static Q_LOGGING_CATEGORY(log,
"Backend.Desktop")
15static Q_LOGGING_CATEGORY(logMouse, "Backend.Desktop.Mouse")
17#define TypeRecordVideo (QEvent::User + 1)
38int g_QtKeyboardModifiers = qRegisterMetaType<Qt::KeyboardModifiers>(
"KeyboardModifiers");
39int g_QtMouseButtons = qRegisterMetaType<Qt::MouseButtons>(
"MouseButtons");
40int g_QtMouseButton = qRegisterMetaType<Qt::MouseButton>(
"MouseButton");
41int g_QMessageBox_Icon = qRegisterMetaType<QMessageBox::Icon>(
"QMessageBox::Icon");
46 , m_pParameterRecord(nullptr)
47 , m_VideoFrameInput(this)
48 , m_AudioBufferInput(this)
49 , m_AudioBufferOutput(this)
52 qDebug(log) << Q_FUNC_INFO;
60 QString szErr = pOperate->metaObject()->className();
61 szErr +=
"::GetViewer() is not CFrmViewer";
62 qWarning(log) << szErr.toStdString().c_str();
65 QString szErr = pOperate->metaObject()->className();
66 szErr +=
"::GetViewer() is not CFrmScroll";
67 qWarning(log) << szErr.toStdString().c_str();
74 &m_Recorder, &QMediaRecorder::errorOccurred,
75 this, [&](QMediaRecorder::Error error,
const QString &errorString) {
76 qDebug(log) <<
"Recorder error occurred:" << error << errorString;
78 emit sigError(error, errorString);
82 &m_Recorder, &QMediaRecorder::recorderStateChanged,
83 this, [&](QMediaRecorder::RecorderState state){
84 qDebug(log) <<
"Recorder state changed:" << state;
85 if(QMediaRecorder::StoppedState == state)
88 if(m_pParameterRecord) {
89 qDebug(log) <<
"End action:"
90 << m_pParameterRecord->GetEndAction()
91 << m_Recorder.actualLocation();
92 switch(m_pParameterRecord->GetEndAction())
94 case CParameterRecord::ENDACTION::OpenFile:
95 QDesktopServices::openUrl(m_Recorder.actualLocation());
97 case CParameterRecord::ENDACTION::OpenFolder: {
98 QFileInfo fi(m_Recorder.actualLocation().toLocalFile());
99 QDesktopServices::openUrl(
100 QUrl::fromLocalFile(fi.absolutePath()));
110 check = connect(&m_Recorder, &QMediaRecorder::actualLocationChanged,
111 this, [&](
const QUrl &location){
112 qInfo(log) <<
"Recorder actual location changed:" << location;
118CBackendDesktop::~CBackendDesktop()
120 qDebug(log) << Q_FUNC_INFO;
127 if(!pOperate)
return -1;
130 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
131 pOperate, SLOT(slotSetServerName(
const QString&)));
133 check = connect(pOperate, SIGNAL(sigClipBoardChanged()),
136 check = connect(
this, SIGNAL(sigSetClipboard(QMimeData*)),
137 pOperate, SLOT(slotSetClipboard(QMimeData*)));
141 m_pParameterRecord = &pOperate->
GetParameter()->m_Record;
142 check = connect(pOperate, SIGNAL(sigRecord(
bool)),
143 this, SLOT(slotRecord(
bool)));
146 check = connect(pOperate, SIGNAL(sigRecordPause(
bool)),
147 this, SLOT(slotRecordPause(
bool)));
151 SIGNAL(recorderStateChanged(QMediaRecorder::RecorderState)),
152 pOperate, SLOT(slotRecorderStateChanged(QMediaRecorder::RecorderState)));
162 if(!pView)
return -1;
165 check = connect(
this, SIGNAL(
sigRunning()), pView, SLOT(slotRunning()));
167 check = connect(
this, SIGNAL(sigSetDesktopSize(
int,
int)),
168 pView, SLOT(slotSetDesktopSize(
int,
int)));
170 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
171 pView, SLOT(slotSetName(
const QString&)));
174 check = connect(
this, SIGNAL(
sigUpdateRect(
const QRect&,
const QImage&)),
175 pView, SLOT(slotUpdateRect(
const QRect&,
const QImage&)));
178 pView, SLOT(slotUpdateRect(
const QImage&)));
180 check = connect(
this, SIGNAL(sigUpdateCursor(
const QCursor&)),
181 pView, SLOT(slotUpdateCursor(
const QCursor&)));
183 check = connect(
this, SIGNAL(sigUpdateCursorPosition(
const QPoint&)),
184 pView, SLOT(slotUpdateCursorPosition(
const QPoint&)));
186 check = connect(
this, SIGNAL(sigUpdateLedState(
unsigned int)),
187 pView, SLOT(slotUpdateLedState(
unsigned int)));
191 check = connect(
this, SIGNAL(sigRecordVideo(
bool, qreal)),
192 pView, SLOT(slotRecordVideo(
bool, qreal)));
194 check = connect(pView, SIGNAL(sigRecordVideo(QImage)),
195 this, SLOT(slotRecordVideo(QImage)),
196 Qt::DirectConnection);
207 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
208 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)),
209 Qt::DirectConnection);
211 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
212 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)),
213 Qt::DirectConnection);
215 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
216 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)),
217 Qt::DirectConnection);
219 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
220 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)),
221 Qt::DirectConnection);
223 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
224 this, SLOT(slotKeyPressEvent(QKeyEvent*)),
225 Qt::DirectConnection);
227 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
228 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)),
229 Qt::DirectConnection);
231 check = connect(pView, SIGNAL(sigInputMethodEvent(QInputMethodEvent*)),
232 this, SLOT(slotInputMethodEvent(QInputMethodEvent*)),
233 Qt::DirectConnection);
239void CBackendDesktop::slotWheelEvent(QWheelEvent *event, QPoint pos)
241 QWheelEvent* e =
new QWheelEvent(
243#
if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
244 event->globalPosition(),
248 event->pixelDelta(), event->angleDelta(), event->buttons(),
249 event->modifiers(), event->phase(), event->inverted(), event->source());
250 QCoreApplication::postEvent(
this, e);
254void CBackendDesktop::slotMouseMoveEvent(QMouseEvent *event, QPoint pos)
256#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
257 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
258 event->buttons(), event->modifiers());
260 QMouseEvent* e =
new QMouseEvent(event->type(), pos, pos, event->button(),
261 event->buttons(), event->modifiers());
263 QCoreApplication::postEvent(
this, e);
267void CBackendDesktop::slotMousePressEvent(QMouseEvent *event, QPoint pos)
269#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
270 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
271 event->buttons(), event->modifiers());
273 QMouseEvent* e =
new QMouseEvent(event->type(), pos, pos, event->button(),
274 event->buttons(), event->modifiers());
276 QCoreApplication::postEvent(
this, e);
280void CBackendDesktop::slotMouseReleaseEvent(QMouseEvent *event, QPoint pos)
282#if QT_VERSION < QT_VERSION_CHECK(6, 4, 0)
283 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
284 event->buttons(), event->modifiers());
286 QMouseEvent* e =
new QMouseEvent(event->type(), pos, pos, event->button(),
287 event->buttons(), event->modifiers());
289 QCoreApplication::postEvent(
this, e);
293void CBackendDesktop::slotKeyPressEvent(QKeyEvent *event)
295 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
296 event->modifiers(), event->text());
297 QCoreApplication::postEvent(
this, e);
301void CBackendDesktop::slotKeyReleaseEvent(QKeyEvent *event)
303 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
304 event->modifiers(), event->text());
305 QCoreApplication::postEvent(
this, e);
309void CBackendDesktop::slotInputMethodEvent(QInputMethodEvent *event)
311 if(event->commitString().isEmpty())
return;
312 QInputMethodEvent* e =
new QInputMethodEvent(event->preeditString(), event->attributes());
313 e->setCommitString(event->commitString(), event->replacementStart(), event->replacementLength());
314 QCoreApplication::postEvent(
this, e);
318void CBackendDesktop::mouseMoveEvent(QMouseEvent *event)
320 qDebug(logMouse) <<
"Need to implement CBackendDesktop::mouseMoveEvent";
323void CBackendDesktop::mousePressEvent(QMouseEvent *event)
325 qDebug(logMouse) <<
"Need to implement CBackendDesktop::mousePressEvent";
328void CBackendDesktop::mouseReleaseEvent(QMouseEvent *event)
330 qDebug(logMouse) <<
"Need to implement CBackendDesktop::mouseReleaseEvent";
333void CBackendDesktop::wheelEvent(QWheelEvent *event)
335 qDebug(logMouse) <<
"Need to implement CBackendDesktop::wheelEvent";
338void CBackendDesktop::keyPressEvent(QKeyEvent *event)
340 qDebug(logMouse) <<
"Need to implement CBackendDesktop::keyPressEvent";
343void CBackendDesktop::keyReleaseEvent(QKeyEvent *event)
345 qDebug(logMouse) <<
"Need to implement CBackendDesktop::keyReleaseEvent";
348void CBackendDesktop::InputMethodEvent(QInputMethodEvent *event)
350 qDebug(logMouse) <<
"Need to implement CBackendDesktop::InputMethodEvent";
358bool CBackendDesktop::event(QEvent *event)
361 switch (event->type()) {
362 case QEvent::MouseButtonPress:
363 case QEvent::MouseButtonDblClick:
364 mousePressEvent((QMouseEvent*)event);
366 case QEvent::MouseButtonRelease:
367 mouseReleaseEvent((QMouseEvent*)event);
369 case QEvent::MouseMove:
370 mouseMoveEvent((QMouseEvent*)event);
373 wheelEvent((QWheelEvent*)event);
375 case QEvent::KeyPress:
376 keyPressEvent((QKeyEvent*)event);
378 case QEvent::KeyRelease:
379 keyReleaseEvent((QKeyEvent*)event);
381 case QEvent::InputMethod:
382 InputMethodEvent((QInputMethodEvent*) event);
385 case TypeRecordVideo:
390 return QObject::event(event);
398void CBackendDesktop::slotRecord(
bool bRecord)
400 qDebug(log) << Q_FUNC_INFO << bRecord;
402 if(QMediaRecorder::RecordingState == m_Recorder.recorderState())
404 (*m_pParameterRecord) >> m_Recorder;
405 m_CaptureSession.setVideoFrameInput(&m_VideoFrameInput);
406 m_CaptureSession.setRecorder(&m_Recorder);
410 m_CaptureSession.setVideoFrameInput(
nullptr);
411 m_CaptureSession.setAudioBufferInput(
nullptr);
412 m_CaptureSession.setRecorder(
nullptr);
414 emit sigRecordVideo(bRecord, m_pParameterRecord->GetVideoFrameRate());
417void CBackendDesktop::slotRecordPause(
bool bPause)
419 qDebug(log) << Q_FUNC_INFO << bPause;
421 if(m_Recorder.recorderState() == QMediaRecorder::RecordingState)
424 if(m_Recorder.recorderState() == QMediaRecorder::PausedState)
429void CBackendDesktop::slotRecordVideo(
const QImage &img)
433 QCoreApplication::postEvent(
this, e);
441 if(QMediaRecorder::RecordingState != m_Recorder.recorderState()) {
442 qCritical(log) <<
"Recorder is inavailable";
445 QVideoFrame frame(e->GetImage());
446 bool bRet = m_VideoFrameInput.sendVideoFrame(frame);
450 qDebug(log) <<
"m_VideoFrameInput.sendVideoFrame fail";
void sigUpdateRect(const QRect &r, const QImage &image)
通知视图,图像更新
int SetViewer(CFrmViewer *pView)
virtual void slotClipBoardChanged()=0
当剪切板发生改变时调用
virtual int WakeUp() override
唤醒后台线程
后端接口。它由协议插件实现。 它默认启动一个定时器来开启一个非 Qt 事件循环(就是普通的循环处理)。 详见: Start()、 slotTimeOut()、 OnProcess() 。 当然,它仍然支...
void sigRunning()
当插件开始成功后触发。仅由插件触发
用于显示从 CConnectDesktop 输出的图像,和向 CConnectDesktop 发送键盘、鼠标事件。
virtual QWidget * GetViewer() override
得到显示视图
virtual CParameterBase * GetParameter()
Get parameter