6#include <QLoggingCategory>
9#include <QDesktopServices>
11#include "ConnectDesktop.h"
12#include "ConnecterThread.h"
14static Q_LOGGING_CATEGORY(log,
"Client.Connect.Desktop")
15static Q_LOGGING_CATEGORY(logMouse, "Client.Connect.Desktop.Mouse")
17#define TypeRecordVideo (QEvent::User + 1)
33int g_QtKeyboardModifiers = qRegisterMetaType<Qt::KeyboardModifiers>(
"KeyboardModifiers");
34int g_QtMouseButtons = qRegisterMetaType<Qt::MouseButtons>(
"MouseButtons");
35int g_QtMouseButton = qRegisterMetaType<Qt::MouseButton>(
"MouseButton");
36int g_QMessageBox_Icon = qRegisterMetaType<Qt::MouseButton>(
"QMessageBox::Icon");
41 , m_pParameterRecord(nullptr)
42 , m_VideoFrameInput(this)
43 , m_AudioBufferInput(this)
44 , m_AudioBufferOutput(this)
52 SetViewer(pView, bDirectConnection);
54 QString szErr = pConnecter->metaObject()->className();
55 szErr +=
"::GetViewer() is not CFrmView";
56 qDebug(log) << szErr.toStdString().c_str();
58 SetConnecter(pConnecter);
63 &m_Recorder, &QMediaRecorder::errorOccurred,
64 this, [&](QMediaRecorder::Error error,
const QString &errorString) {
65 qDebug(log) <<
"Recorder error occurred:" << error << errorString;
71 &m_Recorder, &QMediaRecorder::recorderStateChanged,
72 this, [&](QMediaRecorder::RecorderState state){
73 qDebug(log) <<
"Recorder state changed:" << state;
74 if(QMediaRecorder::StoppedState == state)
77 if(m_pParameterRecord) {
78 qDebug(log) <<
"End action:"
79 << m_pParameterRecord->GetEndAction()
80 << m_Recorder.actualLocation();
81 switch(m_pParameterRecord->GetEndAction())
83 case CParameterRecord::ENDACTION::OpenFile:
84 QDesktopServices::openUrl(m_Recorder.actualLocation());
86 case CParameterRecord::ENDACTION::OpenFolder: {
87 QFileInfo fi(m_Recorder.actualLocation().toLocalFile());
88 QDesktopServices::openUrl(
89 QUrl::fromLocalFile(fi.absolutePath()));
99 check = connect(&m_Recorder, &QMediaRecorder::actualLocationChanged,
100 this, [&](
const QUrl &location){
101 qInfo(log) <<
"Recorder actual location changed:" << location;
107CConnectDesktop::~CConnectDesktop()
109 qDebug(log) <<
"CConnectDesktop::~CConnectDesktop()";
112int CConnectDesktop::SetConnecter(
CConnecter* pConnecter)
114 qDebug(log) <<
"CConnectDesktop::SetConnecter" << pConnecter;
115 Q_ASSERT(pConnecter);
116 if(!pConnecter)
return -1;
119 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
120 pConnecter, SLOT(slotSetServerName(
const QString&)));
122 check = connect(pConnecter, SIGNAL(sigClipBoardChanged()),
125 check = connect(
this, SIGNAL(sigSetClipboard(QMimeData*)),
126 pConnecter, SLOT(slotSetClipboard(QMimeData*)));
132 check = connect(p, SIGNAL(sigRecord(
bool)),
133 this, SLOT(slotRecord(
bool)));
136 check = connect(p, SIGNAL(sigRecordPause(
bool)),
137 this, SLOT(slotRecordPause(
bool)));
141 SIGNAL(recorderStateChanged(QMediaRecorder::RecorderState)),
142 p, SLOT(slotRecorderStateChanged(QMediaRecorder::RecorderState)));
149int CConnectDesktop::SetViewer(
CFrmViewer *pView,
bool bDirectConnection)
152 if(!pView)
return -1;
155 check = connect(
this, SIGNAL(
sigConnected()), pView, SLOT(slotConnected()));
157 check = connect(
this, SIGNAL(sigSetDesktopSize(
int,
int)),
158 pView, SLOT(slotSetDesktopSize(
int,
int)));
160 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
161 pView, SLOT(slotSetName(
const QString&)));
164 check = connect(
this, SIGNAL(
sigUpdateRect(
const QRect&,
const QImage&)),
165 pView, SLOT(slotUpdateRect(
const QRect&,
const QImage&)));
168 pView, SLOT(slotUpdateRect(
const QImage&)));
170 check = connect(
this, SIGNAL(sigUpdateCursor(
const QCursor&)),
171 pView, SLOT(slotUpdateCursor(
const QCursor&)));
173 check = connect(
this, SIGNAL(sigUpdateCursorPosition(
const QPoint&)),
174 pView, SLOT(slotUpdateCursorPosition(
const QPoint&)));
176 check = connect(
this, SIGNAL(sigUpdateLedState(
unsigned int)),
177 pView, SLOT(slotUpdateLedState(
unsigned int)));
180 check = connect(
this, SIGNAL(sigRecordVideo(
bool)),
181 pView, SLOT(slotRecordVideo(
bool)));
183 check = connect(pView, SIGNAL(sigRecordVideo(QImage)),
184 this, SLOT(slotRecordVideo(QImage)),
185 Qt::DirectConnection);
188 if(bDirectConnection)
197 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
198 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)),
199 Qt::DirectConnection);
201 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
202 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)),
203 Qt::DirectConnection);
205 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
206 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)),
207 Qt::DirectConnection);
209 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
210 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)),
211 Qt::DirectConnection);
213 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
214 this, SLOT(slotKeyPressEvent(QKeyEvent*)),
215 Qt::DirectConnection);
217 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
218 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)),
219 Qt::DirectConnection);
222 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
223 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)));
225 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
226 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)));
228 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
229 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)));
231 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
232 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)));
234 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
235 this, SLOT(slotKeyPressEvent(QKeyEvent*)));
237 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
238 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)));
245void CConnectDesktop::slotWheelEvent(QWheelEvent *event, QPoint pos)
247 QWheelEvent* e =
new QWheelEvent(
249#
if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
250 event->globalPosition(),
254 event->pixelDelta(), event->angleDelta(), event->buttons(),
255 event->modifiers(), event->phase(), event->inverted(), event->source());
256 QCoreApplication::postEvent(
this, e);
260void CConnectDesktop::slotMouseMoveEvent(QMouseEvent *event, QPoint pos)
262 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
263 event->buttons(), event->modifiers());
264 QCoreApplication::postEvent(
this, e);
268void CConnectDesktop::slotMousePressEvent(QMouseEvent *event, QPoint pos)
270 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
271 event->buttons(), event->modifiers());
272 QCoreApplication::postEvent(
this, e);
276void CConnectDesktop::slotMouseReleaseEvent(QMouseEvent *event, QPoint pos)
278 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
279 event->buttons(), event->modifiers());
280 QCoreApplication::postEvent(
this, e);
284void CConnectDesktop::slotKeyPressEvent(QKeyEvent *event)
286 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
287 event->modifiers(), event->text());
288 QCoreApplication::postEvent(
this, e);
292void CConnectDesktop::slotKeyReleaseEvent(QKeyEvent *event)
294 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
295 event->modifiers(), event->text());
296 QCoreApplication::postEvent(
this, e);
300void CConnectDesktop::mouseMoveEvent(QMouseEvent *event)
302 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mouseMoveEvent";
305void CConnectDesktop::mousePressEvent(QMouseEvent *event)
307 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mousePressEvent";
310void CConnectDesktop::mouseReleaseEvent(QMouseEvent *event)
312 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mouseReleaseEvent";
315void CConnectDesktop::wheelEvent(QWheelEvent *event)
317 qDebug(logMouse) <<
"Need to implement CConnectDesktop::wheelEvent";
320void CConnectDesktop::keyPressEvent(QKeyEvent *event)
322 qDebug(logMouse) <<
"Need to implement CConnectDesktop::keyPressEvent";
325void CConnectDesktop::keyReleaseEvent(QKeyEvent *event)
327 qDebug(logMouse) <<
"Need to implement CConnectDesktop::keyReleaseEvent";
335bool CConnectDesktop::event(QEvent *event)
338 switch (event->type()) {
339 case QEvent::MouseButtonPress:
340 case QEvent::MouseButtonDblClick:
341 mousePressEvent((QMouseEvent*)event);
343 case QEvent::MouseButtonRelease:
344 mouseReleaseEvent((QMouseEvent*)event);
346 case QEvent::MouseMove:
347 mouseMoveEvent((QMouseEvent*)event);
350 wheelEvent((QWheelEvent*)event);
352 case QEvent::KeyPress:
353 keyPressEvent((QKeyEvent*)event);
355 case QEvent::KeyRelease:
356 keyReleaseEvent((QKeyEvent*)event);
359 case TypeRecordVideo:
364 return QObject::event(event);
372void CConnectDesktop::slotRecord(
bool bRecord)
374 qDebug(log) << Q_FUNC_INFO << bRecord;
376 if(QMediaRecorder::RecordingState == m_Recorder.recorderState())
378 (*m_pParameterRecord) >> m_Recorder;
379 m_CaptureSession.setVideoFrameInput(&m_VideoFrameInput);
380 m_CaptureSession.setRecorder(&m_Recorder);
384 m_CaptureSession.setVideoFrameInput(
nullptr);
385 m_CaptureSession.setAudioBufferInput(
nullptr);
386 m_CaptureSession.setRecorder(
nullptr);
388 emit sigRecordVideo(bRecord);
391void CConnectDesktop::slotRecordPause(
bool bPause)
393 qDebug(log) << Q_FUNC_INFO << bPause;
395 if(m_Recorder.recorderState() == QMediaRecorder::RecordingState)
398 if(m_Recorder.recorderState() == QMediaRecorder::PausedState)
403void CConnectDesktop::slotRecordVideo(
const QImage &img)
407 QCoreApplication::postEvent(
this, e);
413 qDebug(log) <<
"Update image";
415 if(QMediaRecorder::RecordingState != m_Recorder.recorderState()) {
416 qCritical(log) <<
"Recorder is inavailable";
419 QVideoFrame frame(e->GetImage());
420 bool bRet = m_VideoFrameInput.sendVideoFrame(frame);
424 qDebug(log) <<
"m_VideoFrameInput.sendVideoFrame fail";
CConnectDesktop(CConnecter *pConnecter, bool bDirectConnection=true)
void sigUpdateRect(const QRect &r, const QImage &image)
Notify the CFrmView update image.
virtual int WakeUp()
Wake up Connect thread(background thread)
virtual void slotClipBoardChanged()=0
Be called when the clip board change.
void sigError(const int nError, const QString &szError=QString())
Triggered when an error is generated.
void sigConnected()
Emitted when the plugin is successfully connected.
virtual int Disconnect()
Disconnect.
virtual CParameterBase * GetParameter()
Get parameter.
It starts a background thread by default.
virtual QWidget * GetViewer()=0
Get Viewer.
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...