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)
27 qDebug(log) << Q_FUNC_INFO;
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<Qt::MouseButton>(
"QMessageBox::Icon");
46 , m_pParameterRecord(nullptr)
47 , m_VideoFrameInput(this)
48 , m_AudioBufferInput(this)
49 , m_AudioBufferOutput(this)
57 SetViewer(pView, pConnecter, bDirectConnection);
59 QString szErr = pConnecter->metaObject()->className();
60 szErr +=
"::GetViewer() is not CFrmViewer";
61 qWarning(log) << szErr.toStdString().c_str();
64 QString szErr = pConnecter->metaObject()->className();
65 szErr +=
"::GetViewer() is not CFrmScroll";
66 qWarning(log) << szErr.toStdString().c_str();
68 SetConnecter(pConnecter);
73 &m_Recorder, &QMediaRecorder::errorOccurred,
74 this, [&](QMediaRecorder::Error error,
const QString &errorString) {
75 qDebug(log) <<
"Recorder error occurred:" << error << errorString;
81 &m_Recorder, &QMediaRecorder::recorderStateChanged,
82 this, [&](QMediaRecorder::RecorderState state){
83 qDebug(log) <<
"Recorder state changed:" << state;
84 if(QMediaRecorder::StoppedState == state)
87 if(m_pParameterRecord) {
88 qDebug(log) <<
"End action:"
89 << m_pParameterRecord->GetEndAction()
90 << m_Recorder.actualLocation();
91 switch(m_pParameterRecord->GetEndAction())
93 case CParameterRecord::ENDACTION::OpenFile:
94 QDesktopServices::openUrl(m_Recorder.actualLocation());
96 case CParameterRecord::ENDACTION::OpenFolder: {
97 QFileInfo fi(m_Recorder.actualLocation().toLocalFile());
98 QDesktopServices::openUrl(
99 QUrl::fromLocalFile(fi.absolutePath()));
109 check = connect(&m_Recorder, &QMediaRecorder::actualLocationChanged,
110 this, [&](
const QUrl &location){
111 qInfo(log) <<
"Recorder actual location changed:" << location;
117CConnectDesktop::~CConnectDesktop()
119 qDebug(log) <<
"CConnectDesktop::~CConnectDesktop()";
122int CConnectDesktop::SetConnecter(
CConnecter* pConnecter)
124 qDebug(log) <<
"CConnectDesktop::SetConnecter" << pConnecter;
125 Q_ASSERT(pConnecter);
126 if(!pConnecter)
return -1;
129 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
130 pConnecter, SLOT(slotSetServerName(
const QString&)));
132 check = connect(pConnecter, SIGNAL(sigClipBoardChanged()),
135 check = connect(
this, SIGNAL(sigSetClipboard(QMimeData*)),
136 pConnecter, SLOT(slotSetClipboard(QMimeData*)));
142 check = connect(p, SIGNAL(sigRecord(
bool)),
143 this, SLOT(slotRecord(
bool)));
146 check = connect(p, SIGNAL(sigRecordPause(
bool)),
147 this, SLOT(slotRecordPause(
bool)));
151 SIGNAL(recorderStateChanged(QMediaRecorder::RecorderState)),
152 p, SLOT(slotRecorderStateChanged(QMediaRecorder::RecorderState)));
159int CConnectDesktop::SetViewer(
CFrmViewer *pView,
160 CConnecter* pConnecter,
bool bDirectConnection)
163 if(!pView)
return -1;
166 check = connect(
this, SIGNAL(
sigConnected()), pView, SLOT(slotConnected()));
168 check = connect(
this, SIGNAL(sigSetDesktopSize(
int,
int)),
169 pView, SLOT(slotSetDesktopSize(
int,
int)));
171 check = connect(
this, SIGNAL(sigServerName(
const QString&)),
172 pView, SLOT(slotSetName(
const QString&)));
175 check = connect(
this, SIGNAL(
sigUpdateRect(
const QRect&,
const QImage&)),
176 pView, SLOT(slotUpdateRect(
const QRect&,
const QImage&)));
179 pView, SLOT(slotUpdateRect(
const QImage&)));
181 check = connect(
this, SIGNAL(sigUpdateCursor(
const QCursor&)),
182 pView, SLOT(slotUpdateCursor(
const QCursor&)));
184 check = connect(
this, SIGNAL(sigUpdateCursorPosition(
const QPoint&)),
185 pView, SLOT(slotUpdateCursorPosition(
const QPoint&)));
187 check = connect(
this, SIGNAL(sigUpdateLedState(
unsigned int)),
188 pView, SLOT(slotUpdateLedState(
unsigned int)));
192 check = connect(
this, SIGNAL(sigRecordVideo(
bool)),
193 pView, SLOT(slotRecordVideo(
bool)));
195 check = connect(pView, SIGNAL(sigRecordVideo(QImage)),
196 this, SLOT(slotRecordVideo(QImage)),
197 Qt::DirectConnection);
200 if(bDirectConnection)
209 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
210 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)),
211 Qt::DirectConnection);
213 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
214 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)),
215 Qt::DirectConnection);
217 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
218 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)),
219 Qt::DirectConnection);
221 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
222 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)),
223 Qt::DirectConnection);
225 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
226 this, SLOT(slotKeyPressEvent(QKeyEvent*)),
227 Qt::DirectConnection);
229 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
230 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)),
231 Qt::DirectConnection);
234 check = connect(pView, SIGNAL(sigMousePressEvent(QMouseEvent*, QPoint)),
235 this, SLOT(slotMousePressEvent(QMouseEvent*, QPoint)));
237 check = connect(pView, SIGNAL(sigMouseReleaseEvent(QMouseEvent*, QPoint)),
238 this, SLOT(slotMouseReleaseEvent(QMouseEvent*, QPoint)));
240 check = connect(pView, SIGNAL(sigMouseMoveEvent(QMouseEvent*, QPoint)),
241 this, SLOT(slotMouseMoveEvent(QMouseEvent*, QPoint)));
243 check = connect(pView, SIGNAL(sigWheelEvent(QWheelEvent*, QPoint)),
244 this, SLOT(slotWheelEvent(QWheelEvent*, QPoint)));
246 check = connect(pView, SIGNAL(sigKeyPressEvent(QKeyEvent*)),
247 this, SLOT(slotKeyPressEvent(QKeyEvent*)));
249 check = connect(pView, SIGNAL(sigKeyReleaseEvent(QKeyEvent*)),
250 this, SLOT(slotKeyReleaseEvent(QKeyEvent*)));
257void CConnectDesktop::slotWheelEvent(QWheelEvent *event, QPoint pos)
259 QWheelEvent* e =
new QWheelEvent(
261#
if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
262 event->globalPosition(),
266 event->pixelDelta(), event->angleDelta(), event->buttons(),
267 event->modifiers(), event->phase(), event->inverted(), event->source());
268 QCoreApplication::postEvent(
this, e);
272void CConnectDesktop::slotMouseMoveEvent(QMouseEvent *event, QPoint pos)
274 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
275 event->buttons(), event->modifiers());
276 QCoreApplication::postEvent(
this, e);
280void CConnectDesktop::slotMousePressEvent(QMouseEvent *event, QPoint pos)
282 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
283 event->buttons(), event->modifiers());
284 QCoreApplication::postEvent(
this, e);
288void CConnectDesktop::slotMouseReleaseEvent(QMouseEvent *event, QPoint pos)
290 QMouseEvent* e =
new QMouseEvent(event->type(), pos, event->button(),
291 event->buttons(), event->modifiers());
292 QCoreApplication::postEvent(
this, e);
296void CConnectDesktop::slotKeyPressEvent(QKeyEvent *event)
298 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
299 event->modifiers(), event->text());
300 QCoreApplication::postEvent(
this, e);
304void CConnectDesktop::slotKeyReleaseEvent(QKeyEvent *event)
306 QKeyEvent* e =
new QKeyEvent(event->type(), event->key(),
307 event->modifiers(), event->text());
308 QCoreApplication::postEvent(
this, e);
312void CConnectDesktop::mouseMoveEvent(QMouseEvent *event)
314 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mouseMoveEvent";
317void CConnectDesktop::mousePressEvent(QMouseEvent *event)
319 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mousePressEvent";
322void CConnectDesktop::mouseReleaseEvent(QMouseEvent *event)
324 qDebug(logMouse) <<
"Need to implement CConnectDesktop::mouseReleaseEvent";
327void CConnectDesktop::wheelEvent(QWheelEvent *event)
329 qDebug(logMouse) <<
"Need to implement CConnectDesktop::wheelEvent";
332void CConnectDesktop::keyPressEvent(QKeyEvent *event)
334 qDebug(logMouse) <<
"Need to implement CConnectDesktop::keyPressEvent";
337void CConnectDesktop::keyReleaseEvent(QKeyEvent *event)
339 qDebug(logMouse) <<
"Need to implement CConnectDesktop::keyReleaseEvent";
347bool CConnectDesktop::event(QEvent *event)
350 switch (event->type()) {
351 case QEvent::MouseButtonPress:
352 case QEvent::MouseButtonDblClick:
353 mousePressEvent((QMouseEvent*)event);
355 case QEvent::MouseButtonRelease:
356 mouseReleaseEvent((QMouseEvent*)event);
358 case QEvent::MouseMove:
359 mouseMoveEvent((QMouseEvent*)event);
362 wheelEvent((QWheelEvent*)event);
364 case QEvent::KeyPress:
365 keyPressEvent((QKeyEvent*)event);
367 case QEvent::KeyRelease:
368 keyReleaseEvent((QKeyEvent*)event);
371 case TypeRecordVideo:
376 return QObject::event(event);
384void CConnectDesktop::slotRecord(
bool bRecord)
386 qDebug(log) << Q_FUNC_INFO << bRecord;
388 if(QMediaRecorder::RecordingState == m_Recorder.recorderState())
390 (*m_pParameterRecord) >> m_Recorder;
391 m_CaptureSession.setVideoFrameInput(&m_VideoFrameInput);
392 m_CaptureSession.setRecorder(&m_Recorder);
396 m_CaptureSession.setVideoFrameInput(
nullptr);
397 m_CaptureSession.setAudioBufferInput(
nullptr);
398 m_CaptureSession.setRecorder(
nullptr);
400 emit sigRecordVideo(bRecord);
403void CConnectDesktop::slotRecordPause(
bool bPause)
405 qDebug(log) << Q_FUNC_INFO << bPause;
407 if(m_Recorder.recorderState() == QMediaRecorder::RecordingState)
410 if(m_Recorder.recorderState() == QMediaRecorder::PausedState)
415void CConnectDesktop::slotRecordVideo(
const QImage &img)
419 QCoreApplication::postEvent(
this, e);
425 qDebug(log) <<
"Update image";
427 if(QMediaRecorder::RecordingState != m_Recorder.recorderState()) {
428 qCritical(log) <<
"Recorder is inavailable";
431 QVideoFrame frame(e->GetImage());
432 bool bRet = m_VideoFrameInput.sendVideoFrame(frame);
436 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...