mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:10:37 +02:00
added interactivewindow proxy. moved event bridge binding to the proxy instead
This commit is contained in:
parent
ad4f0f500c
commit
ddc678bbc0
2 changed files with 42 additions and 4 deletions
|
@ -69,6 +69,16 @@ void QmlWindowProxy::parentNativeWindowToMainWindow() {
|
||||||
#endif
|
#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) {
|
static void qmlWindowProxyDeleter(QmlWindowProxy* qmlWindowProxy) {
|
||||||
qmlWindowProxy->deleteLater();
|
qmlWindowProxy->deleteLater();
|
||||||
}
|
}
|
||||||
|
@ -129,6 +139,10 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
presentationMode = (InteractiveWindowPresentationMode) properties[PRESENTATION_MODE_PROPERTY].toInt();
|
presentationMode = (InteractiveWindowPresentationMode) properties[PRESENTATION_MODE_PROPERTY].toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_interactiveWindowProxy) {
|
||||||
|
_interactiveWindowProxy = new InteractiveWindowProxy();
|
||||||
|
}
|
||||||
|
|
||||||
if (properties.contains(DOCKED_PROPERTY) && presentationMode == InteractiveWindowPresentationMode::Native) {
|
if (properties.contains(DOCKED_PROPERTY) && presentationMode == InteractiveWindowPresentationMode::Native) {
|
||||||
QVariantMap nativeWindowInfo = properties[DOCKED_PROPERTY].toMap();
|
QVariantMap nativeWindowInfo = properties[DOCKED_PROPERTY].toMap();
|
||||||
Qt::DockWidgetArea dockArea = Qt::TopDockWidgetArea;
|
Qt::DockWidgetArea dockArea = Qt::TopDockWidgetArea;
|
||||||
|
@ -182,11 +196,12 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QObject::connect(quickView.get(), &QQuickView::statusChanged, [&, this] (QQuickView::Status status) {
|
QObject::connect(quickView.get(), &QQuickView::statusChanged, [&, this] (QQuickView::Status status) {
|
||||||
if (status == QQuickView::Ready) {
|
if (status == QQuickView::Ready) {
|
||||||
QQuickItem* rootItem = _dockWidget->getRootItem();
|
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&)),
|
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)),
|
||||||
Qt::QueuedConnection);
|
Qt::QueuedConnection);
|
||||||
QObject::connect(rootItem, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
QObject::connect(rootItem, SIGNAL(keyPressEvent(int, int)), this, SLOT(forwardKeyPressEvent(int, int)),
|
||||||
|
@ -202,9 +217,9 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
} else {
|
} else {
|
||||||
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
auto offscreenUi = DependencyManager::get<OffscreenUi>();
|
||||||
// Build the event bridge and wrapper on the main thread
|
// 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<QmlWindowProxy>(new QmlWindowProxy(object, nullptr), qmlWindowProxyDeleter);
|
_qmlWindowProxy = std::shared_ptr<QmlWindowProxy>(new QmlWindowProxy(object, nullptr), qmlWindowProxyDeleter);
|
||||||
context->setContextProperty(EVENT_BRIDGE_PROPERTY, this);
|
context->setContextProperty(EVENT_BRIDGE_PROPERTY, _interactiveWindowProxy);
|
||||||
if (properties.contains(ADDITIONAL_FLAGS_PROPERTY)) {
|
if (properties.contains(ADDITIONAL_FLAGS_PROPERTY)) {
|
||||||
object->setProperty(ADDITIONAL_FLAGS_PROPERTY, properties[ADDITIONAL_FLAGS_PROPERTY].toUInt());
|
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) {
|
void InteractiveWindow::emitScriptEvent(const QVariant& scriptMessage) {
|
||||||
|
//_interactiveWindowProxy->emitScriptEvent(scriptMessage);
|
||||||
emit scriptEventReceived(scriptMessage);
|
emit scriptEventReceived(scriptMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InteractiveWindow::emitWebEvent(const QVariant& webMessage) {
|
void InteractiveWindow::emitWebEvent(const QVariant& webMessage) {
|
||||||
|
//_interactiveWindowProxy->emitWebEvent(webMessage);
|
||||||
emit webEventReceived(webMessage);
|
emit webEventReceived(webMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -291,6 +308,10 @@ void InteractiveWindow::close() {
|
||||||
_qmlWindowProxy->deleteLater();
|
_qmlWindowProxy->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_interactiveWindowProxy) {
|
||||||
|
delete(_interactiveWindowProxy);
|
||||||
|
}
|
||||||
|
|
||||||
if (_dockWidget) {
|
if (_dockWidget) {
|
||||||
auto window = qApp->getWindow();
|
auto window = qApp->getWindow();
|
||||||
if (QThread::currentThread() != window->thread()) {
|
if (QThread::currentThread() != window->thread()) {
|
||||||
|
|
|
@ -34,7 +34,23 @@ public:
|
||||||
QObject* getQmlWindow() const { return _qmlWindow; }
|
QObject* getQmlWindow() const { return _qmlWindow; }
|
||||||
private:
|
private:
|
||||||
QObject* _qmlWindow;
|
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:
|
private:
|
||||||
std::shared_ptr<QmlWindowProxy> _qmlWindowProxy;
|
std::shared_ptr<QmlWindowProxy> _qmlWindowProxy;
|
||||||
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
||||||
|
InteractiveWindowProxy *_interactiveWindowProxy{ nullptr };
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef InteractiveWindow* InteractiveWindowPointer;
|
typedef InteractiveWindow* InteractiveWindowPointer;
|
||||||
|
|
Loading…
Reference in a new issue