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 m_Menu.addSeparator();
157 m_pScreenShot =
new QAction(QIcon::fromTheme(
"camera-photo"),
158 tr(
"ScreenShot"), &m_Menu);
159 check = connect(m_pScreenShot, SIGNAL(triggered()),
160 this, SLOT(slotScreenShot()));
162 m_Menu.addAction(m_pScreenShot);
164 m_pRecord =
new QAction(
165 QIcon::fromTheme(
"media-record"), tr(
"Start record"), &m_Menu);
166 m_pRecord->setCheckable(
true);
167 check = connect(m_pRecord, SIGNAL(toggled(
bool)),
168 this, SLOT(slotRecord(
bool)));
170 m_Menu.addAction(m_pRecord);
171 m_pRecordPause =
new QAction(
172 QIcon::fromTheme(
"media-playback-pause"), tr(
"Record pause"), &m_Menu);
173 m_pRecordPause->setCheckable(
true);
174 m_pRecordPause->setEnabled(
false);
175 check = connect(m_pRecordPause, SIGNAL(toggled(
bool)),
176 this, SIGNAL(sigRecordPause(
bool)));
178 m_Menu.addAction(m_pRecordPause);
181 m_Menu.addSeparator();
183 m_Menu.addAction(m_pSettings);
195 qDebug(log) << Q_FUNC_INFO;
199 qCritical(log) <<
"new CConnectThread fail";
210 qDebug(log) << Q_FUNC_INFO;
237 Q_ASSERT(m_pFrmViewer);
241 m_pFrmViewer->slotSetZoomFactor(
GetParameter()->GetZoomFactor());
243 m_psbZoomFactor->setValue(m_pFrmViewer->
GetZoomFactor() * 100);
247 m_pZoomToWindow->setChecked(
true);
249 if(m_pZoomAspectRatio)
250 m_pZoomAspectRatio->setChecked(
true);
253 m_pZoomOriginal->setChecked(
true);
256 m_pZoomIn->setChecked(
true);
268 GetParameter()->SetAdaptWindows(m_pFrmViewer->GetAdaptWindows());
276void CConnecterThread::slotRecord(
bool checked)
278 qDebug(log) << Q_FUNC_INFO << checked;
279 QAction* pRecord = qobject_cast<QAction*>(sender());
284 pRecord->setText(tr(
"Stop record"));
287 pRecord->setText(tr(
"Start record"));
289 m_pRecordPause->setEnabled(checked);
290 emit sigRecord(checked);
294void CConnecterThread::slotRecorderStateChanged(
295 QMediaRecorder::RecorderState state)
297 qDebug(log) << Q_FUNC_INFO << state;
298 if(QMediaRecorder::StoppedState == state)
300 m_pRecord->setChecked(
false);
301 m_pRecordPause->setChecked(
false);
308 if(!m_pScroll || !m_pFrmViewer)
return;
309 m_pFrmViewer->slotSetZoomFactor(((
double)v) / 100);
313void CConnecterThread::slotScreenShot()
318 QString szFile = record.GetImageFile(
true);
319 bool bRet = m_pFrmViewer->GrabImage().save(szFile);
321 qDebug(log) <<
"Success: save screenshot to" << szFile;
323 qCritical(log) <<
"Fail: save screenshot to" << szFile;
324 if(record.GetEndAction() != CParameterRecord::ENDACTION::No)
325 QDesktopServices::openUrl(QUrl::fromLocalFile(szFile));
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.