From 2f885bb7f21231c9d351e9a919102e061f866dda Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 11 Mar 2015 15:34:29 -0700 Subject: [PATCH 1/4] Move WindowScriptingInterface to DependencyManager --- interface/src/Application.cpp | 3 ++- interface/src/scripting/WebWindowClass.cpp | 2 +- interface/src/scripting/WindowScriptingInterface.cpp | 5 ----- interface/src/scripting/WindowScriptingInterface.h | 5 ++--- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a7a6c8c094..1dde90aeaa 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -244,6 +244,7 @@ bool setupEssentials(int& argc, char** argv) { auto bandwidthRecorder = DependencyManager::set(); auto resouceCacheSharedItems = DependencyManager::set(); auto entityScriptingInterface = DependencyManager::set(); + auto windowScriptingInterface = DependencyManager::set(); #if defined(Q_OS_MAC) || defined(Q_OS_WIN) auto speechRecognizer = DependencyManager::set(); #endif @@ -3527,7 +3528,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue, RayToOverlayIntersectionResultFromScriptValue); - QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance()); + QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get().data()); scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter, LocationScriptingInterface::locationSetter, windowValue); // register `location` on the global object. diff --git a/interface/src/scripting/WebWindowClass.cpp b/interface/src/scripting/WebWindowClass.cpp index be87870f26..2e0f88c776 100644 --- a/interface/src/scripting/WebWindowClass.cpp +++ b/interface/src/scripting/WebWindowClass.cpp @@ -73,7 +73,7 @@ void WebWindowClass::setVisible(bool visible) { QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) { WebWindowClass* retVal; QString file = context->argument(0).toString(); - QMetaObject::invokeMethod(WindowScriptingInterface::getInstance(), "doCreateWebWindow", Qt::BlockingQueuedConnection, + QMetaObject::invokeMethod(DependencyManager::get().data(), "doCreateWebWindow", Qt::BlockingQueuedConnection, Q_RETURN_ARG(WebWindowClass*, retVal), Q_ARG(const QString&, file), Q_ARG(QString, context->argument(1).toString()), diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index 8ec9fbbb82..d64c75c345 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -25,11 +25,6 @@ #include "WindowScriptingInterface.h" -WindowScriptingInterface* WindowScriptingInterface::getInstance() { - static WindowScriptingInterface sharedInstance; - return &sharedInstance; -} - WindowScriptingInterface::WindowScriptingInterface() : _editDialog(NULL), _nonBlockingFormActive(false), diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 5c0aa4f0a8..3bf3c5fb0c 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -21,7 +21,7 @@ #include "WebWindowClass.h" -class WindowScriptingInterface : public QObject { +class WindowScriptingInterface : public QObject, public Dependency { Q_OBJECT Q_PROPERTY(int innerWidth READ getInnerWidth) Q_PROPERTY(int innerHeight READ getInnerHeight) @@ -29,7 +29,7 @@ class WindowScriptingInterface : public QObject { Q_PROPERTY(int y READ getY) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible) public: - static WindowScriptingInterface* getInstance(); + WindowScriptingInterface(); int getInnerWidth(); int getInnerHeight(); int getX(); @@ -85,7 +85,6 @@ private slots: WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height); private: - WindowScriptingInterface(); QString jsRegExp2QtRegExp(QString string); QDialog* createForm(const QString& title, QScriptValue form); From c3c2a75f48184ee3011940fda6b8d86c19f95086 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 11 Mar 2015 15:38:15 -0700 Subject: [PATCH 2/4] Handle .svo drop events and emit svoImportRequested --- interface/src/Application.cpp | 10 ++++++++-- interface/src/Application.h | 3 +++ interface/src/GLCanvas.cpp | 3 ++- interface/src/scripting/WindowScriptingInterface.cpp | 1 + interface/src/scripting/WindowScriptingInterface.h | 1 + 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 1dde90aeaa..91b4cc5923 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -882,9 +882,15 @@ bool Application::event(QEvent* event) { if (event->type() == QEvent::FileOpen) { QFileOpenEvent* fileEvent = static_cast(event); + + QUrl url = fileEvent->url(); - if (!fileEvent->url().isEmpty()) { - DependencyManager::get()->handleLookupString(fileEvent->url().toString()); + if (!url.isEmpty()) { + if (url.scheme() == HIFI_URL_SCHEME) { + DependencyManager::get()->handleLookupString(fileEvent->url().toString()); + } else if (url.url().toLower().endsWith(SVO_EXTENSION)) { + emit svoImportRequested(url.url()); + } } return false; diff --git a/interface/src/Application.h b/interface/src/Application.h index d8d9132de9..262afac39a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -94,6 +94,7 @@ static const float NODE_KILLED_GREEN = 0.0f; static const float NODE_KILLED_BLUE = 0.0f; static const QString SNAPSHOT_EXTENSION = ".jpg"; +static const QString SVO_EXTENSION = ".svo"; static const float BILLBOARD_FIELD_OF_VIEW = 30.0f; // degrees static const float BILLBOARD_DISTANCE = 5.56f; // meters @@ -315,6 +316,8 @@ signals: void scriptLocationChanged(const QString& newPath); + void svoImportRequested(const QString& url); + public slots: void domainChanged(const QString& domainHostname); void updateWindowTitle(); diff --git a/interface/src/GLCanvas.cpp b/interface/src/GLCanvas.cpp index b72c00c779..4ece8f0857 100644 --- a/interface/src/GLCanvas.cpp +++ b/interface/src/GLCanvas.cpp @@ -170,7 +170,8 @@ void GLCanvas::wheelEvent(QWheelEvent* event) { void GLCanvas::dragEnterEvent(QDragEnterEvent* event) { const QMimeData *mimeData = event->mimeData(); foreach (QUrl url, mimeData->urls()) { - if (url.url().toLower().endsWith(SNAPSHOT_EXTENSION)) { + auto lower = url.url().toLower(); + if (lower.endsWith(SNAPSHOT_EXTENSION) || lower.endsWith(SVO_EXTENSION)) { event->acceptProposedAction(); break; } diff --git a/interface/src/scripting/WindowScriptingInterface.cpp b/interface/src/scripting/WindowScriptingInterface.cpp index d64c75c345..52de31df3c 100644 --- a/interface/src/scripting/WindowScriptingInterface.cpp +++ b/interface/src/scripting/WindowScriptingInterface.cpp @@ -32,6 +32,7 @@ WindowScriptingInterface::WindowScriptingInterface() : { const DomainHandler& domainHandler = DependencyManager::get()->getDomainHandler(); connect(&domainHandler, &DomainHandler::hostnameChanged, this, &WindowScriptingInterface::domainChanged); + connect(Application::getInstance(), &Application::svoImportRequested, this, &WindowScriptingInterface::svoImportRequested); } WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title, const QString& url, int width, int height) { diff --git a/interface/src/scripting/WindowScriptingInterface.h b/interface/src/scripting/WindowScriptingInterface.h index 3bf3c5fb0c..34942366eb 100644 --- a/interface/src/scripting/WindowScriptingInterface.h +++ b/interface/src/scripting/WindowScriptingInterface.h @@ -60,6 +60,7 @@ signals: void domainChanged(const QString& domainHostname); void inlineButtonClicked(const QString& name); void nonBlockingFormClosed(); + void svoImportRequested(const QString& url); private slots: QScriptValue showAlert(const QString& message); From 0048b913113159f366dfcadade5ee6160b75a42c Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 11 Mar 2015 15:42:16 -0700 Subject: [PATCH 3/4] Add handling for opening an .svo using interface --- interface/src/Application.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 91b4cc5923..48e1c4b266 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1457,6 +1457,10 @@ void Application::dropEvent(QDropEvent *event) { if (url.url().toLower().endsWith(SNAPSHOT_EXTENSION)) { snapshotPath = url.toLocalFile(); break; + } else if (url.url().toLower().endsWith(SVO_EXTENSION)) { + emit svoImportRequested(url.url()); + event->acceptProposedAction(); + return; } } From 76ebac118579d8a4aea348112d9dcef02bf2dbb8 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 11 Mar 2015 15:44:26 -0700 Subject: [PATCH 4/4] Add import svo requests in editEntities --- examples/editEntities.js | 64 +++++++++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/examples/editEntities.js b/examples/editEntities.js index faef875d9b..c236336266 100644 --- a/examples/editEntities.js +++ b/examples/editEntities.js @@ -95,6 +95,21 @@ var isActive = false; var placingEntityID = null; +IMPORTING_SVO_OVERLAY_WIDTH = 130; +IMPORTING_SVO_OVERLAY_HEIGHT = 30; +IMPORTING_SVO_OVERLAY_MARGIN = 6; +var importingSVOOverlay = Overlays.addOverlay("text", { + font: { size: 14 }, + text: "Importing SVO...", + x: Window.innerWidth - IMPORTING_SVO_OVERLAY_WIDTH - IMPORTING_SVO_OVERLAY_MARGIN, + y: Window.innerHeight - IMPORTING_SVO_OVERLAY_HEIGHT - IMPORTING_SVO_OVERLAY_MARGIN, + width: IMPORTING_SVO_OVERLAY_WIDTH, + height: IMPORTING_SVO_OVERLAY_HEIGHT, + backgroundColor: { red: 80, green: 80, blue: 80 }, + backgroundAlpha: 0.7, + visible: false, +}); + var toolBar = (function () { var that = {}, toolBar, @@ -753,6 +768,8 @@ Script.scriptEnding.connect(function() { tooltip.cleanup(); selectionDisplay.cleanup(); Entities.setLightsArePickable(originalLightsArePickable); + + Overlays.deleteOverlay(importingSVOOverlay); }); // Do some stuff regularly, like check for placement of various overlays @@ -816,24 +833,7 @@ function handeMenuEvent(menuItem) { } if (importURL) { - var success = Clipboard.importEntities(importURL); - - if (success) { - var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; - var direction = Quat.getFront(Camera.orientation); - var offset = Vec3.multiply(distance, direction); - var position = Vec3.sum(Camera.position, offset); - - position.x = Math.max(0, position.x); - position.y = Math.max(0, position.y); - position.z = Math.max(0, position.z); - - var pastedEntityIDs = Clipboard.pasteEntities(position); - - selectionManager.setSelections(pastedEntityIDs); - } else { - Window.alert("There was an error importing the entity file."); - } + importSVO(importURL); } } else if (menuItem == "Entity List...") { entityListTool.toggleVisible(); @@ -841,6 +841,34 @@ function handeMenuEvent(menuItem) { tooltip.show(false); } +function importSVO(importURL) { + Overlays.editOverlay(importingSVOOverlay, { visible: true }); + + var success = Clipboard.importEntities(importURL); + + if (success) { + var distance = cameraManager.enabled ? cameraManager.zoomDistance : DEFAULT_ENTITY_DRAG_DROP_DISTANCE; + var direction = Quat.getFront(Camera.orientation); + var offset = Vec3.multiply(distance, direction); + var position = Vec3.sum(Camera.position, offset); + + position.x = Math.max(0, position.x); + position.y = Math.max(0, position.y); + position.z = Math.max(0, position.z); + + var pastedEntityIDs = Clipboard.pasteEntities(position); + + if (isActive) { + selectionManager.setSelections(pastedEntityIDs); + } + } else { + Window.alert("There was an error importing the entity file."); + } + + Overlays.editOverlay(importingSVOOverlay, { visible: false }); +} +Window.svoImportRequested.connect(importSVO); + Menu.menuItemEvent.connect(handeMenuEvent); Controller.keyPressEvent.connect(function(event) {