Skip to content

Commit 37553a6

Browse files
committed
automatically activate focus when activating navigation inside a popup
1 parent ad5122e commit 37553a6

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

src/framework/uicomponents/view/popupview.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,17 @@ void PopupView::init()
150150
}
151151
});
152152

153+
navigationController()->navigationChanged().onNotify(this, [this]() {
154+
ui::INavigationPanel* navigationPanel = navigationController()->activePanel();
155+
if (!navigationPanel) {
156+
return;
157+
}
158+
159+
if (navigationPanel->window() == m_window->qWindow() && !m_window->hasActiveFocus()) {
160+
m_window->forceActiveFocus();
161+
}
162+
});
163+
153164
emit windowChanged();
154165
}
155166

src/framework/uicomponents/view/popupview.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class PopupView : public QObject, public QQmlParserStatus, public Injectable, pu
9393
public:
9494
Inject<ui::IMainWindow> mainWindow = { this };
9595
Inject<ui::IUiConfiguration> uiConfiguration = { this };
96-
Inject<ui::INavigationController> navigationController= { this };
96+
Inject<ui::INavigationController> navigationController = { this };
9797

9898
public:
9999

src/framework/uicomponents/view/popupwindow/ipopupwindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class IPopupWindow : public QObject
6161

6262
virtual void setPosition(const QPoint& position) const = 0;
6363

64+
virtual bool hasActiveFocus() const = 0;
6465
virtual void forceActiveFocus() = 0;
6566

6667
virtual void setOnHidden(const std::function<void()>& callback) = 0;

src/framework/uicomponents/view/popupwindow/popupwindow_qquickview.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,11 @@ void PopupWindow_QQuickView::setPosition(const QPoint& position) const
247247
m_view->setPosition(position);
248248
}
249249

250+
bool PopupWindow_QQuickView::hasActiveFocus() const
251+
{
252+
return m_view && m_view->activeFocusItem() != nullptr;
253+
}
254+
250255
void PopupWindow_QQuickView::setOnHidden(const std::function<void()>& callback)
251256
{
252257
m_onHidden = callback;

src/framework/uicomponents/view/popupwindow/popupwindow_qquickview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class PopupWindow_QQuickView : public IPopupWindow, public muse::Injectable, pub
6868

6969
void setPosition(const QPoint& position) const override;
7070

71+
bool hasActiveFocus() const override;
7172
void forceActiveFocus() override;
7273

7374
void setOnHidden(const std::function<void()>& callback) override;

0 commit comments

Comments
 (0)