Commit 80ab162c authored by Alberto Mardegan's avatar Alberto Mardegan
Browse files

Add VncOutput class

parent 5af11089
......@@ -25,6 +25,8 @@ Project {
files: [
"vnc_client.cpp",
"vnc_client.h",
"vnc_output.cpp",
"vnc_output.h",
"main.cpp",
"types.cpp",
"types.h",
......
......@@ -20,6 +20,7 @@
#include "types.h"
#include "vnc_client.h"
#include "vnc_output.h"
#include <QDebug>
#include <QQmlEngine>
......@@ -29,4 +30,5 @@ using namespace LomiriVNC;
void LomiriVNC::registerTypes()
{
qmlRegisterType<VncClient>("LomiriVNC", 1, 0, "VncClient");
qmlRegisterType<VncOutput>("LomiriVNC", 1, 0, "VncOutput");
}
/*
* Copyright (C) 2020 Alberto Mardegan <mardy@users.sourceforge.net>
*
* This file is part of LomiriVNC.
*
* LomiriVNC is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LomiriVNC 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LomiriVNC. If not, see <http://www.gnu.org/licenses/>.
*/
#include "vnc_output.h"
#include "vnc_client.h"
#include <QDebug>
#include <QImage>
#include <QPainter>
using namespace LomiriVNC;
namespace LomiriVNC {
class VncOutputPrivate {
Q_DECLARE_PUBLIC(VncOutput)
public:
VncOutputPrivate(VncOutput *q);
~VncOutputPrivate();
private:
VncClient *m_client;
VncOutput *q_ptr;
};
} // namespace
VncOutputPrivate::VncOutputPrivate(VncOutput *q):
m_client(nullptr),
q_ptr(q)
{
}
VncOutputPrivate::~VncOutputPrivate()
{
}
VncOutput::VncOutput(QQuickItem *parent):
QQuickPaintedItem(parent),
d_ptr(new VncOutputPrivate(this))
{
setOpaquePainting(true);
setAntialiasing(true);
/* For some reason if FBO rendering is enabled, only the first
* frame is drawn, unless the image is a different one
*/
//setRenderTarget(QQuickPaintedItem::FramebufferObject);
}
VncOutput::~VncOutput() = default;
void VncOutput::setClient(VncClient *client)
{
Q_D(VncOutput);
if (client == d->m_client) return;
if (client) {
client->addViewer(this);
} else if (d->m_client) {
d->m_client->removeViewer(this);
}
d->m_client = client;
Q_EMIT clientChanged();
}
VncClient *VncOutput::client() const
{
Q_D(const VncOutput);
return d->m_client;
}
void VncOutput::paint(QPainter *painter)
{
Q_D(VncOutput);
const QImage &image = d->m_client->image();
int w = width();
int h = height();
QSize scaledSize = image.size().scaled(w, h, Qt::KeepAspectRatio);
int x = (w - scaledSize.width()) / 2;
int y = (h - scaledSize.height()) / 2;
painter->drawImage(QRectF(QPointF(x, y), scaledSize), image);
}
/*
* Copyright (C) 2020 Alberto Mardegan <mardy@users.sourceforge.net>
*
* This file is part of LomiriVNC.
*
* LomiriVNC is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LomiriVNC 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LomiriVNC. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOMIRIVNC_VNC_OUTPUT_H
#define LOMIRIVNC_VNC_OUTPUT_H
#include "vnc_client.h"
#include <QQuickPaintedItem>
#include <QScopedPointer>
namespace LomiriVNC {
class VncOutputPrivate;
class VncOutput: public QQuickPaintedItem
{
Q_OBJECT
Q_PROPERTY(VncClient *client READ client WRITE setClient NOTIFY clientChanged)
public:
VncOutput(QQuickItem *parent = nullptr);
virtual ~VncOutput();
void setClient(VncClient *client);
VncClient *client() const;
void paint(QPainter *painter) override;
Q_SIGNALS:
void clientChanged();
private:
Q_DECLARE_PRIVATE(VncOutput)
QScopedPointer<VncOutputPrivate> d_ptr;
};
} // namespace
#endif // LOMIRIVNC_VNC_OUTPUT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment