bool PresenterPlugin::receivePacket(const NetworkPacket &np)
{
if (np.get(QStringLiteral("stop"), false)) {
delete m_view;
m_view = nullptr;
return true;
}
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);
}
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();
QQuickItem *object = m_view->rootObject();
object->setProperty("xPos", m_xPos);
object->setProperty("yPos", m_yPos);
return true;
}
This retrieves the coordinates of a network package from the internal list. It creates a presenter view if it doesn't exist, and sets the x and y positions of the objects in the view. It also starts a timer to track the change in the network package. It returns true on the first successful attempt.