mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 21:18:54 +02:00
Fix JS to QML event bridge messages with Docked Windows
This commit is contained in:
parent
70c9c07229
commit
0400bc6da0
2 changed files with 3 additions and 5 deletions
|
@ -69,7 +69,6 @@ void interactiveWindowPointerFromScriptValue(const QScriptValue& object, Interac
|
||||||
}
|
}
|
||||||
|
|
||||||
InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap& properties) {
|
InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap& properties) {
|
||||||
bool docked = false;
|
|
||||||
InteractiveWindowPresentationMode presentationMode = InteractiveWindowPresentationMode::Native;
|
InteractiveWindowPresentationMode presentationMode = InteractiveWindowPresentationMode::Native;
|
||||||
|
|
||||||
if (properties.contains(PRESENTATION_MODE_PROPERTY)) {
|
if (properties.contains(PRESENTATION_MODE_PROPERTY)) {
|
||||||
|
@ -124,12 +123,12 @@ InteractiveWindow::InteractiveWindow(const QString& sourceUrl, const QVariantMap
|
||||||
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);
|
||||||
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection);
|
QObject::connect(rootItem, SIGNAL(sendToScript(QVariant)), this, SLOT(qmlToScript(const QVariant&)), Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
_dockWidget->setSource(QUrl(sourceUrl));
|
_dockWidget->setSource(QUrl(sourceUrl));
|
||||||
mainWindow->addDockWidget(dockArea, _dockWidget.get());
|
mainWindow->addDockWidget(dockArea, _dockWidget.get());
|
||||||
_dockedWindow = docked;
|
|
||||||
} 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
|
||||||
|
@ -188,10 +187,10 @@ InteractiveWindow::~InteractiveWindow() {
|
||||||
|
|
||||||
void InteractiveWindow::sendToQml(const QVariant& message) {
|
void InteractiveWindow::sendToQml(const QVariant& message) {
|
||||||
// Forward messages received from the script on to QML
|
// Forward messages received from the script on to QML
|
||||||
if (_dockedWindow) {
|
if (_dockWidget) {
|
||||||
QQuickItem* rootItem = _dockWidget->getRootItem();
|
QQuickItem* rootItem = _dockWidget->getRootItem();
|
||||||
if (rootItem) {
|
if (rootItem) {
|
||||||
QMetaObject::invokeMethod(_qmlWindow, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
QMetaObject::invokeMethod(rootItem, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QMetaObject::invokeMethod(_qmlWindow, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
QMetaObject::invokeMethod(_qmlWindow, "fromScript", Qt::QueuedConnection, Q_ARG(QVariant, message));
|
||||||
|
|
|
@ -203,7 +203,6 @@ protected slots:
|
||||||
void qmlToScript(const QVariant& message);
|
void qmlToScript(const QVariant& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool _dockedWindow { false };
|
|
||||||
QPointer<QObject> _qmlWindow;
|
QPointer<QObject> _qmlWindow;
|
||||||
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
std::shared_ptr<DockWidget> _dockWidget { nullptr };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue