20 #include "../clientapp/clientapp.h"
22 #include <QGuiApplication>
35 static int gcd(
int a,
int b)
43 QWidget(parent), _srcStepX(1), _srcStepY(1), _dstStepX(1), _dstStepY(1),
44 _vncWorker(nullptr), _viewOnly(true), _multiScreen(false), _clientId(0), _redrawTimer(0), _tcpTimeoutTimer(0)
46 auto *upper =
new QTimer(
this);
85 qDebug() <<
"Deleting thread" << QObject::sender();
86 delete QObject::sender();
106 QPainter painter(
this);
112 const int endX = (x + w - 1) /
_dstStepX + 1;
113 const int endY = (y + h - 1) /
_dstStepY + 1;
117 const int dstW = endX * _dstStepX - dstX;
118 const int dstH = endY * _dstStepY - dstY;
122 const int srcW = endX * _srcStepX - srcX;
123 const int srcH = endY * _srcStepY - srcY;
126 buffer->copy(srcX, srcY, srcW, srcH).scaled(dstW, dstH, Qt::IgnoreAspectRatio, Qt::SmoothTransformation));
127 painter.drawImage(dstX, dstY, scaled, 0, 0, dstW, dstH);
130 painter.drawImage(x, y, *buffer, x, y, w, h);
150 (remote ==
nullptr || remote->size() ==
_remoteSize))
152 const QSize mySize = this->size();
153 const QSize remoteSize = remote ==
nullptr ?
_remoteSize : remote->size();
154 if (mySize.isEmpty())
156 if (remoteSize.isEmpty())
186 void VncWindow::open(
const QString& host,
int port,
const QString& passwd,
bool ,
bool fullscreen,
const QString& caption,
const int clientId,
const QByteArray& rawThumb)
196 setWindowTitle(caption);
198 setAttribute(Qt::WA_OpaquePaintEvent);
203 setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint | Qt::Tool);
206 for (
auto *screen : QGuiApplication::screens()) {
207 QRect r = screen->geometry();
208 if (best.isNull() || r.left() > best.left()) {
213 qDebug() <<
"Spawning VNC viewer at" << best;
220 move(best.topLeft());
222 setWindowFlags(Qt::Tool | Qt::WindowMaximizeButtonHint);
244 qDebug(
"Closing VNC viewer window.");
275 this->update(x, y, w, h);
313 if (this->isHidden())
345 killTimer(event->timerId());
359 QPainter painter(
this);
361 painter.drawPixmap(0, 0, this->width(), this->height(),
_remoteThumb);
363 painter.fillRect(event->rect(), QColor(60, 63, 66));
365 QFontInfo fi = painter.fontInfo();
366 painter.setPen(QColor(200, 100, 10));
367 painter.setFont(QFont(fi.family(), 28, fi.weight(), fi.italic()));
368 painter.drawText(this->contentsRect(), Qt::AlignCenter, tr(
"Connecting..."));
370 const QRect &r =
event->rect();
371 this->
draw(r.left(), r.top(), r.width(), r.height());
381 if (event->modifiers() == 0 &&
clientApp->isConnectedToLocalManager()) {
384 QWidget::keyReleaseEvent(event);
void draw(const int x, const int y, const int w, const int h)
Draws given part of the current VNC frame buffer to the window.
void timerEvent(QTimerEvent *event)
Called when a Qt timer fires.
const QSharedPointer< QImage > & getFrameBuffer()
void closeEvent(QCloseEvent *e)
Called by Qt if the window is requested to be closed.
void onProjectionStarted()
Triggered by _vncWorker after successfully connecting to the VNC server.
VncThread - communicate with VNC server, scale image if necessary.
bool calcScaling(const QImage *remote)
When using image scaling, calc matching pixel borders for both resolutions to prevent artifacts throu...
void terminateVncThread()
Terminates the vnc worker thread and stops all related timers.
static int gcd(int a, int b)
Calc greatest common divisor.
void imageUpdated(const int x, const int y, const int w, const int h)
void running(const bool isRunning, const int clientId)
void paintEvent(QPaintEvent *event)
Called by Qt when a part of the window should be redrawn.
void keyReleaseEvent(QKeyEvent *event)
Called when user releases a pressed key and the window has focus.
VncWindow(QWidget *parent=0)
void onUpdateImage(const int x, const int y, const int w, const int h)
Triggered by imageUpdate signal from the _vncWorker thread telling that the given region of the image...
void onProjectionStopped()
Triggered by _vncWorker when the connection to the VNC server is lost.
void open(const QString &host, int port, const QString &passwd, bool ro, bool fullscreen, const QString &caption, const int clientId, const QByteArray &rawThumb)
Show the VNC client window and connect to the given VNC server.