mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-05-29 10:51:31 +02:00
Added save/file dialog for transition configurations in transition editor
This commit is contained in:
parent
7fa5e384b9
commit
e4416db06f
4 changed files with 72 additions and 23 deletions
|
@ -340,11 +340,9 @@ QString FadeConfig::eventNames[FADE_CATEGORY_COUNT] = {
|
||||||
"avatar_change",
|
"avatar_change",
|
||||||
};
|
};
|
||||||
|
|
||||||
void FadeConfig::save() const {
|
void FadeConfig::save(const QString& configFilePath) const {
|
||||||
// Save will only work if the HIFI_USE_SOURCE_TREE_RESOURCES environment variable is set
|
|
||||||
assert(editedCategory < FADE_CATEGORY_COUNT);
|
assert(editedCategory < FADE_CATEGORY_COUNT);
|
||||||
QJsonObject lProperties;
|
QJsonObject lProperties;
|
||||||
const QString configFilePath = PathUtils::resourcesPath() + "config/" + eventNames[editedCategory] + ".json";
|
|
||||||
QFile file(configFilePath);
|
QFile file(configFilePath);
|
||||||
if (!file.open(QFile::WriteOnly | QFile::Text)) {
|
if (!file.open(QFile::WriteOnly | QFile::Text)) {
|
||||||
qWarning() << "Fade event configuration file " << configFilePath << " cannot be opened";
|
qWarning() << "Fade event configuration file " << configFilePath << " cannot be opened";
|
||||||
|
@ -369,8 +367,7 @@ void FadeConfig::save() const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FadeConfig::load() {
|
void FadeConfig::load(const QString& configFilePath) {
|
||||||
const QString configFilePath = PathUtils::resourcesPath() + "config/" + eventNames[editedCategory] + ".json";
|
|
||||||
QFile file(configFilePath);
|
QFile file(configFilePath);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
qWarning() << "Fade event configuration file " << configFilePath << " does not exist";
|
qWarning() << "Fade event configuration file " << configFilePath << " does not exist";
|
||||||
|
|
|
@ -160,8 +160,8 @@ public:
|
||||||
float manualThreshold{ 0.f };
|
float manualThreshold{ 0.f };
|
||||||
bool manualFade{ false };
|
bool manualFade{ false };
|
||||||
|
|
||||||
Q_INVOKABLE void save() const;
|
Q_INVOKABLE void save(const QString& filePath) const;
|
||||||
Q_INVOKABLE void load();
|
Q_INVOKABLE void load(const QString& filePath);
|
||||||
|
|
||||||
static QString eventNames[FADE_CATEGORY_COUNT];
|
static QString eventNames[FADE_CATEGORY_COUNT];
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"use strict";
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// debugTransition.js
|
// debugTransition.js
|
||||||
// developer/utilities/render
|
// developer/utilities/render
|
||||||
|
@ -12,12 +10,17 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var TABLET_BUTTON_NAME = "Transition";
|
var TABLET_BUTTON_NAME = "Transition";
|
||||||
var QMLAPP_URL = Script.resolvePath("./transition.qml");
|
var QMLAPP_URL = Script.resolvePath("./transition.qml");
|
||||||
var ICON_URL = Script.resolvePath("../../../system/assets/images/transition-i.svg");
|
var ICON_URL = Script.resolvePath("../../../system/assets/images/transition-i.svg");
|
||||||
var ACTIVE_ICON_URL = Script.resolvePath("../../../system/assets/images/transition-a.svg");
|
var ACTIVE_ICON_URL = Script.resolvePath("../../../system/assets/images/transition-a.svg");
|
||||||
|
|
||||||
|
Script.include([
|
||||||
|
Script.resolvePath("../../../system/libraries/stringHelpers.js"),
|
||||||
|
]);
|
||||||
|
|
||||||
var onScreen = false;
|
var onScreen = false;
|
||||||
|
|
||||||
function onClicked() {
|
function onClicked() {
|
||||||
|
@ -106,10 +109,21 @@
|
||||||
|
|
||||||
Script.update.connect(update);
|
Script.update.connect(update);
|
||||||
|
|
||||||
|
function loadConfiguration(fileUrl) {
|
||||||
|
var config = Render.getConfig("RenderMainView.Fade")
|
||||||
|
config.load(fileUrl)
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveConfiguration(fileUrl) {
|
||||||
|
var config = Render.getConfig("RenderMainView.Fade")
|
||||||
|
config.save(fileUrl)
|
||||||
|
}
|
||||||
|
|
||||||
function fromQml(message) {
|
function fromQml(message) {
|
||||||
tokens = message.split(' ')
|
tokens = message.split('*')
|
||||||
print("Received '"+message+"' from transition.qml")
|
print("Received '"+message+"' from transition.qml")
|
||||||
if (tokens[0]=="edit") {
|
command = tokens[0].toLowerCase()
|
||||||
|
if (command=="edit") {
|
||||||
isEditEnabled = (tokens[1]=="true")
|
isEditEnabled = (tokens[1]=="true")
|
||||||
if (isEditEnabled) {
|
if (isEditEnabled) {
|
||||||
if (gradientSphere==undefined) {
|
if (gradientSphere==undefined) {
|
||||||
|
@ -138,9 +152,28 @@
|
||||||
noiseSphere = undefined
|
noiseSphere = undefined
|
||||||
gradientSphere = undefined
|
gradientSphere = undefined
|
||||||
}
|
}
|
||||||
} else if (tokens[0]=="category") {
|
} else if (command=="category") {
|
||||||
editedCategory = parseInt(tokens[1])
|
editedCategory = parseInt(tokens[1])
|
||||||
}
|
} else if (command=="save") {
|
||||||
|
var filePath = tokens[1]
|
||||||
|
print("Raw token = "+filePath)
|
||||||
|
if (filePath.startsWith("file:///")) {
|
||||||
|
filePath = filePath.substr(8)
|
||||||
|
print("Saving configuration to "+filePath)
|
||||||
|
saveConfiguration(filePath)
|
||||||
|
} else {
|
||||||
|
print("Configurations can only be saved to local files")
|
||||||
|
}
|
||||||
|
} else if (command=="load") {
|
||||||
|
var filePath = tokens[1]
|
||||||
|
if (filePath.startsWith("file:///")) {
|
||||||
|
filePath = filePath.substr(8)
|
||||||
|
print("Loading configuration from "+filePath)
|
||||||
|
loadConfiguration(filePath)
|
||||||
|
} else {
|
||||||
|
print("Configurations can only be loaded from local files")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
button.clicked.connect(onClicked);
|
button.clicked.connect(onClicked);
|
||||||
|
@ -172,6 +205,7 @@
|
||||||
color: COLOR2,
|
color: COLOR2,
|
||||||
ignoreRayIntersection: true
|
ignoreRayIntersection: true
|
||||||
}
|
}
|
||||||
|
|
||||||
var laser = Pointers.createPointer(PickType.Ray, {
|
var laser = Pointers.createPointer(PickType.Ray, {
|
||||||
joint: "Mouse",
|
joint: "Mouse",
|
||||||
filter: Picks.PICK_ENTITIES,
|
filter: Picks.PICK_ENTITIES,
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
import QtQuick 2.7
|
import QtQuick 2.7
|
||||||
import QtQuick.Controls 1.4
|
import QtQuick.Controls 1.4
|
||||||
import QtQuick.Layouts 1.3
|
import QtQuick.Layouts 1.3
|
||||||
|
import QtQuick.Dialogs 1.0
|
||||||
|
|
||||||
import "qrc:///qml/styles-uit"
|
import "qrc:///qml/styles-uit"
|
||||||
import "qrc:///qml/controls-uit" as HifiControls
|
import "qrc:///qml/controls-uit" as HifiControls
|
||||||
|
@ -29,6 +30,24 @@ Rectangle {
|
||||||
property var config: Render.getConfig("RenderMainView.Fade");
|
property var config: Render.getConfig("RenderMainView.Fade");
|
||||||
property var configEdit: Render.getConfig("RenderMainView.FadeEdit");
|
property var configEdit: Render.getConfig("RenderMainView.FadeEdit");
|
||||||
|
|
||||||
|
FileDialog {
|
||||||
|
id: fileDialog
|
||||||
|
title: "Please choose a file"
|
||||||
|
folder: shortcuts.documents
|
||||||
|
nameFilters: [ "JSON files (*.json)", "All files (*)" ]
|
||||||
|
onAccepted: {
|
||||||
|
root.sendToScript(title.split(" ")[0]+"*"+fileUrl.toString())
|
||||||
|
// This is a hack to be sure the widgets below properly reflect the change of category: delete the Component
|
||||||
|
// by setting the loader source to Null and then recreate it 500ms later
|
||||||
|
paramWidgetLoader.sourceComponent = undefined;
|
||||||
|
postpone.interval = 500
|
||||||
|
postpone.start()
|
||||||
|
}
|
||||||
|
onRejected: {
|
||||||
|
}
|
||||||
|
Component.onCompleted: visible = false
|
||||||
|
}
|
||||||
|
|
||||||
ColumnLayout {
|
ColumnLayout {
|
||||||
spacing: 3
|
spacing: 3
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
@ -50,7 +69,7 @@ Rectangle {
|
||||||
checked: root.configEdit["editFade"]
|
checked: root.configEdit["editFade"]
|
||||||
onCheckedChanged: {
|
onCheckedChanged: {
|
||||||
root.configEdit["editFade"] = checked;
|
root.configEdit["editFade"] = checked;
|
||||||
root.sendToScript("edit "+checked);
|
root.sendToScript("edit*"+checked);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HifiControls.ComboBox {
|
HifiControls.ComboBox {
|
||||||
|
@ -72,7 +91,7 @@ Rectangle {
|
||||||
paramWidgetLoader.sourceComponent = undefined;
|
paramWidgetLoader.sourceComponent = undefined;
|
||||||
postpone.interval = 100
|
postpone.interval = 100
|
||||||
postpone.start()
|
postpone.start()
|
||||||
root.sendToScript("category "+currentIndex)
|
root.sendToScript("category*"+currentIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,19 +126,18 @@ Rectangle {
|
||||||
id: saveAction
|
id: saveAction
|
||||||
text: "Save"
|
text: "Save"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.config.save()
|
fileDialog.title = "Save configuration..."
|
||||||
|
fileDialog.selectExisting = false
|
||||||
|
fileDialog.open()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Action {
|
Action {
|
||||||
id: loadAction
|
id: loadAction
|
||||||
text: "Load"
|
text: "Load"
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
root.config.load()
|
fileDialog.title = "Load configuration..."
|
||||||
// This is a hack to be sure the widgets below properly reflect the change of category: delete the Component
|
fileDialog.selectExisting = true
|
||||||
// by setting the loader source to Null and then recreate it 500ms later
|
fileDialog.open()
|
||||||
paramWidgetLoader.sourceComponent = undefined;
|
|
||||||
postpone.interval = 500
|
|
||||||
postpone.start()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue