From c0bd9121fbe1935cb537feccf9d28f470e94becf Mon Sep 17 00:00:00 2001 From: Thijs Wenker Date: Wed, 12 Dec 2018 19:55:14 +0100 Subject: [PATCH] open avatar projects --- .../resources/qml/hifi/AvatarPackager.qml | 66 +++++++++++++++---- .../qml/hifi/avatarPackager/AvatarProject.qml | 59 +++++++++++++++++ interface/src/avatar/AvatarPackager.cpp | 19 ++---- interface/src/avatar/AvatarPackager.h | 9 +-- interface/src/avatar/AvatarProject.cpp | 2 +- interface/src/avatar/AvatarProject.h | 26 +++++++- 6 files changed, 149 insertions(+), 32 deletions(-) create mode 100644 interface/resources/qml/hifi/avatarPackager/AvatarProject.qml diff --git a/interface/resources/qml/hifi/AvatarPackager.qml b/interface/resources/qml/hifi/AvatarPackager.qml index 787c8d6b69..d93a3900a8 100644 --- a/interface/resources/qml/hifi/AvatarPackager.qml +++ b/interface/resources/qml/hifi/AvatarPackager.qml @@ -7,6 +7,7 @@ import "../controlsUit" 1.0 as HifiControls import "../stylesUit" 1.0 import "../windows" as Windows import "../dialogs" +import "avatarPackager" Windows.ScrollingWindow { id: root @@ -19,35 +20,78 @@ Windows.ScrollingWindow { destroyOnHidden: true implicitWidth: 384; implicitHeight: 640 minSize: Qt.vector2d(200, 300) + + //HifiConstants { id: hifi } + + AvatarProject { + id: avatarProject + colorScheme: root.colorScheme + } + Rectangle { + id: avatarPackagerMain anchors.left: parent.left anchors.right: parent.right anchors.top: parent.top anchors.bottom: parent.bottom RalewaySemiBold { - id: displayNameLabel + id: avatarPackagerLabel size: 24; anchors.left: parent.left anchors.top: parent.top anchors.topMargin: 25 - text: 'Avatar Projects' + anchors.bottomMargin: 25 + text: 'Avatar Packager' } HifiControls.Button { + id: createProjectButton anchors.left: parent.left anchors.right: parent.right - anchors.top: displayNameLabel.bottom - text: qsTr("Open Avatar Project") - // color: hifi.buttons.blue + anchors.top: avatarPackagerLabel.bottom + text: qsTr("Create Project") colorScheme: root.colorScheme height: 30 onClicked: function() { - let avatarProject = AvatarPackagerCore.openAvatarProject(); - if (avatarProject) { - console.log("LOAD COMPLETE"); - } else { - console.log("LOAD FAILED"); - } + + } + } + HifiControls.Button { + id: openProjectButton + anchors.left: parent.left + anchors.right: parent.right + anchors.top: createProjectButton.bottom + text: qsTr("Open Avatar Project") + colorScheme: root.colorScheme + height: 30 + onClicked: function() { + var avatarProjectsPath = fileDialogHelper.standardPath(/*fileDialogHelper.StandardLocation.DocumentsLocation*/ 1) + "/High Fidelity/Avatar Projects"; + console.log("path = " + avatarProjectsPath); + + // TODO: make the dialog modal + + var browser = desktop.fileDialog({ + selectDirectory: false, + dir: fileDialogHelper.pathToUrl(avatarProjectsPath), + filter: "Avatar Project FST Files (*.fst)", + title: "Open Project (.fst)" + }); + + browser.canceled.connect(function() { + + }); + + browser.selectedFile.connect(function(fileUrl) { + console.log("FOUND PATH " + fileUrl); + let fstFilePath = fileDialogHelper.urlToPath(fileUrl); + let avatarProject = AvatarPackagerCore.openAvatarProject(fstFilePath); + if (avatarProject) { + console.log("LOAD COMPLETE"); + console.log("file dir = " + AvatarPackagerCore.currentAvatarProject.projectFolderPath); + avatarProject.visible = true; + avatarPackagerMain.visible = false; + } + }); } } } diff --git a/interface/resources/qml/hifi/avatarPackager/AvatarProject.qml b/interface/resources/qml/hifi/avatarPackager/AvatarProject.qml new file mode 100644 index 0000000000..a34c709567 --- /dev/null +++ b/interface/resources/qml/hifi/avatarPackager/AvatarProject.qml @@ -0,0 +1,59 @@ +import QtQuick 2.6 +import QtQuick.Controls 2.2 +import QtQuick.Layouts 1.3 +import QtGraphicalEffects 1.0 + +import "../../controlsUit" 1.0 as HifiControls +import "../../stylesUit" 1.0 + +Rectangle { + id: avatarProject + + HifiConstants { id: hifi } + + + z: 3 + property int colorScheme; + + visible: false + + anchors.left: parent.left + anchors.right: parent.right + anchors.top: parent.top + anchors.bottom: parent.bottom + + RalewaySemiBold { + id: avatarProjectLabel + size: 24; + anchors.left: parent.left + anchors.top: parent.top + anchors.topMargin: 25 + anchors.bottomMargin: 25 + text: 'Avatar Project' + } + HifiControls.Button { + id: openFolderButton + anchors.left: parent.left + anchors.right: parent.right + anchors.top: avatarProjectLabel.bottom + text: qsTr("Open Project Folder") + colorScheme: avatarProject.colorScheme + height: 30 + onClicked: function() { + fileDialogHelper.openDirectory(AvatarPackagerCore.currentAvatarProject.projectFolderPath); + } + } + HifiControls.Button { + id: uploadButton + anchors.left: parent.left + anchors.right: parent.right + anchors.top: openFolderButton.bottom + text: qsTr("Upload") + color: hifi.buttons.blue + colorScheme: avatarProject.colorScheme + height: 30 + onClicked: function() { + + } + } +} diff --git a/interface/src/avatar/AvatarPackager.cpp b/interface/src/avatar/AvatarPackager.cpp index ef127d4459..c6c1318eab 100644 --- a/interface/src/avatar/AvatarPackager.cpp +++ b/interface/src/avatar/AvatarPackager.cpp @@ -12,11 +12,9 @@ #include "AvatarPackager.h" #include -#include #include #include -#include "ModelSelector.h" bool AvatarPackager::open() { static const QUrl url{ "hifi/AvatarPackager.qml" }; @@ -28,17 +26,10 @@ bool AvatarPackager::open() { return true; } -QObject* AvatarPackager::openAvatarProject() { - // TODO: use QML file browser here, could handle this on QML side instead - static Setting::Handle lastModelBrowseLocation("LastModelBrowseLocation", - QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)); - const QString filename = QFileDialog::getOpenFileName(nullptr, "Select your model file ...", - lastModelBrowseLocation.get(), - "Model files (*.fst *.fbx)"); - QFileInfo fileInfo(filename); - - if (fileInfo.isFile() && fileInfo.completeSuffix().contains(QRegExp("fst|fbx|FST|FBX"))) { - return AvatarProject::openAvatarProject(fileInfo.absoluteFilePath()); +QObject* AvatarPackager::openAvatarProject(QString avatarProjectFSTPath) { + if (_currentAvatarProject) { + _currentAvatarProject->deleteLater(); } - return nullptr; + _currentAvatarProject = AvatarProject::openAvatarProject(avatarProjectFSTPath); + return _currentAvatarProject; } diff --git a/interface/src/avatar/AvatarPackager.h b/interface/src/avatar/AvatarPackager.h index 8f29f98c0b..a8ef6c6421 100644 --- a/interface/src/avatar/AvatarPackager.h +++ b/interface/src/avatar/AvatarPackager.h @@ -21,15 +21,16 @@ class AvatarPackager : public QObject, public Dependency { Q_OBJECT SINGLETON_DEPENDENCY + Q_PROPERTY(QObject* currentAvatarProject READ getAvatarProject) public: bool open(); - Q_INVOKABLE void openAvatarProjectWithoutReturnType() { - openAvatarProject(); - } + Q_INVOKABLE QObject* openAvatarProject(QString avatarProjectFSTPath); - Q_INVOKABLE QObject* openAvatarProject(); +private: + Q_INVOKABLE AvatarProject* getAvatarProject() const { return _currentAvatarProject; }; + AvatarProject* _currentAvatarProject { nullptr }; }; #endif // hifi_AvatarPackager_h diff --git a/interface/src/avatar/AvatarProject.cpp b/interface/src/avatar/AvatarProject.cpp index 876bd1725b..a3b22ab2c2 100644 --- a/interface/src/avatar/AvatarProject.cpp +++ b/interface/src/avatar/AvatarProject.cpp @@ -1,5 +1,5 @@ // -// AvatarProject.h +// AvatarProject.cpp // // // Created by Thijs Wenker on 12/7/2018 diff --git a/interface/src/avatar/AvatarProject.h b/interface/src/avatar/AvatarProject.h index cc347c3d4b..2114b147dd 100644 --- a/interface/src/avatar/AvatarProject.h +++ b/interface/src/avatar/AvatarProject.h @@ -14,8 +14,15 @@ #define hifi_AvatarProject_h #include +#include +#include class AvatarProject : public QObject { + Q_OBJECT + Q_PROPERTY(QString projectFolderPath READ getProjectPath) + Q_PROPERTY(QString projectFSTPath READ getFSTPath) + Q_PROPERTY(QString projectFBXPath READ getFBXPath) + public: Q_INVOKABLE bool write() { // Write FST here @@ -33,13 +40,28 @@ public: static AvatarProject* openAvatarProject(QString path); private: - AvatarProject(QString fstPath) { - + AvatarProject(QString fstPath) : + _fstPath(fstPath) { + auto fileInfo = QFileInfo(_fstPath); + _projectPath = fileInfo.absoluteDir().absolutePath(); + + _fstPath = _projectPath + "TemporaryFBX.fbx"; + } ~AvatarProject() { // TODO: cleanup FST / AvatarProjectUploader etc. } + + Q_INVOKABLE QString getProjectPath() const { return _projectPath; } + Q_INVOKABLE QString getFSTPath() const { return _fstPath; } + Q_INVOKABLE QString getFBXPath() const { return _fbxPath; } + + QString _projectPath; + QString _fstPath; + // TODO: handle this in the FST Class + QString _fbxPath; + }; #endif // hifi_AvatarProject_h