Commit a40e521c authored by Alberto Mardegan's avatar Alberto Mardegan
Browse files

VncOutput: expose painted rect and VNC size to QML

parent a238fdab
......@@ -84,6 +84,8 @@ void VncOutputPrivate::updateMapping()
Q_Q(VncOutput);
qreal oldScale = m_scale;
QSizeF oldVncSize = m_vncSize;
QRectF oldPaintedRect = m_paintedRect;
qreal w = q->width();
qreal h = q->height();
......@@ -118,6 +120,12 @@ void VncOutputPrivate::updateMapping()
Q_EMIT q->scaleChanged();
}
Q_EMIT q->centerChanged();
if (m_vncSize != oldVncSize) {
Q_EMIT q->remoteScreenSizeChanged();
}
if (m_paintedRect != oldPaintedRect) {
Q_EMIT q->marginsChanged();
}
}
void VncOutputPrivate::sendMouseEvent(const QPointF &pos,
......@@ -200,6 +208,36 @@ QPointF VncOutput::center() const
return d->m_center;
}
QSizeF VncOutput::remoteScreenSize() const
{
Q_D(const VncOutput);
return d->m_vncSize;
}
qreal VncOutput::bottomMargin() const
{
Q_D(const VncOutput);
return height() - d->m_paintedRect.bottom();
}
qreal VncOutput::leftMargin() const
{
Q_D(const VncOutput);
return d->m_paintedRect.x();
}
qreal VncOutput::rightMargin() const
{
Q_D(const VncOutput);
return width() - d->m_paintedRect.right();
}
qreal VncOutput::topMargin() const
{
Q_D(const VncOutput);
return d->m_paintedRect.y();
}
void VncOutput::paint(QPainter *painter)
{
Q_D(VncOutput);
......@@ -207,6 +245,8 @@ void VncOutput::paint(QPainter *painter)
const QImage &image = d->m_client->image();
if (image.size() != d->m_vncSize) {
d->updateMapping();
Q_EMIT remoteScreenSizeChanged();
Q_EMIT marginsChanged();
}
painter->drawImage(d->m_paintedRect, image, d->m_vncVisibleRect);
}
......@@ -217,6 +257,7 @@ void VncOutput::geometryChanged(const QRectF &newGeometry,
Q_D(VncOutput);
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
d->updateMapping();
Q_EMIT marginsChanged();
}
void VncOutput::hoverMoveEvent(QHoverEvent *event)
......
......@@ -24,6 +24,7 @@
#include <QQuickPaintedItem>
#include <QScopedPointer>
#include <QSizeF>
namespace LomiriVNC {
......@@ -36,6 +37,12 @@ class VncOutput: public QQuickPaintedItem
NOTIFY requestedScaleChanged)
Q_PROPERTY(qreal scale READ scale NOTIFY scaleChanged)
Q_PROPERTY(QPointF center READ center WRITE setCenter NOTIFY centerChanged)
Q_PROPERTY(QSizeF remoteScreenSize READ remoteScreenSize
NOTIFY remoteScreenSizeChanged)
Q_PROPERTY(qreal bottomMargin READ bottomMargin NOTIFY marginsChanged)
Q_PROPERTY(qreal leftMargin READ leftMargin NOTIFY marginsChanged)
Q_PROPERTY(qreal rightMargin READ rightMargin NOTIFY marginsChanged)
Q_PROPERTY(qreal topMargin READ topMargin NOTIFY marginsChanged)
public:
VncOutput(QQuickItem *parent = nullptr);
......@@ -52,6 +59,13 @@ public:
void setCenter(const QPointF &center);
QPointF center() const;
QSizeF remoteScreenSize() const;
qreal bottomMargin() const;
qreal leftMargin() const;
qreal rightMargin() const;
qreal topMargin() const;
void paint(QPainter *painter) override;
Q_SIGNALS:
......@@ -59,6 +73,8 @@ Q_SIGNALS:
void requestedScaleChanged();
void scaleChanged();
void centerChanged();
void remoteScreenSizeChanged();
void marginsChanged();
protected:
void geometryChanged(const QRectF &newGeometry,
......
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