3#include <QLoggingCategory>
4#include <QDesktopServices>
7#include <QWidgetAction>
10#include "ConnecterThread.h"
11#include "ConnectThread.h"
12#include "PluginClient.h"
14static Q_LOGGING_CATEGORY(log,
"Client.Connecter.Thread")
19 , m_pFrmViewer(
nullptr)
21 , m_pZoomToWindow(
nullptr)
22 , m_pZoomAspectRatio(
nullptr)
23 , m_pZoomOriginal(
nullptr)
26 , m_psbZoomFactor(
nullptr)
27 , m_pScreenShot(
nullptr)
30 , m_pRecordPause(
nullptr)
33 qDebug(log) << Q_FUNC_INFO;
36CConnecterThread::~CConnecterThread()
38 qDebug(log) << Q_FUNC_INFO;
43 qDebug(log) << Q_FUNC_INFO;
51 Q_ASSERT(!(m_pFrmViewer && m_pScroll));
66 qDebug(log) << Q_FUNC_INFO;
78int CConnecterThread::InitialMenu()
83 QMenu* pMenuZoom =
new QMenu(&m_Menu);
84 pMenuZoom->setTitle(tr(
"Zoom"));
85 pMenuZoom->setIcon(QIcon::fromTheme(
"zoom"));
86 m_pMenuZoom = m_Menu.addMenu(pMenuZoom);
87 m_pZoomToWindow = pMenuZoom->addAction(
88 QIcon::fromTheme(
"zoom-fit-best"), tr(
"Zoom to window"));
89 m_pZoomToWindow->setCheckable(
true);
90 check = connect(m_pZoomToWindow, &QAction::toggled,
this,
92 m_pScroll->slotSetAdaptWindows(
96 m_pZoomAspectRatio = pMenuZoom->addAction(
97 QIcon::fromTheme(
"zoom-aspect-ratio"),
98 tr(
"Keep aspect ration to windows"));
99 m_pZoomAspectRatio->setCheckable(
true);
100 check = connect(m_pZoomAspectRatio, &QAction::toggled,
this,
102 m_pScroll->slotSetAdaptWindows(
106 m_pZoomOriginal = pMenuZoom->addAction(
107 QIcon::fromTheme(
"zoom-original"), tr(
"Original"));
108 m_pZoomOriginal->setCheckable(
true);
109 check = connect(m_pZoomOriginal, &QAction::toggled,
this,
111 m_pScroll->slotSetAdaptWindows(
115 m_pZoomIn = pMenuZoom->addAction(QIcon::fromTheme(
"zoom-in"), tr(
"Zoom in"));
116 m_pZoomIn->setCheckable(
true);
118 m_pZoomIn, &QAction::toggled,
this,
121 m_psbZoomFactor->setValue((m_pFrmViewer->
GetZoomFactor() + 0.1) * 100);
124 m_pZoomOut = pMenuZoom->addAction(
125 QIcon::fromTheme(
"zoom-out"), tr(
"Zoom out"));
126 m_pZoomOut->setCheckable(
true);
128 m_pZoomOut, &QAction::toggled,
this,
131 m_psbZoomFactor->setValue((m_pFrmViewer->
GetZoomFactor() - 0.1) * 100);
134 QActionGroup* pGBViewZoom =
new QActionGroup(
this);
136 pGBViewZoom->addAction(m_pZoomToWindow);
137 pGBViewZoom->addAction(m_pZoomAspectRatio);
138 pGBViewZoom->addAction(m_pZoomOriginal);
139 pGBViewZoom->addAction(m_pZoomIn);
140 pGBViewZoom->addAction(m_pZoomOut);
142 m_psbZoomFactor =
new QSpinBox(pMenuZoom);
143 m_psbZoomFactor->setRange(0, 9999999);
144 m_psbZoomFactor->setValue(100);
145 m_psbZoomFactor->setSuffix(
"%");
146 m_psbZoomFactor->setEnabled(
false);
147 m_psbZoomFactor->setFocusPolicy(Qt::NoFocus);
149 m_psbZoomFactor, SIGNAL(valueChanged(
int)),
152 QWidgetAction* pFactor =
new QWidgetAction(pMenuZoom);
153 pFactor->setDefaultWidget(m_psbZoomFactor);
154 pMenuZoom->insertAction(m_pZoomOut, pFactor);
156 QMenu* pMenuShortCut =
new QMenu(&m_Menu);
157 pMenuShortCut->setTitle(tr(
"Send shortcut key"));
158 m_Menu.addMenu(pMenuShortCut);
159 pMenuShortCut->addAction(
160 tr(
"Send Ctl+Alt+Del"),
this, SLOT(slotShortcutCtlAltDel()));
161 pMenuShortCut->addAction(
162 tr(
"Send lock screen (Win+L)"),
this, SLOT(slotShortcutLock()));
164 m_Menu.addSeparator();
165 m_pScreenShot =
new QAction(QIcon::fromTheme(
"camera-photo"),
166 tr(
"ScreenShot"), &m_Menu);
167 check = connect(m_pScreenShot, SIGNAL(triggered()),
168 this, SLOT(slotScreenShot()));
170 m_Menu.addAction(m_pScreenShot);
172 m_pRecord =
new QAction(
173 QIcon::fromTheme(
"media-record"), tr(
"Start record"), &m_Menu);
174 m_pRecord->setCheckable(
true);
175 check = connect(m_pRecord, SIGNAL(toggled(
bool)),
176 this, SLOT(slotRecord(
bool)));
178 m_Menu.addAction(m_pRecord);
179 m_pRecordPause =
new QAction(
180 QIcon::fromTheme(
"media-playback-pause"), tr(
"Record pause"), &m_Menu);
181 m_pRecordPause->setCheckable(
true);
182 m_pRecordPause->setEnabled(
false);
183 check = connect(m_pRecordPause, SIGNAL(toggled(
bool)),
184 this, SIGNAL(sigRecordPause(
bool)));
186 m_Menu.addAction(m_pRecordPause);
189 m_Menu.addSeparator();
191 m_Menu.addAction(m_pSettings);
203 qDebug(log) << Q_FUNC_INFO;
207 qCritical(log) <<
"new CConnectThread fail";
218 qDebug(log) << Q_FUNC_INFO;
245 Q_ASSERT(m_pFrmViewer);
249 m_pFrmViewer->slotSetZoomFactor(
GetParameter()->GetZoomFactor());
251 m_psbZoomFactor->setValue(m_pFrmViewer->
GetZoomFactor() * 100);
255 m_pZoomToWindow->setChecked(
true);
257 if(m_pZoomAspectRatio)
258 m_pZoomAspectRatio->setChecked(
true);
261 m_pZoomOriginal->setChecked(
true);
264 m_pZoomIn->setChecked(
true);
276 GetParameter()->SetAdaptWindows(m_pFrmViewer->GetAdaptWindows());
284void CConnecterThread::slotRecord(
bool checked)
286 qDebug(log) << Q_FUNC_INFO << checked;
287 QAction* pRecord = qobject_cast<QAction*>(sender());
292 pRecord->setText(tr(
"Stop record"));
295 pRecord->setText(tr(
"Start record"));
297 m_pRecordPause->setEnabled(checked);
298 emit sigRecord(checked);
302void CConnecterThread::slotRecorderStateChanged(
303 QMediaRecorder::RecorderState state)
305 qDebug(log) << Q_FUNC_INFO << state;
306 if(QMediaRecorder::StoppedState == state)
308 m_pRecord->setChecked(
false);
309 m_pRecordPause->setChecked(
false);
316 if(!m_pScroll || !m_pFrmViewer)
return;
317 m_pFrmViewer->slotSetZoomFactor(((
double)v) / 100);
321void CConnecterThread::slotScreenShot()
326 QString szFile = record.GetImageFile(
true);
327 bool bRet = m_pFrmViewer->GrabImage().save(szFile);
329 qDebug(log) <<
"Success: save screenshot to" << szFile;
331 qCritical(log) <<
"Fail: save screenshot to" << szFile;
332 if(record.GetEndAction() != CParameterRecord::ENDACTION::No)
333 QDesktopServices::openUrl(QUrl::fromLocalFile(szFile));
336void CConnecterThread::slotShortcutCtlAltDel()
342 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Control, Qt::ControlModifier));
343 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Alt, Qt::AltModifier));
344 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Delete, Qt::ControlModifier | Qt::AltModifier));
345 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Control, Qt::ControlModifier));
346 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Alt, Qt::AltModifier));
347 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Delete, Qt::ControlModifier | Qt::AltModifier));
350void CConnecterThread::slotShortcutLock()
356 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_Super_L, Qt::NoModifier));
357 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyPress, Qt::Key_L, Qt::NoModifier));
358 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_Super_L, Qt::NoModifier));
359 emit m_pFrmViewer->sigKeyPressEvent(
new QKeyEvent(QKeyEvent::KeyRelease, Qt::Key_L, Qt::NoModifier));
The class only is used by CConnecterThread.
The connector interface of the plug-in, which is only used by the plug-in.
virtual CParameterBase * GetParameter()
Get parameter.
virtual QString ServerName()
Current connect server name (remote desktop name, if not present, then IP:PORT).
It starts a background thread by default.
virtual int Load(QSettings &set) override
Load parameters.
virtual QWidget * GetViewer() override
Get Viewer.
virtual int Initial() override
Initial parameters and resource.
void slotValueChanged(int v)
emit by zoom menu in the class
virtual int Clean() override
Clean parameters and resource.
virtual int DisConnect() override
emit sigConnected() in CConnectThread::run()
virtual QString ServerName() override
Current connect server name (remote desktop name, if not present, then IP:PORT).
virtual int Connect() override
Start a background thread, and create an instance of CConnect .
virtual int Save(QSettings &set) override
Save parameters.
virtual int Load(QSettings &set)
Load parameters.
virtual Q_INVOKABLE int Clean()
Clean parameters and resource.
virtual int Save(QSettings &set)
Save parameters.
virtual Q_INVOKABLE int Initial()
Initial parameters and resource.
void sigViewerFocusIn(QWidget *pView)
The view is focus.
A widget which displays output image from a CConnectDesktop and sends input keypresses and mouse acti...
ADAPT_WINDOWS
The ADAPT_WINDOWS enum.
@ Original
Original desktop size, the left-top of the desktop is aligned with the left-top of the window.
@ Zoom
zoom windows = desktop size * factor
@ KeepAspectRationToWindow
Keep desktop aspectration adapt to windows.
@ ZoomToWindow
Desktop adapt to windows.
double GetZoomFactor() const
Adjust the zoom factor.