diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-11-07 15:39:49 +0200 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-11-08 09:23:33 +0000 |
commit | b3a15d608daf1065f8da3b985b4d9e189fcd977b (patch) | |
tree | 05533d8dc80bf240171c02815b0640f332f300dc /editorlib | |
parent | 65e5d11f194224b74a8aa51f49c75e6f31ff9e37 (diff) |
New export GLTF dialog
Allows setting export options and more intuitive scene name handling.
Change-Id: Iad586760bcdb83ae24ef3118139fb20aac1a56d1
Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'editorlib')
-rw-r--r-- | editorlib/qml.qrc | 1 | ||||
-rw-r--r-- | editorlib/qml/EditorContent.qml | 27 | ||||
-rw-r--r-- | editorlib/qml/EditorToolbar.qml | 9 | ||||
-rw-r--r-- | editorlib/qml/ExportDialog.qml | 232 | ||||
-rw-r--r-- | editorlib/qml/inputfields/StyledButton.qml | 3 | ||||
-rw-r--r-- | editorlib/src/editorscene.cpp | 26 | ||||
-rw-r--r-- | editorlib/src/editorscene.h | 4 |
7 files changed, 265 insertions, 37 deletions
diff --git a/editorlib/qml.qrc b/editorlib/qml.qrc index a0e73bb..fef6a9b 100644 --- a/editorlib/qml.qrc +++ b/editorlib/qml.qrc @@ -87,6 +87,7 @@ <file alias="StyledRadioButton.qml">qml/inputfields/StyledRadioButton.qml</file> <file alias="SettingsDialog.qml">qml/SettingsDialog.qml</file> <file alias="CameraPositionMenu.qml">qml/CameraPositionMenu.qml</file> + <file alias="ExportDialog.qml">qml/ExportDialog.qml</file> <file>editorlib_en.qm</file> <file>editorlib_fi.qm</file> <file>shaders/ontopmaterial.frag</file> diff --git a/editorlib/qml/EditorContent.qml b/editorlib/qml/EditorContent.qml index 6248ac1..3cde3ef 100644 --- a/editorlib/qml/EditorContent.qml +++ b/editorlib/qml/EditorContent.qml @@ -46,7 +46,6 @@ Item { property url saveFolder: "file:///" property url textureFolder: "file:///" property url importFolder: "file:///" - property url exportGltfFolder: "file:///" property string saveFileTitleAddition: { if (saveFileUrl != "") " - " + saveFileUrl.toString().substring(saveFileUrl.toString().lastIndexOf("/") + 1) @@ -157,11 +156,6 @@ Item { } } - function exportGltfScene() { - exportGltfSceneDialog.folder = exportGltfFolder - exportGltfSceneDialog.open(); - } - function showNormalXPlane() { editorScene.helperPlane.enabled = true editorScene.helperPlaneTransform.rotation = @@ -367,7 +361,6 @@ Item { property alias saveFolder: editorContent.saveFolder property alias textureFolder: editorContent.textureFolder property alias importFolder: editorContent.importFolder - property alias exportGltfFolder: editorContent.exportGltfFolder property alias defaultFolder: editorContent.defaultFolder } @@ -430,22 +423,6 @@ Item { } } - FileDialog { - id: exportGltfSceneDialog - selectMultiple: false - selectExisting: false - selectFolder: true - title: qsTr("Export GLTF Scene to a folder") + editorScene.emptyString - onAccepted: { - if (editorScene.exportGltfScene(fileUrl) === true) { - notification.title = qsTr("GLTF Export Success") + editorScene.emptyString - notification.text = qsTr("Scene exported successfully.") + editorScene.emptyString - notification.open() - } - editorContent.exportGltfFolder = folder; - } - } - Shortcut { sequence: StandardKey.Copy onActivated: { @@ -571,6 +548,10 @@ Item { id: settingsDialog } + ExportDialog { + id: exportDialog + } + MessageDialog { id: closingDialog icon: StandardIcon.Warning diff --git a/editorlib/qml/EditorToolbar.qml b/editorlib/qml/EditorToolbar.qml index fe5b48a..eccf5f4 100644 --- a/editorlib/qml/EditorToolbar.qml +++ b/editorlib/qml/EditorToolbar.qml @@ -75,7 +75,7 @@ Item { ToolbarButton { enabledIconSource: "images/export_gltf.png" tooltip: qsTr("Export Scene as GLTF (Ctrl + E)") + editorScene.emptyString - onEnabledButtonClicked: editorContent.exportGltfScene() + onEnabledButtonClicked: exportDialog.show() visible: editorScene.canExportGltf } @@ -339,4 +339,11 @@ Item { sequence: "Shift+S" onActivated: settingsDialog.show() } + Shortcut { + sequence: "Ctrl+E" + onActivated: { + if (editorScene.canExportGltf) + exportDialog.show(); + } + } } diff --git a/editorlib/qml/ExportDialog.qml b/editorlib/qml/ExportDialog.qml new file mode 100644 index 0000000..d38a802 --- /dev/null +++ b/editorlib/qml/ExportDialog.qml @@ -0,0 +1,232 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the Qt3D Editor of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.5 +import QtQuick.Window 2.2 +import QtQuick.Layouts 1.2 +import QtQuick.Dialogs 1.2 +import Qt.labs.settings 1.0 + +Window { + id: dialog + title: qsTr("Export GLTF scene") + editorScene.emptyString + modality: Qt.WindowModal + width: 400 + height: 300 + color: editorContent.paneBackgroundColor + minimumHeight: exportLayout.Layout.minimumHeight + buttonRow.Layout.minimumHeight + minimumWidth: buttonRow.Layout.minimumWidth + property bool previousExportBinaryJson + property bool previousExportCompactJson + property string previousExportSceneName + property url previousExportFolder + + property bool exportBinaryJson: true + property bool exportCompactJson: false + property string exportSceneName: "" + property url exportFolder: "file:///" + property url currentFolder: exportFolder + property string folderPath: parseFolderString(currentFolder) + + property bool accepted: false + + onVisibleChanged: { + if (visible == true) { + accepted = false; + previousExportBinaryJson = exportBinaryJson; + previousExportCompactJson = exportCompactJson; + previousExportSceneName = exportSceneName; + previousExportFolder = exportFolder; + humanReadableJsonButton.checked = true; + binaryJsonButton.checked = exportBinaryJson; + compactJsonButton.checked = exportCompactJson; + sceneNameField.text = exportSceneName; + currentFolder = exportFolder; + } else { + if (accepted) { + exportBinaryJson = binaryJsonButton.checked; + exportCompactJson = compactJsonButton.checked; + exportSceneName = sceneNameField.text; + exportFolder = currentFolder; + notification.title = qsTr("GLTF Export Success"); + notification.text = qsTr("Scene exported successfully."); + notification.open(); + } else { + exportBinaryJson = previousExportBinaryJson; + exportCompactJson = previousExportCompactJson; + exportSceneName = previousExportSceneName; + exportFolder = previousExportFolder; + } + } + } + + Settings { + id: settings + // Use detailed category name, as plugin saves settings under QtCreator application + category: "Qt 3D SceneEditor GLTF Export" + property alias binaryJson: dialog.exportBinaryJson + property alias compactJson: dialog.exportCompactJson + property alias sceneName: dialog.exportSceneName + property alias folder: dialog.exportFolder + } + + ColumnLayout { + id: exportLayout + anchors.top: parent.top + anchors.bottom: separator.top + anchors.left: parent.left + anchors.right: parent.right + anchors.margins: 8 + spacing: 8 + Layout.minimumHeight: gltfOptionsLayout.Layout.minimumHeight + + sceneFilesLayout.Layout.minimumHeight + + 6 * spacing + + ColumnLayout { + id: gltfOptionsLayout + StyledLabel { + text: qsTr("JSON format") + editorScene.emptyString + font.weight: Font.Bold + } + RowLayout { + StyledRadioButton { + id: humanReadableJsonButton + } + StyledLabel { + anchors.verticalCenter: parent.verticalCenter + text: qsTr("Human Readable") + editorScene.emptyString + } + StyledRadioButton { + id: compactJsonButton + checked: exportCompactJson + } + StyledLabel { + anchors.verticalCenter: parent.verticalCenter + text: qsTr("Compact") + editorScene.emptyString + } + StyledRadioButton { + id: binaryJsonButton + checked: exportBinaryJson + } + StyledLabel { + anchors.verticalCenter: parent.verticalCenter + text: qsTr("Binary") + editorScene.emptyString + } + } + } + + ColumnLayout { + id: sceneFilesLayout + width: parent.width + spacing: 8 + Layout.bottomMargin: 8 + + StyledLabel { + text: qsTr("Export Folder") + editorScene.emptyString + font.weight: Font.Bold + } + StyledButton { + implicitWidth: parent.width + implicitHeight: editorContent.qlcControlHeight + text: folderPath + margins: 0 + onButtonClicked: fileDialog.open() + } + StyledLabel { + text: qsTr("Exported Scene Name") + editorScene.emptyString + font.weight: Font.Bold + } + StyledTextField { + id: sceneNameField + anchors.margins: 4 + inputMethodHints: Qt.ImhUrlCharactersOnly + implicitWidth: parent.width + selectByMouse: true + } + + } + } + + FileDialog { + id: fileDialog + selectMultiple: false + selectExisting: false + selectFolder: true + folder: dialog.currentFolder + title: qsTr("Export GLTF Scene to a folder") + editorScene.emptyString + onAccepted: { + dialog.currentFolder = fileUrl; + } + } + + Rectangle { + id: separator + width: parent.width + height: 1 + color: editorContent.listHighlightColor + anchors.bottom: buttonRow.top + anchors.bottomMargin: 8 + anchors.topMargin: 8 + } + + RowLayout { + id: buttonRow + anchors.bottom: parent.bottom + anchors.right: parent.right + anchors.bottomMargin: 4 + anchors.rightMargin: 4 + spacing: 4 + Layout.minimumHeight: applyButton.height + 2 * spacing + Layout.minimumWidth: applyButton.width + cancelButton.width + 4 * spacing + + StyledButton { + id: applyButton + text: qsTr("Export Scene") + editorScene.emptyString + onButtonClicked: { + var options = {binaryJson: binaryJsonButton.checked, + compactJson: compactJsonButton.checked}; + if (editorScene.exportGltfScene(currentFolder, sceneNameField.text, options) + === true) { + dialog.accepted = true; + dialog.close(); + } + } + } + StyledButton { + id: cancelButton + text: qsTr("Cancel") + editorScene.emptyString + onButtonClicked: { + dialog.accepted = false; + dialog.close(); + } + } + } + + function parseFolderString(url) { + return url.toString().replace(/^(file:\/{2,})/,""); + } +} diff --git a/editorlib/qml/inputfields/StyledButton.qml b/editorlib/qml/inputfields/StyledButton.qml index aa40f15..39fe045 100644 --- a/editorlib/qml/inputfields/StyledButton.qml +++ b/editorlib/qml/inputfields/StyledButton.qml @@ -29,6 +29,7 @@ import QtQuick 2.5 Item { property alias text: buttonText.text + property int margins: 4 width: 100 height: 32 @@ -37,7 +38,7 @@ Item { Rectangle { id: control anchors.fill: parent - anchors.margins: 4 + anchors.margins: parent.margins color: { if (mouseArea.containsPress) editorContent.iconHighlightColor diff --git a/editorlib/src/editorscene.cpp b/editorlib/src/editorscene.cpp index c9e0cc5..1d5a4ce 100644 --- a/editorlib/src/editorscene.cpp +++ b/editorlib/src/editorscene.cpp @@ -2179,19 +2179,21 @@ void EditorScene::changeCameraPosition(EditorScene::CameraPosition preset) camera->setUpVector(up); } -bool EditorScene::exportGltfScene(const QUrl &fileUrl) +bool EditorScene::exportGltfScene(const QUrl &folder, const QString &exportName, + const QJSValue &options) { #ifdef GLTF_EXPORTER_AVAILABLE if (canExportGltf()) { - QVariantHash options; - // Export binary json for maximum loading efficiency - options.insert(QStringLiteral("binaryJson"), QVariant(true)); - QString exportDir = fileUrl.toLocalFile(); - int index = exportDir.lastIndexOf(QLatin1Char('/')); - QString sceneName = exportDir.mid(index + 1); - exportDir.chop(sceneName.length() + 1); - if (exportDir.length() > 0 && sceneName.length() > 0) { - if (!m_gltfExporter->exportScene(m_sceneEntity, exportDir, sceneName, options)) + QString exportDir = folder.toLocalFile(); + QVariantHash optionsHash; + const QString binaryKey = QStringLiteral("binaryJson"); + const QString compactKey = QStringLiteral("compactJson"); + if (options.hasProperty(binaryKey)) + optionsHash.insert(binaryKey, options.property(binaryKey).toBool()); + if (options.hasProperty(compactKey)) + optionsHash.insert(compactKey, options.property(compactKey).toBool()); + if (exportDir.length() > 0 && exportName.length() > 0) { + if (!m_gltfExporter->exportScene(m_sceneEntity, exportDir, exportName, optionsHash)) setError(m_gltfExportFailString); else return true; @@ -2200,7 +2202,9 @@ bool EditorScene::exportGltfScene(const QUrl &fileUrl) } } #else - Q_UNUSED(fileUrl) + Q_UNUSED(folder) + Q_UNUSED(exportName) + Q_UNUSED(options) #endif return false; } diff --git a/editorlib/src/editorscene.h b/editorlib/src/editorscene.h index 89bbbf1..3fe5ede 100644 --- a/editorlib/src/editorscene.h +++ b/editorlib/src/editorscene.h @@ -39,6 +39,7 @@ #include <QtGui/QQuaternion> #include <Qt3DCore/QNodeId> #include <Qt3DCore/QEntity> +#include <QtQml/QJSValue> namespace Qt3DCore { class QTransform; @@ -267,7 +268,8 @@ public: Q_INVOKABLE void updateWorldPositionLabel(int xPos, int yPos); Q_INVOKABLE void updateWorldPositionLabelToDragHandle(DragMode dragMode, int handleIndex = 0); Q_INVOKABLE void changeCameraPosition(CameraPosition preset); - Q_INVOKABLE bool exportGltfScene(const QUrl &fileUrl); + Q_INVOKABLE bool exportGltfScene(const QUrl &folder, const QString &exportName, + const QJSValue &options); void removeEntityFromMultiSelection(const QString &name); void addEntityToMultiSelection(const QString &name); |