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

VncOutput: send mouse events to VNC server

parent 246f5e25
......@@ -24,6 +24,7 @@
#include <QDebug>
#include <QImage>
#include <QMouseEvent>
#include <QPainter>
#include <QPointF>
#include <QTransform>
......@@ -43,6 +44,8 @@ public:
void setCenter(const QPointF &center);
void updateMapping();
void sendMouseEvent(const QPointF &pos, Qt::MouseButtons buttons);
private:
VncClient *m_client;
QSize m_vncSize;
......@@ -122,12 +125,23 @@ void VncOutputPrivate::updateMapping()
Q_EMIT q->centerChanged();
}
void VncOutputPrivate::sendMouseEvent(const QPointF &pos,
Qt::MouseButtons buttons)
{
if (Q_UNLIKELY(!m_client ||
!m_paintedRect.contains(pos.toPoint()))) return;
m_client->sendMouseEvent(m_itemToVnc.map(pos), buttons);
}
VncOutput::VncOutput(QQuickItem *parent):
QQuickPaintedItem(parent),
d_ptr(new VncOutputPrivate(this))
{
setOpaquePainting(true);
setAntialiasing(true);
setAcceptedMouseButtons(Qt::AllButtons);
setAcceptHoverEvents(true);
/* For some reason if FBO rendering is enabled, only the first
* frame is drawn, unless the image is a different one
*/
......@@ -201,3 +215,34 @@ void VncOutput::geometryChanged(const QRectF &newGeometry,
QQuickPaintedItem::geometryChanged(newGeometry, oldGeometry);
d->updateMapping();
}
void VncOutput::hoverMoveEvent(QHoverEvent *event)
{
Q_D(VncOutput);
QQuickPaintedItem::hoverMoveEvent(event);
d->sendMouseEvent(event->pos(), Qt::NoButton);
}
void VncOutput::mouseMoveEvent(QMouseEvent *event)
{
Q_D(VncOutput);
QQuickPaintedItem::mouseMoveEvent(event);
d->sendMouseEvent(event->localPos(), event->buttons());
event->accept();
}
void VncOutput::mousePressEvent(QMouseEvent *event)
{
Q_D(VncOutput);
QQuickPaintedItem::mousePressEvent(event);
d->sendMouseEvent(event->localPos(), event->buttons());
event->accept();
}
void VncOutput::mouseReleaseEvent(QMouseEvent *event)
{
Q_D(VncOutput);
QQuickPaintedItem::mouseReleaseEvent(event);
d->sendMouseEvent(event->localPos(), event->buttons());
event->accept();
}
......@@ -58,6 +58,10 @@ Q_SIGNALS:
protected:
void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry) override;
void hoverMoveEvent(QHoverEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
private:
Q_DECLARE_PRIVATE(VncOutput)
......
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