2019-07-05 16:58:46 +01:00
|
|
|
/**
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
|
2019-07-05 16:58:46 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
2019-07-05 16:58:46 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "presenterplugin.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
#include <KPluginFactory>
|
|
|
|
|
|
|
|
#include <QDBusConnection>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QDebug>
|
2019-07-05 16:58:46 +01:00
|
|
|
#include <QQmlError>
|
|
|
|
#include <QQuickItem>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QQuickView>
|
2019-07-21 11:26:33 +01:00
|
|
|
#include <QtGlobal>
|
2019-07-05 16:58:46 +01:00
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "plugin_presenter_debug.h"
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QScreen>
|
|
|
|
#include <core/daemon.h>
|
|
|
|
#include <core/device.h>
|
2019-07-05 16:58:46 +01:00
|
|
|
|
|
|
|
K_PLUGIN_CLASS_WITH_JSON(PresenterPlugin, "kdeconnect_presenter.json")
|
|
|
|
|
|
|
|
class PresenterView : public QQuickView
|
|
|
|
{
|
|
|
|
public:
|
2022-09-10 22:23:52 +01:00
|
|
|
PresenterView()
|
|
|
|
{
|
2024-10-09 21:27:35 +01:00
|
|
|
Qt::WindowFlags windowFlags = Qt::WindowFlags(Qt::WindowDoesNotAcceptFocus | Qt::WindowFullScreen | Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint
|
|
|
|
| Qt::Tool | (int)(Qt::WA_TranslucentBackground));
|
2019-08-18 00:42:17 +01:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
windowFlags |= Qt::WindowTransparentForInput;
|
|
|
|
#endif
|
|
|
|
setFlags(windowFlags);
|
2019-07-05 16:58:46 +01:00
|
|
|
setColor(QColor(Qt::transparent));
|
|
|
|
|
|
|
|
setResizeMode(QQuickView::SizeViewToRootObject);
|
|
|
|
setSource(QUrl(QStringLiteral("qrc:/presenter/Presenter.qml")));
|
|
|
|
|
|
|
|
const auto ourErrors = errors();
|
|
|
|
for (const auto &error : ourErrors) {
|
2023-08-06 11:00:02 +01:00
|
|
|
qCWarning(KDECONNECT_PLUGIN_PRESENTER) << "error" << error.description() << error.url() << error.line() << error.column();
|
2019-07-05 16:58:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
PresenterPlugin::PresenterPlugin(QObject *parent, const QVariantList &args)
|
2019-07-05 16:58:46 +01:00
|
|
|
: KdeConnectPlugin(parent, args)
|
|
|
|
, m_view(nullptr)
|
|
|
|
, m_timer(new QTimer(this))
|
|
|
|
{
|
2019-07-19 22:23:39 +01:00
|
|
|
m_timer->setInterval(500);
|
2019-07-05 16:58:46 +01:00
|
|
|
m_timer->setSingleShot(true);
|
|
|
|
}
|
|
|
|
|
2023-07-31 08:25:45 +01:00
|
|
|
void PresenterPlugin::receivePacket(const NetworkPacket &np)
|
2019-07-05 16:58:46 +01:00
|
|
|
{
|
2019-07-21 11:22:20 +01:00
|
|
|
if (np.get<bool>(QStringLiteral("stop"), false)) {
|
|
|
|
delete m_view;
|
|
|
|
m_view = nullptr;
|
2023-07-31 08:25:45 +01:00
|
|
|
return;
|
2019-07-21 11:22:20 +01:00
|
|
|
}
|
|
|
|
|
2019-07-05 16:58:46 +01:00
|
|
|
if (!m_view) {
|
|
|
|
m_view = new PresenterView;
|
2019-07-21 11:26:33 +01:00
|
|
|
m_xPos = 0.5f;
|
|
|
|
m_yPos = 0.5f;
|
2019-07-05 16:58:46 +01:00
|
|
|
m_view->showFullScreen();
|
|
|
|
connect(this, &QObject::destroyed, m_view, &QObject::deleteLater);
|
|
|
|
connect(m_timer, &QTimer::timeout, m_view, &QObject::deleteLater);
|
|
|
|
}
|
|
|
|
|
2019-07-21 11:26:33 +01:00
|
|
|
QSize screenSize = m_view->screen()->size();
|
2022-09-10 22:23:52 +01:00
|
|
|
float ratio = float(screenSize.width()) / screenSize.height();
|
2019-07-21 11:26:33 +01:00
|
|
|
|
|
|
|
m_xPos += np.get<float>(QStringLiteral("dx"));
|
|
|
|
m_yPos += np.get<float>(QStringLiteral("dy")) * ratio;
|
|
|
|
m_xPos = qBound(0.f, m_xPos, 1.f);
|
|
|
|
m_yPos = qBound(0.f, m_yPos, 1.f);
|
2019-07-05 16:58:46 +01:00
|
|
|
|
|
|
|
m_timer->start();
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QQuickItem *object = m_view->rootObject();
|
2019-07-21 11:26:33 +01:00
|
|
|
object->setProperty("xPos", m_xPos);
|
|
|
|
object->setProperty("yPos", m_yPos);
|
2019-07-05 16:58:46 +01:00
|
|
|
}
|
|
|
|
|
2023-07-26 09:15:11 +01:00
|
|
|
#include "moc_presenterplugin.cpp"
|
2019-07-05 16:58:46 +01:00
|
|
|
#include "presenterplugin.moc"
|