From 9a4bb293a715617f1c206dcc1666acd02bc92264 Mon Sep 17 00:00:00 2001 From: Albert Vaca Cintora Date: Sun, 21 Jul 2019 12:26:33 +0200 Subject: [PATCH] Receive deltas instead of abs positions from phone --- plugins/presenter/presenterplugin.cpp | 18 +++++++++++++----- plugins/presenter/presenterplugin.h | 1 + 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/presenter/presenterplugin.cpp b/plugins/presenter/presenterplugin.cpp index 7555b1d86..f8a083fd7 100644 --- a/plugins/presenter/presenterplugin.cpp +++ b/plugins/presenter/presenterplugin.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -79,19 +80,26 @@ bool PresenterPlugin::receivePacket(const NetworkPacket& np) if (!m_view) { m_view = new PresenterView; + m_xPos = 0.5f; + m_yPos = 0.5f; m_view->showFullScreen(); connect(this, &QObject::destroyed, m_view, &QObject::deleteLater); connect(m_timer, &QTimer::timeout, m_view, &QObject::deleteLater); } - auto screenSize = m_view->screen()->size(); - auto ratio = screenSize.width()/screenSize.height(); + QSize screenSize = m_view->screen()->size(); + float ratio = float(screenSize.width())/screenSize.height(); + + m_xPos += np.get(QStringLiteral("dx")); + m_yPos += np.get(QStringLiteral("dy")) * ratio; + m_xPos = qBound(0.f, m_xPos, 1.f); + m_yPos = qBound(0.f, m_yPos, 1.f); m_timer->start(); - auto object = m_view->rootObject(); - object->setProperty("xPos", np.get(QStringLiteral("px"))/2 + 0.5); - object->setProperty("yPos", np.get(QStringLiteral("py"))/2 + 0.5); + QQuickItem* object = m_view->rootObject(); + object->setProperty("xPos", m_xPos); + object->setProperty("yPos", m_yPos); return true; } diff --git a/plugins/presenter/presenterplugin.h b/plugins/presenter/presenterplugin.h index 3cd9bb508..395ff27f4 100644 --- a/plugins/presenter/presenterplugin.h +++ b/plugins/presenter/presenterplugin.h @@ -47,6 +47,7 @@ public: private: QPointer m_view; QTimer* m_timer; + float m_xPos, m_yPos; }; #endif