mirror of
https://gitlab.com/kelteseth/ScreenPlay.git
synced 2024-11-06 02:52:29 +01:00
Add widget type to the ScreenPlayWidget executable as an argument. This can be ether qmlWidget or htmlWidget for now.
This commit is contained in:
parent
57001e500a
commit
04705a5ec3
@ -337,14 +337,14 @@ Item {
|
||||
+ "/" + activeScreen,
|
||||
ScreenPlay.installedListModel.get(activeScreen).screenPreview,
|
||||
(Math.round(sliderVolume.value * 100) / 100),
|
||||
settingsComboBox.model.get(settingsComboBox.currentIndex).text.toString(
|
||||
), type)
|
||||
settingsComboBox.model.get(settingsComboBox.currentIndex).text.toString(),
|
||||
type)
|
||||
|
||||
} else {
|
||||
ScreenPlay.screenPlayManager.createWidget(
|
||||
ScreenPlay.globalVariables.localStoragePath + "/" + activeScreen,
|
||||
ScreenPlay.installedListModel.get(
|
||||
activeScreen).screenPreview)
|
||||
ScreenPlay.installedListModel.get(activeScreen).screenPreview,
|
||||
type)
|
||||
}
|
||||
sidebar.state = "inactive"
|
||||
monitorSelection.deselectAll()
|
||||
|
@ -36,11 +36,13 @@ Create::Create()
|
||||
|
||||
void Create::createWidget(const QString& localStoragePath, const QString& title, const QString& previewThumbnail, const QString& createdBy, const QString& license, const QString& type, const QVector<QString>& tags)
|
||||
{
|
||||
QtConcurrent::run([=]() {
|
||||
QUrl localStoragePathUrl { localStoragePath };
|
||||
QDir dir;
|
||||
dir.cd(localStoragePathUrl.toLocalFile());
|
||||
// Create a temp dir so we can later alter it to the workshop id
|
||||
auto folderName = QString("_tmp_" + QTime::currentTime().toString()).replace(":", "");
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
if (!dir.mkdir(folderName)) {
|
||||
qDebug() << "Could create folder: " << folderName;
|
||||
@ -55,9 +57,32 @@ void Create::createWidget(const QString& localStoragePath, const QString& title,
|
||||
if (type == "QML") {
|
||||
obj.insert("type", "qmlWidget");
|
||||
obj.insert("file", "main.qml");
|
||||
|
||||
QFile fileMainQML(workingPath + "/main.qml");
|
||||
if (!fileMainQML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /main.qml";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainQML(&fileMainQML);
|
||||
outMainQML.setCodec("UTF-8");
|
||||
outMainQML << "import QtQuick 2.14 \n\n Item {\n id:root \n}";
|
||||
fileMainQML.close();
|
||||
|
||||
} else {
|
||||
obj.insert("type", "htmlWidget");
|
||||
obj.insert("file", "index.html");
|
||||
|
||||
QFile fileMainHTML(workingPath + "/index.html");
|
||||
if (!fileMainHTML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /index.html";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainHTML(&fileMainHTML);
|
||||
outMainHTML.setCodec("UTF-8");
|
||||
outMainHTML << "<html>\n<head></head>\n<body></body>\n</html>";
|
||||
fileMainHTML.close();
|
||||
}
|
||||
|
||||
QJsonArray tagsJsonArray;
|
||||
@ -65,7 +90,6 @@ void Create::createWidget(const QString& localStoragePath, const QString& title,
|
||||
tagsJsonArray.append(tmp);
|
||||
}
|
||||
obj.insert("tags", tagsJsonArray);
|
||||
QString workingPath = dir.path() + "/" + folderName;
|
||||
|
||||
QFile file(workingPath + "/project.json");
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
@ -91,18 +115,8 @@ void Create::createWidget(const QString& localStoragePath, const QString& title,
|
||||
out << doc.toJson();
|
||||
file.close();
|
||||
|
||||
QFile fileMainQML(workingPath + "/main.qml");
|
||||
if (!fileMainQML.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
qDebug() << "Could not open /main.qml";
|
||||
return;
|
||||
}
|
||||
|
||||
QTextStream outMainQML(&fileMainQML);
|
||||
outMainQML.setCodec("UTF-8");
|
||||
outMainQML << "import QtQuick 2.14 \n\n Item {\n id:root \n}";
|
||||
fileMainQML.close();
|
||||
|
||||
emit widgetCreatedSuccessful(workingPath);
|
||||
});
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -105,7 +105,7 @@ void ScreenPlayManager::createWallpaper(
|
||||
/*!
|
||||
Creates a ScreenPlayWidget object via a \a absoluteStoragePath and a \a preview image (relative path).
|
||||
*/
|
||||
void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QString& previewImage)
|
||||
void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QString& previewImage, const QString& type)
|
||||
{
|
||||
m_tracker->sendEvent("widget", "start");
|
||||
increaseActiveWidgetsCounter();
|
||||
@ -117,7 +117,7 @@ void ScreenPlayManager::createWidget(const QUrl& absoluteStoragePath, const QStr
|
||||
absoluteStoragePath.toLocalFile(),
|
||||
previewImage,
|
||||
absoluteStoragePath.toString(),
|
||||
this));
|
||||
type));
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -95,7 +95,7 @@ public slots:
|
||||
const QString& fillMode,
|
||||
const QString& type, const bool saveToProfilesConfigFile = true);
|
||||
|
||||
void createWidget(const QUrl& absoluteStoragePath, const QString& previewImage);
|
||||
void createWidget(const QUrl& absoluteStoragePath, const QString& previewImage, const QString &type);
|
||||
|
||||
void removeAllWallpapers();
|
||||
bool removeWallpaperAt(const int at = 0);
|
||||
|
@ -16,20 +16,21 @@ ScreenPlayWidget::ScreenPlayWidget(
|
||||
const QString& projectPath,
|
||||
const QString& previewImage,
|
||||
const QString& fullPath,
|
||||
QObject* parent)
|
||||
: QObject { parent }
|
||||
const QString& type)
|
||||
: QObject { nullptr }
|
||||
, m_globalVariables { globalVariables }
|
||||
, m_projectPath { projectPath }
|
||||
, m_previewImage { previewImage }
|
||||
, m_appID { appID }
|
||||
, m_position { 0, 0 }
|
||||
, m_type { type }
|
||||
{
|
||||
const QStringList proArgs { m_projectPath, m_appID };
|
||||
const QStringList proArgs { m_projectPath, m_appID, m_type };
|
||||
m_process.setArguments(proArgs);
|
||||
|
||||
if (fullPath.endsWith(".exe")) {
|
||||
m_process.setProgram(fullPath);
|
||||
} else if (fullPath.endsWith(".qml")) {
|
||||
} else {
|
||||
m_process.setProgram(m_globalVariables->widgetExecutablePath().path());
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@ class ScreenPlayWidget : public QObject {
|
||||
Q_PROPERTY(QString previewImage READ previewImage WRITE setPreviewImage NOTIFY previewImageChanged)
|
||||
Q_PROPERTY(QPoint position READ position WRITE setPosition NOTIFY positionChanged)
|
||||
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
|
||||
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
|
||||
|
||||
public:
|
||||
explicit ScreenPlayWidget(
|
||||
@ -30,7 +31,7 @@ public:
|
||||
const QString& projectPath,
|
||||
const QString& previewImage,
|
||||
const QString& fullPath,
|
||||
QObject* parent = nullptr);
|
||||
const QString& type);
|
||||
|
||||
~ScreenPlayWidget() {}
|
||||
|
||||
@ -54,6 +55,11 @@ public:
|
||||
return m_appID;
|
||||
}
|
||||
|
||||
QString type() const
|
||||
{
|
||||
return m_type;
|
||||
}
|
||||
|
||||
public slots:
|
||||
void setProjectPath(QString projectPath)
|
||||
{
|
||||
@ -91,12 +97,23 @@ public slots:
|
||||
emit appIDChanged(m_appID);
|
||||
}
|
||||
|
||||
void setType(QString type)
|
||||
{
|
||||
if (m_type == type)
|
||||
return;
|
||||
|
||||
m_type = type;
|
||||
emit typeChanged(m_type);
|
||||
}
|
||||
|
||||
signals:
|
||||
void projectPathChanged(QString projectPath);
|
||||
void previewImageChanged(QString previewImage);
|
||||
void positionChanged(QPoint position);
|
||||
void appIDChanged(QString appID);
|
||||
|
||||
void typeChanged(QString type);
|
||||
|
||||
private:
|
||||
QProcess m_process;
|
||||
const shared_ptr<GlobalVariables>& m_globalVariables;
|
||||
@ -105,5 +122,6 @@ private:
|
||||
QString m_previewImage;
|
||||
QString m_appID;
|
||||
QPoint m_position;
|
||||
QString m_type;
|
||||
};
|
||||
}
|
||||
|
@ -14,18 +14,18 @@ int main(int argc, char* argv[])
|
||||
|
||||
QStringList argumentList = app.arguments();
|
||||
|
||||
// If we start with only one argument (app path),
|
||||
// If we start with only one argument (app, path, type),
|
||||
// it means we want to test a single widget
|
||||
if (argumentList.length() == 1) {
|
||||
WidgetWindow spwmw("test","appid" );
|
||||
WidgetWindow spwmw("test","appid", "qmlWidget");
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
if (argumentList.length() != 3) {
|
||||
if (argumentList.length() != 4) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
WidgetWindow spwmw(argumentList.at(1), argumentList.at(2));
|
||||
WidgetWindow spwmw(argumentList.at(1), argumentList.at(2), argumentList.at(3));
|
||||
|
||||
QObject::connect(&sdk, &ScreenPlaySDK::sdkDisconnected, &spwmw, &WidgetWindow::destroyThis);
|
||||
QObject::connect(&sdk, &ScreenPlaySDK::incommingMessage, &spwmw, &WidgetWindow::messageReceived);
|
||||
|
@ -2,10 +2,20 @@
|
||||
|
||||
#include <QCoreApplication>
|
||||
|
||||
WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
|
||||
: QObject(parent)
|
||||
WidgetWindow::WidgetWindow(const QString projectPath, const QString appid, const QString type)
|
||||
: QObject(nullptr)
|
||||
, m_appID { appid }
|
||||
, m_type { type }
|
||||
{
|
||||
QStringList availableTypes {
|
||||
"qmlWidget",
|
||||
"htmlWidget",
|
||||
"standaloneWidget"
|
||||
};
|
||||
|
||||
if (!availableTypes.contains(m_type)) {
|
||||
QGuiApplication::exit(-4);
|
||||
}
|
||||
|
||||
Qt::WindowFlags flags = m_window.flags();
|
||||
m_window.setWidth(300);
|
||||
@ -41,6 +51,7 @@ WidgetWindow::WidgetWindow(QString projectPath, QString appid, QObject* parent)
|
||||
}
|
||||
// Instead of setting "renderType: Text.NativeRendering" every time
|
||||
// we can set it here once :)
|
||||
|
||||
m_window.setTextRenderType(QQuickWindow::TextRenderType::NativeTextRendering);
|
||||
// m_window.setResizeMode(QQuickView::ResizeMode::SizeViewToRootObject);
|
||||
m_window.setSource(QUrl("qrc:/mainWidget.qml"));
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include <QWindow>
|
||||
#include <QtQuick/QQuickView>
|
||||
#include <QtQuick/QQuickWindow>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
#include <qt_windows.h>
|
||||
@ -24,7 +25,7 @@ class WidgetWindow : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit WidgetWindow(QString projectPath, QString appid, QObject* parent = nullptr);
|
||||
explicit WidgetWindow(const QString projectPath, const QString appid, const QString type);
|
||||
|
||||
Q_PROPERTY(QString appID READ appID WRITE setAppID NOTIFY appIDChanged)
|
||||
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
|
||||
|
Loading…
Reference in New Issue
Block a user