diff --git a/framework/uicomponents/qml/Muse/UiComponents/windowview.cpp b/framework/uicomponents/qml/Muse/UiComponents/windowview.cpp index a718a68f17..6dcadd8f20 100644 --- a/framework/uicomponents/qml/Muse/UiComponents/windowview.cpp +++ b/framework/uicomponents/qml/Muse/UiComponents/windowview.cpp @@ -59,6 +59,8 @@ void WindowView::init() }); navigationController()->navigationChanged().onNotify(this, [this]() { + updateNavigationParentControl(); + if (!(m_focusPolicies & FocusPolicy::TabFocus)) { return; } @@ -528,23 +530,44 @@ void WindowView::setNavigationParentControl(ui::INavigationControl* navigationPa return; } + QObject* oldCtrl = dynamic_cast(m_navigationParentControl); + + if (oldCtrl) { + disconnect(oldCtrl, &QObject::destroyed, this, nullptr); + } + m_navigationParentControl = navigationParentControl; + + //! NOTE At the moment we have only qml navigation controls + QObject* qmlCtrl = dynamic_cast(navigationParentControl); + + if (qmlCtrl) { + connect(qmlCtrl, &QObject::destroyed, this, [this]() { + m_navigationParentControl = nullptr; + emit navigationParentControlChanged(nullptr); + }); + } + emit navigationParentControlChanged(m_navigationParentControl); } void WindowView::resolveNavigationParentControl() { - ui::INavigationControl* ctrl = navigationController()->activeControl(); - setNavigationParentControl(ctrl); + setNavigationParentControl(navigationController()->activeControl()); +} - //! NOTE At the moment we have only qml navigation controls - QObject* qmlCtrl = dynamic_cast(ctrl); +void WindowView::updateNavigationParentControl() +{ + if (!isOpened() || !m_parentWindow) { + return; + } - if (qmlCtrl) { - connect(qmlCtrl, &QObject::destroyed, this, [this]() { - setNavigationParentControl(nullptr); - }); + ui::INavigationControl* activeControl = navigationController()->activeControl(); + if (!activeControl || activeControl->window() != m_parentWindow) { + return; } + + setNavigationParentControl(activeControl); } void WindowView::activateNavigationParentControl() diff --git a/framework/uicomponents/qml/Muse/UiComponents/windowview.h b/framework/uicomponents/qml/Muse/UiComponents/windowview.h index 3b525925b7..808e7ca62f 100644 --- a/framework/uicomponents/qml/Muse/UiComponents/windowview.h +++ b/framework/uicomponents/qml/Muse/UiComponents/windowview.h @@ -194,6 +194,7 @@ public slots: void updateSize(const QSize& newSize); void resolveNavigationParentControl(); + void updateNavigationParentControl(); void activateNavigationParentControl(); QQmlEngine* m_engine = nullptr;