Working on event bridge and scripting interfaces

This commit is contained in:
Brad Davis 2015-12-29 12:22:12 -05:00
parent 0901e3aae1
commit d6f5296c3b
2 changed files with 103 additions and 10 deletions

View file

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

View file

@ -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<controller::ScriptingInterface>();
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<AnimationCache>().data());
rootContext->setContextProperty("Controller", DependencyManager::get<controller::ScriptingInterface>().data());
rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
rootContext->setContextProperty("MyAvatar", getMyAvatar());
rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());
rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().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<AvatarManager>().data());
rootContext->setContextProperty("Camera", &_myCamera);
#if defined(Q_OS_MAC) || defined(Q_OS_WIN)
rootContext->setContextProperty("SpeechRecognizer", DependencyManager::get<SpeechRecognizer>().data());
#endif
rootContext->setContextProperty("Overlays", &_overlays);
rootContext->setContextProperty("Desktop", DependencyManager::get<DesktopScriptingInterface>().data());
rootContext->setContextProperty("Window", DependencyManager::get<WindowScriptingInterface>().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<AnimationCache>().data());
rootContext->setContextProperty("SoundCache", DependencyManager::get<SoundCache>().data());
rootContext->setContextProperty("Account", AccountScriptingInterface::getInstance());
rootContext->setContextProperty("DialogsManager", _dialogsManagerScriptingInterface);
rootContext->setContextProperty("GlobalServices", GlobalServicesScriptingInterface::getInstance());
rootContext->setContextProperty("FaceTracker", DependencyManager::get<DdeFaceTracker>().data());
rootContext->setContextProperty("AvatarManager", DependencyManager::get<AvatarManager>().data());
rootContext->setContextProperty("UndoStack", &_undoStackScriptingInterface);
rootContext->setContextProperty("LODManager", DependencyManager::get<LODManager>().data());
rootContext->setContextProperty("Paths", DependencyManager::get<PathUtils>().data());
rootContext->setContextProperty("HMD", DependencyManager::get<HMDScriptingInterface>().data());
rootContext->setContextProperty("Scene", DependencyManager::get<SceneScriptingInterface>().data());
rootContext->setContextProperty("Render", DependencyManager::get<RenderScriptingInterface>().data());
rootContext->setContextProperty("ScriptDiscoveryService", this->getRunningScriptsWidget());
_glWidget->installEventFilter(offscreenUi.data());
VrMenu::load();
VrMenu::executeQueuedLambdas();