From 3b4494c485bc997d83b68a02e9dea7e3de19b602 Mon Sep 17 00:00:00 2001 From: kelteseth Date: Tue, 20 Mar 2018 14:42:22 +0100 Subject: [PATCH] Add create of empty widgets --- .gitmodules | 9 ++-- ScreenPlay/ScreenPlay.pro | 6 ++- ScreenPlay/examples | 1 + ScreenPlay/qml/Create/Create.qml | 30 +++++++------ ScreenPlay/qml/Create/CreateWidget.qml | 11 ++++- ScreenPlay/qml/Create/CreateWidgetButton.qml | 2 +- ScreenPlay/src/create.cpp | 44 ++++++++++++++++++++ ScreenPlay/src/create.h | 28 +++++++++++++ ScreenPlay/src/settings.cpp | 10 +++++ ScreenPlay/src/settings.h | 4 ++ 10 files changed, 122 insertions(+), 23 deletions(-) create mode 160000 ScreenPlay/examples create mode 100644 ScreenPlay/src/create.cpp create mode 100644 ScreenPlay/src/create.h diff --git a/.gitmodules b/.gitmodules index 74863a9f..35dca663 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "QtAV"] - path = ScreenPlay/ThirdParty/QtAV - url = https://github.com/wang-bin/QtAV.git -[submodule "stomt-qt-sdk"] - path = ScreenPlay/ThirdParty/stomt-qt-sdk - url = https://github.com/Aimber/stomt-qt-sdk.git \ No newline at end of file +[submodule "ScreenPlay/examples"] + path = ScreenPlay/examples + url = https://github.com/Aimber/ScreenPlay-examples.git diff --git a/ScreenPlay/ScreenPlay.pro b/ScreenPlay/ScreenPlay.pro index 89433173..d9467dae 100644 --- a/ScreenPlay/ScreenPlay.pro +++ b/ScreenPlay/ScreenPlay.pro @@ -21,7 +21,8 @@ SOURCES += main.cpp \ src/projectsettingslistmodel.cpp \ src/startuperror.cpp \ src/screenplay.cpp \ - src/qmlutilities.cpp + src/qmlutilities.cpp \ + src/create.cpp RESOURCES += \ Resources.qrc \ @@ -44,7 +45,8 @@ HEADERS += \ src/projectsettingslistmodel.h \ src/startuperror.h \ src/screenplay.h \ - src/qmlutilities.h + src/qmlutilities.h \ + src/create.h INCLUDEPATH += \ $$PWD/ThirdParty/ \ diff --git a/ScreenPlay/examples b/ScreenPlay/examples new file mode 160000 index 00000000..66091ad1 --- /dev/null +++ b/ScreenPlay/examples @@ -0,0 +1 @@ +Subproject commit 66091ad14daa9122d0357fc7a98f29139f526fc6 diff --git a/ScreenPlay/qml/Create/Create.qml b/ScreenPlay/qml/Create/Create.qml index beb929c5..e428df9d 100644 --- a/ScreenPlay/qml/Create/Create.qml +++ b/ScreenPlay/qml/Create/Create.qml @@ -264,7 +264,7 @@ Rectangle { spacing: 20 Button { text: qsTr("QML Quickstart Guide") - Material.background: Material.Blue + Material.background: Material.Orange Material.foreground: "white" icon.source: "qrc:/assets/icons/icon_info.svg" icon.color:"white" @@ -280,25 +280,29 @@ Rectangle { icon.color:"white" icon.width: 16 icon.height: 16 - + onClicked: Qt.openUrlExternally("https://qmlbook.github.io/index.html") } -// Button { -// text: qsTr("Lore Ipsum") -// Material.background: Material.Orange -// Material.foreground: "white" -// icon.source: "qrc:/assets/icons/icon_plus.svg" -// icon.color:"white" -// icon.width: 16 -// icon.height: 16 -// } Button { - text: qsTr("Community") - Material.background: Material.Orange + text: qsTr("Forums") + Material.background: Material.Blue Material.foreground: "white" icon.source: "qrc:/assets/icons/icon_people.svg" icon.color:"white" icon.width: 16 icon.height: 16 + onClicked: Qt.openUrlExternally("http://forum.screen-play.rocks:4567/") + } + Button { + text: qsTr("Workshop") + Material.background: Material.Red + Material.foreground: "white" + + icon.source: "qrc:/assets/icons/icon_steam.svg" + icon.color: "white" + icon.width: 16 + icon.height: 16 + onClicked: Qt.openUrlExternally( + "steam://url/SteamWorkshopPage/672870") } } } diff --git a/ScreenPlay/qml/Create/CreateWidget.qml b/ScreenPlay/qml/Create/CreateWidget.qml index bc8f344c..0dbbc360 100644 --- a/ScreenPlay/qml/Create/CreateWidget.qml +++ b/ScreenPlay/qml/Create/CreateWidget.qml @@ -1,5 +1,6 @@ import QtQuick 2.9 import QtGraphicalEffects 1.0 +import Qt.labs.platform 1.0 Item { state: "out" @@ -27,8 +28,15 @@ Item { anchors.topMargin: 20 imgSource: "qrc:/assets/icons/icon_emptyWidget.svg" onClicked: { - + folderDialog.open() } + FolderDialog { + id: folderDialog + onAccepted: { + screenPlayCreate.copyProject("/examples/scenes/empty", folderDialog.currentFolder) + } + } + } Text { id: txtExamples @@ -77,6 +85,7 @@ Item { buttonActive: true onClicked: { + } } } diff --git a/ScreenPlay/qml/Create/CreateWidgetButton.qml b/ScreenPlay/qml/Create/CreateWidgetButton.qml index 465e55de..a26ada99 100644 --- a/ScreenPlay/qml/Create/CreateWidgetButton.qml +++ b/ScreenPlay/qml/Create/CreateWidgetButton.qml @@ -85,7 +85,7 @@ Item { enabled: buttonActive cursorShape: Qt.PointingHandCursor onClicked: { - + btnEmpty.clicked() } } } diff --git a/ScreenPlay/src/create.cpp b/ScreenPlay/src/create.cpp new file mode 100644 index 00000000..248751c0 --- /dev/null +++ b/ScreenPlay/src/create.cpp @@ -0,0 +1,44 @@ +#include "create.h" + + +Create::Create(Settings *st, QMLUtilities *util, QObject *parent) : QObject(parent) +{ + m_settings = st; + m_utils = util; +} + +void Create::copyProject(QString relativeProjectPath, QString toPath) +{ + if(toPath.contains("file:///")){ + toPath.remove("file:///"); + } + QString srcFilePath = m_settings->getScreenPlayBasePath().toString() + relativeProjectPath ; + + // Todo: UI Error handling + if(copyRecursively(srcFilePath, toPath)){ + emit m_utils->openFolderInExplorer(toPath); + } +} + +bool Create::copyRecursively(const QString &srcFilePath, const QString &tgtFilePath) +{ + QFileInfo srcFileInfo(srcFilePath); + if (srcFileInfo.isDir()) { + QDir targetDir(tgtFilePath); + targetDir.cdUp(); + QDir sourceDir(srcFilePath); + QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System); + foreach (const QString &fileName, fileNames) { + const QString newSrcFilePath + = srcFilePath + QLatin1Char('/') + fileName; + const QString newTgtFilePath + = tgtFilePath + QLatin1Char('/') + fileName; + if (!copyRecursively(newSrcFilePath, newTgtFilePath)) + return false; + } + } else { + if (!QFile::copy(srcFilePath, tgtFilePath)) + return false; + } + return true; +} diff --git a/ScreenPlay/src/create.h b/ScreenPlay/src/create.h new file mode 100644 index 00000000..02caa9c5 --- /dev/null +++ b/ScreenPlay/src/create.h @@ -0,0 +1,28 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "qmlutilities.h" +#include "settings.h" + +class Create : public QObject +{ + Q_OBJECT +public: + explicit Create(Settings* st, QMLUtilities* util,QObject *parent = nullptr); + +signals: + +public slots: + void copyProject(QString relativeProjectPath, QString toPath); + bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath); + +private: + Settings* m_settings; + QMLUtilities* m_utils; +}; diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index ae1ab34a..26e1a91e 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -222,6 +222,16 @@ void Settings::createDefaultConfig() defaultSettings.close(); } +QUrl Settings::getScreenPlayBasePath() const +{ + return m_screenPlayBasePath; +} + +void Settings::setScreenPlayBasePath(QUrl screenPlayBasePath) +{ + m_screenPlayBasePath = screenPlayBasePath; +} + QUrl Settings::getScreenPlayWindowPath() const { return m_screenPlayWindowPath; diff --git a/ScreenPlay/src/settings.h b/ScreenPlay/src/settings.h index 57ce5f7e..d6d96210 100644 --- a/ScreenPlay/src/settings.h +++ b/ScreenPlay/src/settings.h @@ -118,6 +118,9 @@ public: return m_offlineMode; } + QUrl getScreenPlayBasePath() const; + void setScreenPlayBasePath(QUrl screenPlayBasePath); + signals: void autostartChanged(bool autostart); void highPriorityStartChanged(bool highPriorityStart); @@ -296,6 +299,7 @@ private: QUrl m_localStoragePath; QUrl m_localSettingsPath; QUrl m_screenPlayWindowPath; + QUrl m_screenPlayBasePath; bool m_hasWorkshopBannerSeen = false; bool m_pauseWallpaperWhenIngame = true;