From 3ce81844da80673531b8611d360bf9b211ac0da8 Mon Sep 17 00:00:00 2001 From: Zach Fox Date: Thu, 27 Apr 2017 12:53:35 -0700 Subject: [PATCH] Snapshot JS interface for better Settings handling --- interface/src/Application.cpp | 3 +++ interface/src/ui/Snapshot.cpp | 7 +++++++ interface/src/ui/Snapshot.h | 9 ++++++++- interface/src/ui/overlays/Web3DOverlay.cpp | 2 ++ scripts/system/snapshot.js | 6 +++--- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d5e1d2201b..171c755101 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -535,6 +535,7 @@ bool setupEssentials(int& argc, char** argv) { DependencyManager::set(nullptr, qApp->getOcteeSceneStats()); DependencyManager::set(); DependencyManager::set(); + DependencyManager::set(); return previousSessionCrashed; } @@ -2052,6 +2053,7 @@ void Application::initializeUi() { rootContext->setContextProperty("Scene", DependencyManager::get().data()); rootContext->setContextProperty("Render", _renderEngine->getConfiguration().get()); rootContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface()); + rootContext->setContextProperty("Snapshot", DependencyManager::get().data()); rootContext->setContextProperty("ApplicationCompositor", &getApplicationCompositor()); @@ -5504,6 +5506,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri scriptEngine->registerGlobalObject("Menu", MenuScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("Stats", Stats::getInstance()); scriptEngine->registerGlobalObject("Settings", SettingsScriptingInterface::getInstance()); + scriptEngine->registerGlobalObject("Snapshot", DependencyManager::get().data()); scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance()); scriptEngine->registerGlobalObject("AudioStats", DependencyManager::get()->getStats().data()); scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get().data()); diff --git a/interface/src/ui/Snapshot.cpp b/interface/src/ui/Snapshot.cpp index f75190530c..59ecce5bc7 100644 --- a/interface/src/ui/Snapshot.cpp +++ b/interface/src/ui/Snapshot.cpp @@ -194,3 +194,10 @@ void Snapshot::uploadSnapshot(const QString& filename, const QUrl& href) { multiPart); } +QString Snapshot::getSnapshotsLocation() { + return snapshotsLocation.get(""); +} + +void Snapshot::setSnapshotsLocation(const QString& location) { + snapshotsLocation.set(location); +} diff --git a/interface/src/ui/Snapshot.h b/interface/src/ui/Snapshot.h index 14e1bc2e9f..93ffbbc7bb 100644 --- a/interface/src/ui/Snapshot.h +++ b/interface/src/ui/Snapshot.h @@ -18,6 +18,7 @@ #include #include +#include class QFile; class QTemporaryFile; @@ -32,7 +33,9 @@ private: QUrl _URL; }; -class Snapshot { +class Snapshot : public QObject, public Dependency { + Q_OBJECT + SINGLETON_DEPENDENCY public: static QString saveSnapshot(QImage image); static QTemporaryFile* saveTempSnapshot(QImage image); @@ -40,6 +43,10 @@ public: static Setting::Handle snapshotsLocation; static void uploadSnapshot(const QString& filename, const QUrl& href = QUrl("")); + +public slots: + Q_INVOKABLE QString getSnapshotsLocation(); + Q_INVOKABLE void setSnapshotsLocation(const QString& location); private: static QFile* savedFileForSnapshot(QImage & image, bool isTemporary); }; diff --git a/interface/src/ui/overlays/Web3DOverlay.cpp b/interface/src/ui/overlays/Web3DOverlay.cpp index 24b12dacf0..fedead5aa5 100644 --- a/interface/src/ui/overlays/Web3DOverlay.cpp +++ b/interface/src/ui/overlays/Web3DOverlay.cpp @@ -51,6 +51,7 @@ #include "ui/AvatarInputs.h" #include "avatar/AvatarManager.h" #include "scripting/GlobalServicesScriptingInterface.h" +#include "ui/Snapshot.h" static const float DPI = 30.47f; static const float INCHES_TO_METERS = 1.0f / 39.3701f; @@ -177,6 +178,7 @@ void Web3DOverlay::loadSourceURL() { _webSurface->getRootContext()->setContextProperty("Quat", new Quat()); _webSurface->getRootContext()->setContextProperty("MyAvatar", DependencyManager::get()->getMyAvatar().get()); _webSurface->getRootContext()->setContextProperty("Entities", DependencyManager::get().data()); + _webSurface->getRootContext()->setContextProperty("Snapshot", DependencyManager::get().data()); if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") { auto tabletScriptingInterface = DependencyManager::get(); diff --git a/scripts/system/snapshot.js b/scripts/system/snapshot.js index 6d0c4bbf58..e342a5d149 100644 --- a/scripts/system/snapshot.js +++ b/scripts/system/snapshot.js @@ -7,7 +7,7 @@ // Distributed under the Apache License, Version 2.0 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -/* globals Tablet, Script, HMD, Settings, DialogsManager, Menu, Reticle, OverlayWebWindow, Desktop, Account, MyAvatar */ +/* globals Tablet, Script, HMD, Settings, DialogsManager, Menu, Reticle, OverlayWebWindow, Desktop, Account, MyAvatar, Snapshot */ /* eslint indent: ["error", 4, { "outerIIFEBody": 0 }] */ (function() { // BEGIN LOCAL_SCOPE @@ -116,7 +116,7 @@ function onMessage(message) { action: "captureSettings", setting: Settings.getValue("alsoTakeAnimatedSnapshot", true) })); - if (Settings.getValue("snapshotsLocation", "") !== "") { + if (Snapshot.getSnapshotsLocation() !== "") { tablet.emitScriptEvent(JSON.stringify({ type: "snapshot", action: "showPreviousImages", @@ -141,7 +141,7 @@ function onMessage(message) { var snapshotPath = Window.browseDir("Choose Snapshots Directory", "", ""); if (snapshotPath) { // not cancelled - Settings.setValue("snapshotsLocation", snapshotPath); + Snapshot.setSnapshotsLocation(snapshotPath); tablet.emitScriptEvent(JSON.stringify({ type: "snapshot", action: "snapshotLocationChosen"