-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvncclientwidget2cls.cpp
198 lines (164 loc) · 5.9 KB
/
vncclientwidget2cls.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (C) 2013 Azril Azam
*
* Desc
*
* This file is a part of the 100% Qt5 VNC RFB-CLIENT implementation without
* using any 3rd party rfb library
*
* rfbclientwidget2cls.cpp
*
*
* Qt5 RFB-CLIENT is free software: you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Qt5 RFB-CLIENT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Qt HTML platform plugin. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include "vncclientwidget2cls.h"
vncclientwidget2cls::vncclientwidget2cls(QWidget *parent) :
QWidget(parent)
{
QPalette pl;
this->setAutoFillBackground(true);
pl.setColor(QPalette::Background,Qt::black);
this->setPalette(pl);
this->widgetResizing = false;
this->rfbWidget.setParent(this);
this->rfbWidget.hide();
this->setMinimumSize(640,480);
connect(&this->rfbWidget,SIGNAL(vncFrameResizeSignal()),this,SLOT(vncFrameResizeSlot()));
connect(&this->rfbWidget,SIGNAL(rfbClientDisconnectedSignal()),this,SLOT(rfbClientDisconnectedSlot()));
connect(&this->rfbWidget,SIGNAL(rfbClientPauseSignal()),this,SLOT(rfbClientPauseSlot()));
connect(&this->rfbWidget,SIGNAL(vncGrabIOSIG()),this,SLOT(rfbClientScreenLockSlot()));
connect(&this->rfbWidget,SIGNAL(vncUngrabIOSIG()),this,SLOT(rfbClientScreenUnlockSlot()));
this->rfbWidget.move(0,0);
this->rfbWidget.show();
this->resize(640,480);
}
vncclientwidget2cls::~vncclientwidget2cls()
{
disconnect(&this->rfbWidget,SIGNAL(vncFrameResizeSignal()),this,SLOT(vncFrameResizeSlot()));
//disconnect(this->rfbWidget,SIGNAL(rfbClientConnectedSignal()),this,SLOT(vncClientConnectedSignal()));
disconnect(&this->rfbWidget,SIGNAL(rfbClientDisconnectedSignal()),this,SLOT(rfbClientDisconnectedSlot()));
disconnect(&this->rfbWidget,SIGNAL(rfbClientPauseSignal()),this,SLOT(rfbClientPauseSlot()));
disconnect(&this->rfbWidget,SIGNAL(vncGrabIOSIG()),this,SLOT(rfbClientScreenLockSlot()));
disconnect(&this->rfbWidget,SIGNAL(vncUngrabIOSIG()),this,SLOT(rfbClientScreenUnlockSlot()));
}
QImage vncclientwidget2cls::getScreenCapture()
{
return this->rfbWidget.getScreenCapture();
}
void vncclientwidget2cls::changeEvent(QEvent *E)
{
//handle min max
if (E->type() == QEvent::WindowStateChange)
{
QWindowStateChangeEvent* event = static_cast< QWindowStateChangeEvent* >( E);
if( event->oldState() & Qt::WindowMinimized )
this->updateSize();
else if ( event->oldState() == Qt::WindowNoState && this->windowState() == Qt::WindowMaximized )
this->updateSize();
}
}
bool vncclientwidget2cls::connectVNCIPC(QString server)
{
qDebug() << "Connecting VNCIPC at" << server;
return this->rfbWidget.connectVNCIPC(server);
}
bool vncclientwidget2cls::connectVNCTCP(QString server, qint16 port)
{
return this->rfbWidget.connectVNCTCP(server,port);
}
void vncclientwidget2cls::disconnectVNC()
{
this->rfbWidget.disconnectVNC();
}
void vncclientwidget2cls::rfbClientDisconnectedSlot()
{
emit this->vncClientDisconnectedSignal();
}
void vncclientwidget2cls::rfbClientPauseSlot()
{
emit this->vncClientPauseSignal();
}
void vncclientwidget2cls::rfbClientConnectedSlot()
{
emit this->vncClientConnectedSignal();
}
void vncclientwidget2cls::rfbClientScreenLockSlot()
{
emit this->vncClientScreenLockSignal();
}
void vncclientwidget2cls::rfbClientScreenUnlockSlot()
{
emit this->vncClientScreenUnlockSignal();
}
void vncclientwidget2cls::resizeEvent(QResizeEvent *)
{
this->updateSize();
}
void vncclientwidget2cls::closeEvent(QCloseEvent *E)
{
E->ignore();
this->disconnectVNC();
E->accept();
}
void vncclientwidget2cls::vncFrameResizeSlot()
{
qDebug() << "updateSize";
this->updateSize();
emit this->vncFrameResizeEvent();
}
void vncclientwidget2cls::updateSize()
{
this->widgetResizing = true;
//resize width to rfbwidget
if (this->geometry().width() < this->rfbWidget.maximumWidth())
this->rfbWidget.resize(this->geometry().width(),this->rfbWidget.geometry().height());
//resize width to maximum
if (this->geometry().width() >= this->rfbWidget.maximumWidth())
this->rfbWidget.resize(this->rfbWidget.maximumWidth(),this->rfbWidget.geometry().height());
//resize height to rfbwidget
if (this->geometry().height() < this->rfbWidget.maximumHeight())
this->rfbWidget.resize(this->rfbWidget.geometry().width(),this->geometry().height());
if (this->geometry().height() >= this->rfbWidget.maximumHeight())
this->rfbWidget.resize(this->rfbWidget.geometry().width(),this->rfbWidget.maximumHeight());
if (this->geometry().width() < this->rfbWidget.maximumWidth())
this->rfbWidget.move(0,this->rfbWidget.y());
else
{
//move to center
qint32 mX = this->rfbWidget.geometry().width() /2;
qint32 rw = this->geometry().width()/2;
qint32 tgtX = rw - mX;
this->rfbWidget.move(tgtX,this->rfbWidget.y());
}
if (this->geometry().height() < this->rfbWidget.maximumHeight())
this->rfbWidget.move(this->rfbWidget.x(),0);
else
{
qint32 mY = this->rfbWidget.geometry().height()/2;
qint32 rh = this->geometry().height()/2;
qint32 tgtY = rh - mY;
this->rfbWidget.move(this->rfbWidget.x(),tgtY);
}
this->widgetResizing = false;
}
bool vncclientwidget2cls::setPauseVNC()
{
return this->rfbWidget.setPauseRFB();
}
bool vncclientwidget2cls::setResumeVNC()
{
return this->rfbWidget.setResumeRFB();
}