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

VncOutput: listen to (virtual) keyboard input events

parent 76670ec8
......@@ -44,6 +44,7 @@ public:
void setCenter(const QPointF &center);
void updateMapping();
void sendKeyEvent(const QString &text);
void sendMouseEvent(const QPointF &pos, Qt::MouseButtons buttons);
private:
......@@ -128,6 +129,13 @@ void VncOutputPrivate::updateMapping()
}
}
void VncOutputPrivate::sendKeyEvent(const QString &text)
{
for (const QChar c: text) {
m_client->sendKeyEvent(c);
}
}
void VncOutputPrivate::sendMouseEvent(const QPointF &pos,
Qt::MouseButtons buttons)
{
......@@ -145,6 +153,7 @@ VncOutput::VncOutput(QQuickItem *parent):
setAntialiasing(true);
setAcceptedMouseButtons(Qt::AllButtons);
setAcceptHoverEvents(true);
setFlag(QQuickItem::ItemAcceptsInputMethod, true);
/* For some reason if FBO rendering is enabled, only the first
* frame is drawn, unless the image is a different one
*/
......@@ -279,6 +288,40 @@ void VncOutput::hoverMoveEvent(QHoverEvent *event)
d->sendMouseEvent(event->pos(), Qt::NoButton);
}
void VncOutput::inputMethodEvent(QInputMethodEvent *event)
{
Q_D(VncOutput);
qDebug() << Q_FUNC_INFO << event;
d->sendKeyEvent(event->commitString());
}
QVariant VncOutput::inputMethodQuery(Qt::InputMethodQuery query) const
{
QVariant ret = QQuickPaintedItem::inputMethodQuery(query);
if (query == Qt::ImHints) {
ret = int(Qt::ImhHiddenText |
Qt::ImhNoAutoUppercase |
Qt::ImhNoPredictiveText);
}
return ret;
}
void VncOutput::keyPressEvent(QKeyEvent *event)
{
Q_D(VncOutput);
if (d->m_client) {
d->m_client->sendKeyEvent(event, true);
}
}
void VncOutput::keyReleaseEvent(QKeyEvent *event)
{
Q_D(VncOutput);
if (d->m_client) {
d->m_client->sendKeyEvent(event, false);
}
}
void VncOutput::mouseMoveEvent(QMouseEvent *event)
{
Q_D(VncOutput);
......
......@@ -83,6 +83,10 @@ protected:
void geometryChanged(const QRectF &newGeometry,
const QRectF &oldGeometry) override;
void hoverMoveEvent(QHoverEvent *event) override;
void inputMethodEvent(QInputMethodEvent *event) override;
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void mousePressEvent(QMouseEvent *event) override;
void mouseReleaseEvent(QMouseEvent *event) override;
......
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