Skip to content

Commit

Permalink
automatically activate focus when activating navigation inside a popup
Browse files Browse the repository at this point in the history
  • Loading branch information
Eism committed Jan 21, 2025
1 parent ad5122e commit 37553a6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/framework/uicomponents/view/popupview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,17 @@ void PopupView::init()
}
});

navigationController()->navigationChanged().onNotify(this, [this]() {
ui::INavigationPanel* navigationPanel = navigationController()->activePanel();
if (!navigationPanel) {
return;
}

if (navigationPanel->window() == m_window->qWindow() && !m_window->hasActiveFocus()) {
m_window->forceActiveFocus();
}
});

emit windowChanged();
}

Expand Down
2 changes: 1 addition & 1 deletion src/framework/uicomponents/view/popupview.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class PopupView : public QObject, public QQmlParserStatus, public Injectable, pu
public:
Inject<ui::IMainWindow> mainWindow = { this };
Inject<ui::IUiConfiguration> uiConfiguration = { this };
Inject<ui::INavigationController> navigationController= { this };
Inject<ui::INavigationController> navigationController = { this };

public:

Expand Down
1 change: 1 addition & 0 deletions src/framework/uicomponents/view/popupwindow/ipopupwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class IPopupWindow : public QObject

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

virtual bool hasActiveFocus() const = 0;
virtual void forceActiveFocus() = 0;

virtual void setOnHidden(const std::function<void()>& callback) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,11 @@ void PopupWindow_QQuickView::setPosition(const QPoint& position) const
m_view->setPosition(position);
}

bool PopupWindow_QQuickView::hasActiveFocus() const
{
return m_view && m_view->activeFocusItem() != nullptr;
}

void PopupWindow_QQuickView::setOnHidden(const std::function<void()>& callback)
{
m_onHidden = callback;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PopupWindow_QQuickView : public IPopupWindow, public muse::Injectable, pub

void setPosition(const QPoint& position) const override;

bool hasActiveFocus() const override;
void forceActiveFocus() override;

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

0 comments on commit 37553a6

Please sign in to comment.