From d6f5296c3b68d265e801128ccdb918401cccb763 Mon Sep 17 00:00:00 2001 From: Brad Davis Date: Tue, 29 Dec 2015 12:22:12 -0500 Subject: [PATCH] Working on event bridge and scripting interfaces --- interface/resources/qml/QmlWindow.qml | 64 ++++++++++++++++++++++++--- interface/src/Application.cpp | 49 ++++++++++++++++++-- 2 files changed, 103 insertions(+), 10 deletions(-) diff --git a/interface/resources/qml/QmlWindow.qml b/interface/resources/qml/QmlWindow.qml index 71d66fb99f..c5d942518f 100644 --- a/interface/resources/qml/QmlWindow.qml +++ b/interface/resources/qml/QmlWindow.qml @@ -3,6 +3,7 @@ import QtQuick 2.3 import QtQuick.Controls 1.2 import QtWebChannel 1.0 import QtWebSockets 1.0 +import "qrc:///qtwebchannel/qwebchannel.js" as WebChannel import "controls" import "styles" @@ -12,19 +13,57 @@ VrDialog { HifiConstants { id: hifi } title: "QmlWindow" resizable: true - enabled: false + enabled: false + focus: true + property var channel; + + // Don't destroy on close... otherwise the JS/C++ will have a dangling pointer destroyOnCloseButton: false contentImplicitWidth: clientArea.implicitWidth contentImplicitHeight: clientArea.implicitHeight - property url source: "" + property alias source: pageLoader.source - onEnabledChanged: { - if (enabled) { - clientArea.forceActiveFocus() + /* + WebSocket { + id: socket + url: "ws://localhost:51016"; + active: false + + // the following three properties/functions are required to align the QML WebSocket API with the HTML5 WebSocket API. + property var send: function (arg) { + sendTextMessage(arg); } - } + onTextMessageReceived: { + onmessage({data: message}); + } + + property var onmessage; + + onStatusChanged: { + if (socket.status == WebSocket.Error) { + console.error("Error: " + socket.errorString) + } else if (socket.status == WebSocket.Closed) { + console.log("Socket closed"); + } else if (socket.status == WebSocket.Open) { + console.log("Connected") + //open the webchannel with the socket as transport + new WebChannel.QWebChannel(socket, function(ch) { + root.channel = ch; + var myUrl = root.source.toString().toLowerCase(); + console.log(myUrl); + var bridge = root.channel.objects[myUrl]; + console.log(bridge); + }); + } + } + } + */ + Keys.onPressed: { + console.log("QmlWindow keypress") + } + Item { id: clientArea implicitHeight: 600 @@ -33,12 +72,23 @@ VrDialog { y: root.clientY width: root.clientWidth height: root.clientHeight + focus: true Loader { id: pageLoader objectName: "Loader" - source: root.source anchors.fill: parent + focus: true + + onLoaded: { + console.log("Loaded content") + //socket.active = true; //connect + forceActiveFocus() + } + + Keys.onPressed: { + console.log("QmlWindow pageLoader keypress") + } } } // item } // dialog diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index d10679cc3a..5ad12102f7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1094,9 +1094,52 @@ void Application::initializeUi() { offscreenUi->setBaseUrl(QUrl::fromLocalFile(PathUtils::resourcesPath() + "/qml/")); offscreenUi->load("Root.qml"); offscreenUi->load("RootMenu.qml"); - auto scriptingInterface = DependencyManager::get(); - offscreenUi->getRootContext()->setContextProperty("Controller", scriptingInterface.data()); - offscreenUi->getRootContext()->setContextProperty("MyAvatar", getMyAvatar()); + + auto rootContext = offscreenUi->getRootContext(); + rootContext->setContextProperty("Audio", &AudioScriptingInterface::getInstance()); + rootContext->setContextProperty("AnimationCache", DependencyManager::get().data()); + rootContext->setContextProperty("Controller", DependencyManager::get().data()); + rootContext->setContextProperty("Entities", DependencyManager::get().data()); + rootContext->setContextProperty("MyAvatar", getMyAvatar()); + rootContext->setContextProperty("Messages", DependencyManager::get().data()); + rootContext->setContextProperty("Recording", DependencyManager::get().data()); + + rootContext->setContextProperty("TREE_SCALE", TREE_SCALE); + rootContext->setContextProperty("Quat", new Quat()); + rootContext->setContextProperty("Vec3", new Vec3()); + rootContext->setContextProperty("Uuid", new ScriptUUID()); + + rootContext->setContextProperty("AvatarList", DependencyManager::get().data()); + + rootContext->setContextProperty("Camera", &_myCamera); + +#if defined(Q_OS_MAC) || defined(Q_OS_WIN) + rootContext->setContextProperty("SpeechRecognizer", DependencyManager::get().data()); +#endif + + rootContext->setContextProperty("Overlays", &_overlays); + rootContext->setContextProperty("Desktop", DependencyManager::get().data()); + + rootContext->setContextProperty("Window", DependencyManager::get().data()); + rootContext->setContextProperty("Menu", MenuScriptingInterface::getInstance()); + rootContext->setContextProperty("Stats", Stats::getInstance()); + rootContext->setContextProperty("Settings", SettingsScriptingInterface::getInstance()); + rootContext->setContextProperty("AudioDevice", AudioDeviceScriptingInterface::getInstance()); + rootContext->setContextProperty("AnimationCache", DependencyManager::get().data()); + rootContext->setContextProperty("SoundCache", DependencyManager::get().data()); + rootContext->setContextProperty("Account", AccountScriptingInterface::getInstance()); + rootContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface); + rootContext->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance()); + rootContext->setContextProperty("FaceTracker", DependencyManager::get().data()); + rootContext->setContextProperty("AvatarManager", DependencyManager::get().data()); + rootContext->setContextProperty("UndoStack", &_undoStackScriptingInterface); + rootContext->setContextProperty("LODManager", DependencyManager::get().data()); + rootContext->setContextProperty("Paths", DependencyManager::get().data()); + rootContext->setContextProperty("HMD", DependencyManager::get().data()); + rootContext->setContextProperty("Scene", DependencyManager::get().data()); + rootContext->setContextProperty("Render", DependencyManager::get().data()); + rootContext->setContextProperty("ScriptDiscoveryService", this->getRunningScriptsWidget()); + _glWidget->installEventFilter(offscreenUi.data()); VrMenu::load(); VrMenu::executeQueuedLambdas();