diff --git a/ScreenPlayWidget/SPWidgetmain.cpp b/ScreenPlayWidget/SPWidgetmain.cpp index 6333b85c..a93cdfa3 100644 --- a/ScreenPlayWidget/SPWidgetmain.cpp +++ b/ScreenPlayWidget/SPWidgetmain.cpp @@ -1,16 +1,24 @@ #include #include +#include -int main(int argc, char *argv[]) +#include "src/spwidgetmainwindow.h" + +int main(int argc, char* argv[]) { - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); + QGuiApplication::setAttribute(Qt::AA_UseOpenGLES); QGuiApplication app(argc, argv); - QQmlApplicationEngine engine; - engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); - if (engine.rootObjects().isEmpty()) - return -1; + QStringList argumentList = app.arguments(); + + if (argumentList.length() != 3) { + return -3; + } + + SPWidgetmainwindow spwmw(argumentList.at(1), argumentList.at(2)); + //SPWidgetmainwindow spwmw("asasasasd", "D:/672870/xkcd"); return app.exec(); } diff --git a/ScreenPlayWidget/ScreenPlayWidget.pro b/ScreenPlayWidget/ScreenPlayWidget.pro index d6ff32b6..e897f476 100644 --- a/ScreenPlayWidget/ScreenPlayWidget.pro +++ b/ScreenPlayWidget/ScreenPlayWidget.pro @@ -13,7 +13,8 @@ DEFINES += QT_DEPRECATED_WARNINGS #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ - SPWidgetmain.cpp + SPWidgetmain.cpp \ + src/spwidgetmainwindow.cpp RESOURCES += \ SPWidgetResources.qrc @@ -28,3 +29,6 @@ QML_DESIGNER_IMPORT_PATH = qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target + +HEADERS += \ + src/spwidgetmainwindow.h diff --git a/ScreenPlayWidget/main.qml b/ScreenPlayWidget/main.qml index 8892354f..b6c49e32 100644 --- a/ScreenPlayWidget/main.qml +++ b/ScreenPlayWidget/main.qml @@ -10,11 +10,42 @@ Window { color: "transparent" flags: Qt.SplashScreen | Qt.ToolTip | Qt.WindowStaysOnBottomHint - Loader { - id:loader - anchors.fill: parent - asynchronous: true + ScreenPlaySDK { + id: spSDK + contentType: "ScreenPlayWindow" + appID: mainwindow.appID + onIncommingMessageError: { + + } + onIncommingMessage: { + var obj2 = 'import QtQuick 2.9; Item {Component.onCompleted: sceneLoader.item.' + + key + ' = ' + value + '; }' + var newObject = Qt.createQmlObject(obj2.toString(), root, "err") + newObject.destroy(10000) + } + + onSdkConnected: { + + } + + onSdkDisconnected: { + screenVideo.state = "destroy" + } } + Connections { + target: mainWindow + + onSetWidgetSource: { + loader.source = Qt.resolvedUrl("file:///" + source) + print(loader.source) + } + } + + Loader { + id: loader + anchors.fill: parent + asynchronous: true + } } diff --git a/ScreenPlayWidget/src/spwidgetmainwindow.cpp b/ScreenPlayWidget/src/spwidgetmainwindow.cpp new file mode 100644 index 00000000..997fcda0 --- /dev/null +++ b/ScreenPlayWidget/src/spwidgetmainwindow.cpp @@ -0,0 +1,27 @@ +#include "spwidgetmainwindow.h" + +SPWidgetmainwindow::SPWidgetmainwindow(QString projectPath, QString appid, QScreen* parent) + : QWindow(parent) +{ + m_appID = appid; + + QFile configTmp; + QJsonDocument configJsonDocument; + QJsonParseError parseError; + + configTmp.setFileName(projectPath + "/project.json"); + configTmp.open(QIODevice::ReadOnly | QIODevice::Text); + m_projectConfig = configTmp.readAll(); + configJsonDocument = QJsonDocument::fromJson(m_projectConfig.toUtf8(), &parseError); + + if (!(parseError.error == QJsonParseError::NoError)) { + qWarning("Settings Json Parse Error "); + } + + m_project = configJsonDocument.object(); + + emit setWidgetSource(projectPath + "/" + m_project.value("file").toString()); + + m_quickRenderer = QSharedPointer(new QQuickView(this)); + m_quickRenderer.data()->rootContext()->setContextProperty("mainwindow", this); +} diff --git a/ScreenPlayWidget/src/spwidgetmainwindow.h b/ScreenPlayWidget/src/spwidgetmainwindow.h new file mode 100644 index 00000000..de8e456c --- /dev/null +++ b/ScreenPlayWidget/src/spwidgetmainwindow.h @@ -0,0 +1,77 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include + + +class SPWidgetmainwindow : public QWindow { + Q_OBJECT + +public: + explicit SPWidgetmainwindow( QString projectPath, QString appid,QScreen* parent = nullptr); + + Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged) + Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged) + Q_PROPERTY(QString projectConfig READ projectConfig WRITE setProjectConfig NOTIFY projectConfigChanged) + + QString appID() const + { + return m_appID; + } + + QString type() const + { + return m_type; + } + + QString projectConfig() const + { + return m_projectConfig; + } + +signals: + void appIDChanged(QString appID); + void typeChanged(QString type); + void projectConfigChanged(QString projectConfig); + void setWidgetSource(QString source); + +public slots: + void setAppID(QString appID) + { + if (m_appID == appID) + return; + + m_appID = appID; + emit appIDChanged(m_appID); + } + void setType(QString type) + { + if (m_type == type) + return; + + m_type = type; + emit typeChanged(m_type); + } + void setProjectConfig(QString projectConfig) + { + if (m_projectConfig == projectConfig) + return; + + m_projectConfig = projectConfig; + emit projectConfigChanged(m_projectConfig); + } + +private: + QString m_appID; + QString m_type = "qmlWidget"; + QString m_projectConfig; + QJsonObject m_project; + + QSharedPointer m_quickRenderer = nullptr; +}; diff --git a/ScreenPlayWindow/SPWmain.cpp b/ScreenPlayWindow/SPWmain.cpp index 03bc94ac..97725f96 100644 --- a/ScreenPlayWindow/SPWmain.cpp +++ b/ScreenPlayWindow/SPWmain.cpp @@ -6,6 +6,7 @@ int main(int argc, char* argv[]) { QApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QApplication::setAttribute(Qt::AA_UseOpenGLES); + QApplication a(argc, argv); QStringList argumentList = a.arguments(); diff --git a/ScreenPlayWindow/src/SPWmainwindow.h b/ScreenPlayWindow/src/SPWmainwindow.h index 09c02d22..ccc49b7d 100644 --- a/ScreenPlayWindow/src/SPWmainwindow.h +++ b/ScreenPlayWindow/src/SPWmainwindow.h @@ -23,7 +23,7 @@ class MainWindow : public QWindow { Q_OBJECT public: - explicit MainWindow(int i, QString projectPath, QString id, QString decoder,QString volume, QString fillmode, QScreen* parent = 0); + explicit MainWindow(int i, QString projectPath, QString id, QString decoder,QString volume, QString fillmode, QScreen* parent = nullptr); ~MainWindow();