API Documentation
Loading...
Searching...
No Matches
VncClientWidget.h
Go to the documentation of this file.
1#pragma once
4#include <NDEVR/Device.h>
7#include "Base/Headers/Time.h"
8#include <QWidget>
9#include <QtWidgets>
10#include <QtNetwork>
11#include <QRegion>
12#include <QKeyEvent>
13namespace NDEVR
14{
15 class TcpServer;
16 struct VncScreen
17 {
19 QRect rect;
21 };
22 class VncClientWidget;
23 class VncDevice : public Device
24 {
25 Q_OBJECT
26 public:
27 explicit VncDevice(VncClientWidget* parent);
28 ~VncDevice();
29 void update() override;
30 [[nodiscard]] virtual TimeSpan updateInterval() const override;
31 bool connectToVncServer(const String& ip, const String& password, int port = 5900);
32 bool connectToVncServer();
35 void requestFullRefresh();
36
37
38 bool postEvent(QEvent* event);
39 void postKeyEvent(QKeyEvent* event, bool is_down);
40
41 protected:
42 void waitToRead(uint04 size) const;
43 bool sendCommand(const char* const command, uint04 min_response_size, uint04 retry_count);
44
45 void sendEncodings();
46 void sendContinuousUpdateRequest(bool enable);
47 void sendUpdateFrameBufferRequest(bool force_refresh_all);
48 void sendRequestDesktopSize(QSize size, fltp08 scale_factor = 1.0);
49 void sendMouseEvent(const MouseEvent& event);
50 void sendKeyEvent(bool is_pressed, QKeyEvent* event);
51 void sendKeyEvent(bool is_pressed, const KeyEvent& event);
52 bool setupVncConnection(const String& password);
53 void tearDownTcp();
54
55 QByteArray desHash(QByteArray challenge, QString passStr);
56 uint02 makeU16(quint8 l, quint8 h);
57 uint04 makeU32(quint16 l, quint16 h);
58 uint04 makeU32(quint8 lowest, quint8 low, quint8 high, quint8 highest);
59 static quint32 TranslateRfbKey(int key, bool modifier);
61 void setFrameBufferSize(const QSize& size);
62 private slots:
63 void onServerMessage();
64 protected:
65 NDEVRMouseManager m_mouse_manager;
67 QTcpSocket* m_socket;
79 int m_port;
80
83 bool m_setup_connection = false;
90 bool m_is_ready = false;
91
92 };
93 class VncClientWidget : public QWidget
94 {
95 static constexpr uint01 s_screen_count = 2;
96 Q_OBJECT
97 public:
98 explicit VncClientWidget(QWidget* parent = 0);
100 void mousePressEvent(QMouseEvent* event) override;
101 bool connectToVncServer(const String& ip, const String& password, int port = 5900);
102 bool isConnectedToServer();
104 void tryRefreshScreen(bool force_refresh_all);
105 void setResizeTcpServer(TcpServer* server, fltp08 size_multiplier);
106 void setMouse(const Vector<2, uint04>& hotspot, QImage mouse);
107 QImage* imageToRender();
108 void refreshTcpSize();
109 void commit(const QRegion& region);
110 protected:
111 bool event(QEvent* event) override;
112 void paintEvent(QPaintEvent*) override;
113 void keyPressEvent(QKeyEvent* event) override;
114 void keyReleaseEvent(QKeyEvent* event) override;
115 void resizeEvent(QResizeEvent* event) override;
116 private:
117 VncDevice* m_device;
118 TcpServer* m_tcp_server;
119 fltp08 m_size_multiplier;
120 QImage m_screen_buffer[s_screen_count];
121 uint01 m_screen_index = 0;
122 bool m_is_painting;
123 };
124}
125
126
A bitset that stores 8 bits (elements with only two possible values: 0 or 1, true or false,...
Definition BitFlag.hpp:68
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Device.h:48
Definition Event.h:42
Vector< 3, fltp08 > size() const
Definition Model.cpp:223
Definition Event.h:276
Definition String.h:40
Definition TcpServer.h:14
Represents a timestamp with utilities for manipulation and conversion.
Definition Time.h:54
Definition TimeSpan.h:40
An element of a vector space. An element of the real coordinate space Rn Basis vector,...
Definition Vector.hpp:62
Definition VncClientWidget.h:94
void setMouse(const Vector< 2, uint04 > &hotspot, QImage mouse)
Definition VncClientWidget.cpp:1217
void keyReleaseEvent(QKeyEvent *event) override
Definition VncClientWidget.cpp:1312
void paintEvent(QPaintEvent *) override
Definition VncClientWidget.cpp:1274
void tryRefreshScreen(bool force_refresh_all)
Definition VncClientWidget.cpp:1206
~VncClientWidget()
Definition VncClientWidget.cpp:1201
bool event(QEvent *event) override
Definition VncClientWidget.cpp:1261
void setResizeTcpServer(TcpServer *server, fltp08 size_multiplier)
Definition VncClientWidget.cpp:1211
void keyPressEvent(QKeyEvent *event) override
Definition VncClientWidget.cpp:1306
void disconnectFromVncServer()
Definition VncClientWidget.cpp:1300
void mousePressEvent(QMouseEvent *event) override
Definition VncClientWidget.cpp:1288
void refreshTcpSize()
Definition VncClientWidget.cpp:1245
void commit(const QRegion &region)
Definition VncClientWidget.cpp:1252
void resizeEvent(QResizeEvent *event) override
Definition VncClientWidget.cpp:1317
QImage * imageToRender()
Definition VncClientWidget.cpp:1234
bool isConnectedToServer()
Definition VncClientWidget.cpp:1293
VncClientWidget(QWidget *parent=0)
Definition VncClientWidget.cpp:1180
bool connectToVncServer(const String &ip, const String &password, int port=5900)
Definition VncClientWidget.cpp:1194
Definition VncClientWidget.h:24
Buffer< VncScreen > m_screens
Definition VncClientWidget.h:73
virtual TimeSpan updateInterval() const override
Definition VncClientWidget.cpp:57
void readFrameBufferMessage()
Definition VncClientWidget.cpp:899
uint04 makeU32(quint16 l, quint16 h)
Definition VncClientWidget.cpp:669
void sendKeyEvent(bool is_pressed, QKeyEvent *event)
Definition VncClientWidget.cpp:1159
bool m_supports_continuous_updates
Definition VncClientWidget.h:86
void sendMouseEvent(const MouseEvent &event)
Definition VncClientWidget.cpp:573
fltp04 m_jpg_quality
Definition VncClientWidget.h:81
PixelFormat m_pixel_format
Definition VncClientWidget.h:74
~VncDevice()
Definition VncClientWidget.cpp:52
void sendRequestDesktopSize(QSize size, fltp08 scale_factor=1.0)
Definition VncClientWidget.cpp:256
Time m_last_full_refresh_time
Definition VncClientWidget.h:69
Buffer< bool > m_key_down_events
Definition VncClientWidget.h:76
void tearDownTcp()
Definition VncClientWidget.cpp:405
void update() override
Definition VncClientWidget.cpp:110
static quint32 TranslateRfbKey(int key, bool modifier)
Definition VncClientWidget.cpp:689
String m_connection
Definition VncClientWidget.h:72
bool m_is_ready
Definition VncClientWidget.h:90
Buffer< KeyEvent > m_key_events
Definition VncClientWidget.h:75
QByteArray desHash(QByteArray challenge, QString passStr)
Definition VncClientWidget.cpp:199
BitFlag m_mouse_button_flag
Definition VncClientWidget.h:77
VncDevice(VncClientWidget *parent)
Definition VncClientWidget.cpp:41
void disconnectFromVncServer()
Definition VncClientWidget.cpp:551
int m_port
Definition VncClientWidget.h:79
void waitToRead(uint04 size) const
Definition VncClientWidget.cpp:470
void sendUpdateFrameBufferRequest(bool force_refresh_all)
Definition VncClientWidget.cpp:239
void sendContinuousUpdateRequest(bool enable)
Definition VncClientWidget.cpp:222
QSize m_frame_size
Definition VncClientWidget.h:68
void requestFullRefresh()
Definition VncClientWidget.cpp:567
bool m_has_sent_frame_request
Definition VncClientWidget.h:82
bool postEvent(QEvent *event)
Definition VncClientWidget.cpp:624
void sendEncodings()
Definition VncClientWidget.cpp:424
QImage m_copy_image
Definition VncClientWidget.h:78
bool m_request_full_refresh
Definition VncClientWidget.h:84
bool m_supports_extended_size
Definition VncClientWidget.h:87
void postKeyEvent(QKeyEvent *event, bool is_down)
Definition VncClientWidget.cpp:629
bool m_setup_connection
Definition VncClientWidget.h:83
bool m_request_disconnect
Definition VncClientWidget.h:88
Time m_last_refresh_time
Definition VncClientWidget.h:70
void setFrameBufferSize(const QSize &size)
Definition VncClientWidget.cpp:1129
bool sendCommand(const char *const command, uint04 min_response_size, uint04 retry_count)
Definition VncClientWidget.cpp:636
bool m_is_continuous_mode
Definition VncClientWidget.h:85
VncClientWidget * m_widget
Definition VncClientWidget.h:66
bool isConnectedToServer()
Definition VncClientWidget.cpp:541
bool connectToVncServer()
Definition VncClientWidget.cpp:69
QTcpSocket * m_socket
Definition VncClientWidget.h:67
NDEVRMouseManager m_mouse_manager
Definition VncClientWidget.h:65
uint02 makeU16(quint8 l, quint8 h)
Definition VncClientWidget.cpp:661
String m_password
Definition VncClientWidget.h:71
bool setupVncConnection(const String &password)
Definition VncClientWidget.cpp:298
bool m_request_client_resize
Definition VncClientWidget.h:89
Definition ACIColor.h:37
float fltp04
Defines an alias representing a 4 byte floating-point number.
Definition BaseValues.hpp:157
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:98
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:109
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:181
Definition VncDefines.h:1680
Definition VncClientWidget.h:17
uint04 id
Definition VncClientWidget.h:18
QRect rect
Definition VncClientWidget.h:19
uint04 flags
Definition VncClientWidget.h:20