Snapshot JS interface for better Settings handling

This commit is contained in:
Zach Fox 2017-04-27 12:53:35 -07:00
parent 794751abfa
commit 3ce81844da
5 changed files with 23 additions and 4 deletions

View file

@ -535,6 +535,7 @@ bool setupEssentials(int& argc, char** argv) {
DependencyManager::set<OctreeStatsProvider>(nullptr, qApp->getOcteeSceneStats());
DependencyManager::set<AvatarBookmarks>();
DependencyManager::set<LocationBookmarks>();
DependencyManager::set<Snapshot>();
return previousSessionCrashed;
}
@ -2052,6 +2053,7 @@ void Application::initializeUi() {
rootContext->setContextProperty("Scene", DependencyManager::get<SceneScriptingInterface>().data());
rootContext->setContextProperty("Render", _renderEngine->getConfiguration().get());
rootContext->setContextProperty("Reticle", getApplicationCompositor().getReticleInterface());
rootContext->setContextProperty("Snapshot", DependencyManager::get<Snapshot>().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<Snapshot>().data());
scriptEngine->registerGlobalObject("AudioDevice", AudioDeviceScriptingInterface::getInstance());
scriptEngine->registerGlobalObject("AudioStats", DependencyManager::get<AudioClient>()->getStats().data());
scriptEngine->registerGlobalObject("AudioScope", DependencyManager::get<AudioScope>().data());

View file

@ -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);
}

View file

@ -18,6 +18,7 @@
#include <QStandardPaths>
#include <SettingHandle.h>
#include <DependencyManager.h>
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<QString> 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);
};

View file

@ -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<AvatarManager>()->getMyAvatar().get());
_webSurface->getRootContext()->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
_webSurface->getRootContext()->setContextProperty("Snapshot", DependencyManager::get<Snapshot>().data());
if (_webSurface->getRootItem() && _webSurface->getRootItem()->objectName() == "tabletRoot") {
auto tabletScriptingInterface = DependencyManager::get<TabletScriptingInterface>();

View file

@ -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"