mirror of
https://github.com/overte-org/overte.git
synced 2025-07-23 06:44:07 +02:00
Merge pull request #4424 from huffman/open-svo
Handle drag-n-dropped .svos and using interface to open .svo files
This commit is contained in:
commit
f91a19a918
7 changed files with 70 additions and 31 deletions
|
@ -95,6 +95,21 @@ var isActive = false;
|
||||||
|
|
||||||
var placingEntityID = null;
|
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 toolBar = (function () {
|
||||||
var that = {},
|
var that = {},
|
||||||
toolBar,
|
toolBar,
|
||||||
|
@ -753,6 +768,8 @@ Script.scriptEnding.connect(function() {
|
||||||
tooltip.cleanup();
|
tooltip.cleanup();
|
||||||
selectionDisplay.cleanup();
|
selectionDisplay.cleanup();
|
||||||
Entities.setLightsArePickable(originalLightsArePickable);
|
Entities.setLightsArePickable(originalLightsArePickable);
|
||||||
|
|
||||||
|
Overlays.deleteOverlay(importingSVOOverlay);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Do some stuff regularly, like check for placement of various overlays
|
// Do some stuff regularly, like check for placement of various overlays
|
||||||
|
@ -816,24 +833,7 @@ function handeMenuEvent(menuItem) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (importURL) {
|
if (importURL) {
|
||||||
var success = Clipboard.importEntities(importURL);
|
importSVO(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.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (menuItem == "Entity List...") {
|
} else if (menuItem == "Entity List...") {
|
||||||
entityListTool.toggleVisible();
|
entityListTool.toggleVisible();
|
||||||
|
@ -841,6 +841,34 @@ function handeMenuEvent(menuItem) {
|
||||||
tooltip.show(false);
|
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);
|
Menu.menuItemEvent.connect(handeMenuEvent);
|
||||||
|
|
||||||
Controller.keyPressEvent.connect(function(event) {
|
Controller.keyPressEvent.connect(function(event) {
|
||||||
|
|
|
@ -244,6 +244,7 @@ bool setupEssentials(int& argc, char** argv) {
|
||||||
auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
|
auto bandwidthRecorder = DependencyManager::set<BandwidthRecorder>();
|
||||||
auto resouceCacheSharedItems = DependencyManager::set<ResouceCacheSharedItems>();
|
auto resouceCacheSharedItems = DependencyManager::set<ResouceCacheSharedItems>();
|
||||||
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
|
auto entityScriptingInterface = DependencyManager::set<EntityScriptingInterface>();
|
||||||
|
auto windowScriptingInterface = DependencyManager::set<WindowScriptingInterface>();
|
||||||
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
|
||||||
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
auto speechRecognizer = DependencyManager::set<SpeechRecognizer>();
|
||||||
#endif
|
#endif
|
||||||
|
@ -882,9 +883,15 @@ bool Application::event(QEvent* event) {
|
||||||
if (event->type() == QEvent::FileOpen) {
|
if (event->type() == QEvent::FileOpen) {
|
||||||
|
|
||||||
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
QFileOpenEvent* fileEvent = static_cast<QFileOpenEvent*>(event);
|
||||||
|
|
||||||
|
QUrl url = fileEvent->url();
|
||||||
|
|
||||||
if (!fileEvent->url().isEmpty()) {
|
if (!url.isEmpty()) {
|
||||||
DependencyManager::get<AddressManager>()->handleLookupString(fileEvent->url().toString());
|
if (url.scheme() == HIFI_URL_SCHEME) {
|
||||||
|
DependencyManager::get<AddressManager>()->handleLookupString(fileEvent->url().toString());
|
||||||
|
} else if (url.url().toLower().endsWith(SVO_EXTENSION)) {
|
||||||
|
emit svoImportRequested(url.url());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -1451,6 +1458,10 @@ void Application::dropEvent(QDropEvent *event) {
|
||||||
if (url.url().toLower().endsWith(SNAPSHOT_EXTENSION)) {
|
if (url.url().toLower().endsWith(SNAPSHOT_EXTENSION)) {
|
||||||
snapshotPath = url.toLocalFile();
|
snapshotPath = url.toLocalFile();
|
||||||
break;
|
break;
|
||||||
|
} else if (url.url().toLower().endsWith(SVO_EXTENSION)) {
|
||||||
|
emit svoImportRequested(url.url());
|
||||||
|
event->acceptProposedAction();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3528,7 +3539,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
||||||
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue,
|
qScriptRegisterMetaType(scriptEngine, RayToOverlayIntersectionResultToScriptValue,
|
||||||
RayToOverlayIntersectionResultFromScriptValue);
|
RayToOverlayIntersectionResultFromScriptValue);
|
||||||
|
|
||||||
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", WindowScriptingInterface::getInstance());
|
QScriptValue windowValue = scriptEngine->registerGlobalObject("Window", DependencyManager::get<WindowScriptingInterface>().data());
|
||||||
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
|
scriptEngine->registerGetterSetter("location", LocationScriptingInterface::locationGetter,
|
||||||
LocationScriptingInterface::locationSetter, windowValue);
|
LocationScriptingInterface::locationSetter, windowValue);
|
||||||
// register `location` on the global object.
|
// register `location` on the global object.
|
||||||
|
|
|
@ -94,6 +94,7 @@ static const float NODE_KILLED_GREEN = 0.0f;
|
||||||
static const float NODE_KILLED_BLUE = 0.0f;
|
static const float NODE_KILLED_BLUE = 0.0f;
|
||||||
|
|
||||||
static const QString SNAPSHOT_EXTENSION = ".jpg";
|
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_FIELD_OF_VIEW = 30.0f; // degrees
|
||||||
static const float BILLBOARD_DISTANCE = 5.56f; // meters
|
static const float BILLBOARD_DISTANCE = 5.56f; // meters
|
||||||
|
@ -315,6 +316,8 @@ signals:
|
||||||
|
|
||||||
void scriptLocationChanged(const QString& newPath);
|
void scriptLocationChanged(const QString& newPath);
|
||||||
|
|
||||||
|
void svoImportRequested(const QString& url);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void updateWindowTitle();
|
void updateWindowTitle();
|
||||||
|
|
|
@ -170,7 +170,8 @@ void GLCanvas::wheelEvent(QWheelEvent* event) {
|
||||||
void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
|
void GLCanvas::dragEnterEvent(QDragEnterEvent* event) {
|
||||||
const QMimeData *mimeData = event->mimeData();
|
const QMimeData *mimeData = event->mimeData();
|
||||||
foreach (QUrl url, mimeData->urls()) {
|
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();
|
event->acceptProposedAction();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ void WebWindowClass::setVisible(bool visible) {
|
||||||
QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) {
|
QScriptValue WebWindowClass::constructor(QScriptContext* context, QScriptEngine* engine) {
|
||||||
WebWindowClass* retVal;
|
WebWindowClass* retVal;
|
||||||
QString file = context->argument(0).toString();
|
QString file = context->argument(0).toString();
|
||||||
QMetaObject::invokeMethod(WindowScriptingInterface::getInstance(), "doCreateWebWindow", Qt::BlockingQueuedConnection,
|
QMetaObject::invokeMethod(DependencyManager::get<WindowScriptingInterface>().data(), "doCreateWebWindow", Qt::BlockingQueuedConnection,
|
||||||
Q_RETURN_ARG(WebWindowClass*, retVal),
|
Q_RETURN_ARG(WebWindowClass*, retVal),
|
||||||
Q_ARG(const QString&, file),
|
Q_ARG(const QString&, file),
|
||||||
Q_ARG(QString, context->argument(1).toString()),
|
Q_ARG(QString, context->argument(1).toString()),
|
||||||
|
|
|
@ -25,11 +25,6 @@
|
||||||
|
|
||||||
#include "WindowScriptingInterface.h"
|
#include "WindowScriptingInterface.h"
|
||||||
|
|
||||||
WindowScriptingInterface* WindowScriptingInterface::getInstance() {
|
|
||||||
static WindowScriptingInterface sharedInstance;
|
|
||||||
return &sharedInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
WindowScriptingInterface::WindowScriptingInterface() :
|
WindowScriptingInterface::WindowScriptingInterface() :
|
||||||
_editDialog(NULL),
|
_editDialog(NULL),
|
||||||
_nonBlockingFormActive(false),
|
_nonBlockingFormActive(false),
|
||||||
|
@ -37,6 +32,7 @@ WindowScriptingInterface::WindowScriptingInterface() :
|
||||||
{
|
{
|
||||||
const DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
const DomainHandler& domainHandler = DependencyManager::get<NodeList>()->getDomainHandler();
|
||||||
connect(&domainHandler, &DomainHandler::hostnameChanged, this, &WindowScriptingInterface::domainChanged);
|
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) {
|
WebWindowClass* WindowScriptingInterface::doCreateWebWindow(const QString& title, const QString& url, int width, int height) {
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
#include "WebWindowClass.h"
|
#include "WebWindowClass.h"
|
||||||
|
|
||||||
class WindowScriptingInterface : public QObject {
|
class WindowScriptingInterface : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(int innerWidth READ getInnerWidth)
|
Q_PROPERTY(int innerWidth READ getInnerWidth)
|
||||||
Q_PROPERTY(int innerHeight READ getInnerHeight)
|
Q_PROPERTY(int innerHeight READ getInnerHeight)
|
||||||
|
@ -29,7 +29,7 @@ class WindowScriptingInterface : public QObject {
|
||||||
Q_PROPERTY(int y READ getY)
|
Q_PROPERTY(int y READ getY)
|
||||||
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible)
|
Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible)
|
||||||
public:
|
public:
|
||||||
static WindowScriptingInterface* getInstance();
|
WindowScriptingInterface();
|
||||||
int getInnerWidth();
|
int getInnerWidth();
|
||||||
int getInnerHeight();
|
int getInnerHeight();
|
||||||
int getX();
|
int getX();
|
||||||
|
@ -60,6 +60,7 @@ signals:
|
||||||
void domainChanged(const QString& domainHostname);
|
void domainChanged(const QString& domainHostname);
|
||||||
void inlineButtonClicked(const QString& name);
|
void inlineButtonClicked(const QString& name);
|
||||||
void nonBlockingFormClosed();
|
void nonBlockingFormClosed();
|
||||||
|
void svoImportRequested(const QString& url);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
QScriptValue showAlert(const QString& message);
|
QScriptValue showAlert(const QString& message);
|
||||||
|
@ -85,7 +86,6 @@ private slots:
|
||||||
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height);
|
WebWindowClass* doCreateWebWindow(const QString& title, const QString& url, int width, int height);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WindowScriptingInterface();
|
|
||||||
QString jsRegExp2QtRegExp(QString string);
|
QString jsRegExp2QtRegExp(QString string);
|
||||||
QDialog* createForm(const QString& title, QScriptValue form);
|
QDialog* createForm(const QString& title, QScriptValue form);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue