diff --git a/interface/src/ui/InteractiveWindow.cpp b/interface/src/ui/InteractiveWindow.cpp index fc2d8c56bf..0b83e2ed88 100644 --- a/interface/src/ui/InteractiveWindow.cpp +++ b/interface/src/ui/InteractiveWindow.cpp @@ -69,6 +69,16 @@ void QmlWindowProxy::parentNativeWindowToMainWindow() { #endif } +void InteractiveWindowProxy::emitScriptEvent(const QVariant& scriptMessage){ + qDebug() << "EmitScriptEvent"; + emit scriptEventReceived(scriptMessage); +} + +void InteractiveWindowProxy::emitWebEvent(const QVariant& webMessage) { + qDebug() << "EmitWebEvent"; + emit webEventReceived(webMessage); +} + static void qmlWindowProxyDeleter(QmlWindowProxy* qmlWindowProxy) { qmlWindowProxy->deleteLater(); } @@ -129,6 +139,10 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap presentationMode = (InteractiveWindowPresentationMode) properties[PRESENTATION_MODE_PROPERTY].toInt(); } + if (!_interactiveWindowProxy) { + _interactiveWindowProxy = new InteractiveWindowProxy(); + } + if (properties.contains(DOCKED_PROPERTY) && presentationMode == InteractiveWindowPresentationMode::Native) { QVariantMap nativeWindowInfo = properties[DOCKED_PROPERTY].toMap(); Qt::DockWidgetArea dockArea = Qt::TopDockWidgetArea; @@ -182,11 +196,12 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap break; } } - + + QObject::connect(quickView.get(), &QQuickView::statusChanged, [&, this] (QQuickView::Status status) { if (status == QQuickView::Ready) { QQuickItem* rootItem = _dockWidget->getRootItem(); - _dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, this); + _dockWidget->getQuickView()->rootContext()->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy); QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection); QObject::connect(rootItem, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)), @@ -202,9 +217,9 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap } else { auto offscreenUi = DependencyManager::get(); // Build the event bridge and wrapper on the main thread - offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, [&](QQmlContext* context, QObject* object) { + offscreenUi->loadInNewContext(CONTENT_WINDOW_QML, [&, this](QQmlContext* context, QObject* object) { _qmlWindowProxy = std::shared_ptr(new QmlWindowProxy(object, nullptr), qmlWindowProxyDeleter); - context->setContextProperty(EVENT_BRIDGE_PROPERTY, this); + context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy); if (properties.contains(ADDITIONAL_FLAGS_PROPERTY)) { object->setProperty(ADDITIONAL_FLAGS_PROPERTY, properties[ADDITIONAL_FLAGS_PROPERTY].toUInt()); } @@ -275,10 +290,12 @@ void InteractiveWindow::sendToQml(const QVariant& message) { } void InteractiveWindow::emitScriptEvent(const QVariant& scriptMessage) { + //_interactiveWindowProxy->emitScriptEvent(scriptMessage); emit scriptEventReceived(scriptMessage); } void InteractiveWindow::emitWebEvent(const QVariant& webMessage) { + //_interactiveWindowProxy->emitWebEvent(webMessage); emit webEventReceived(webMessage); } @@ -291,6 +308,10 @@ void InteractiveWindow::close() { _qmlWindowProxy->deleteLater(); } + if (_interactiveWindowProxy) { + delete(_interactiveWindowProxy); + } + if (_dockWidget) { auto window = qApp->getWindow(); if (QThread::currentThread() != window->thread()) { diff --git a/interface/src/ui/InteractiveWindow.h b/interface/src/ui/InteractiveWindow.h index 0098658c16..a1eede8b8a 100644 --- a/interface/src/ui/InteractiveWindow.h +++ b/interface/src/ui/InteractiveWindow.h @@ -34,7 +34,23 @@ public: QObject* getQmlWindow() const { return _qmlWindow; } private: QObject* _qmlWindow; +}; + +class InteractiveWindowProxy : public QObject { + Q_OBJECT +public: + InteractiveWindowProxy(){} + +public slots: + + void emitScriptEvent(const QVariant& scriptMessage); + void emitWebEvent(const QVariant& webMessage); + +signals: + + void scriptEventReceived(const QVariant& message); + void webEventReceived(const QVariant& message); }; @@ -309,6 +325,7 @@ protected slots: private: std::shared_ptr _qmlWindowProxy; std::shared_ptr _dockWidget { nullptr }; + InteractiveWindowProxy *_interactiveWindowProxy{ nullptr }; }; typedef InteractiveWindow* InteractiveWindowPointer;