vcl/inc/qt5/QtInstanceWidget.hxx | 2 +- vcl/qt5/QtInstanceWidget.cxx | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 6 deletions(-)
New commits: commit f9fccb9023a2610480dde60d570d2b3f3169de57 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Aug 6 18:10:28 2024 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Wed Aug 7 07:12:10 2024 +0200 tdf#130857 qt weld: Implement QtInstanceWidget::has_child_focus Change-Id: I97ac73943969ecb8f1f189adc1cf4b5c4b052fd1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171558 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx index bdeb1bf83f3a..f5f359b536c3 100644 --- a/vcl/qt5/QtInstanceWidget.cxx +++ b/vcl/qt5/QtInstanceWidget.cxx @@ -65,7 +65,20 @@ bool QtInstanceWidget::has_focus() const bool QtInstanceWidget::is_active() const { return has_focus(); } -bool QtInstanceWidget::has_child_focus() const { return true; } +bool QtInstanceWidget::has_child_focus() const +{ + QWidget* pFocusWidget = QApplication::focusWidget(); + if (!pFocusWidget) + return false; + + QWidget* pParent = pFocusWidget->parentWidget(); + while (pParent) + { + if (pParent == m_pWidget) + return true; + } + return false; +} void QtInstanceWidget::show() {} commit 70b6d20e930453a963118744c747fb08935a86ee Author: Michael Weghorn <[email protected]> AuthorDate: Tue Aug 6 18:00:27 2024 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Wed Aug 7 07:12:03 2024 +0200 tdf#130857 qt weld: Implement QtInstanceWidget::is_active For now, let it be the same as `QtInstanceWidget::has_focus` as there seems to be no direct equivalent, and the comment in weld.hxx also questions whether there is much value in having two different methods: // return if this widget has the keyboard focus within the active window // TODO: review if this has any practical difference from has_focus() virtual bool is_active() const = 0; Change-Id: If90377d734a6c721c369a2d206c0e6122ac61853 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171557 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx index 34dd3b611c74..bdeb1bf83f3a 100644 --- a/vcl/qt5/QtInstanceWidget.cxx +++ b/vcl/qt5/QtInstanceWidget.cxx @@ -63,7 +63,7 @@ bool QtInstanceWidget::has_focus() const return m_pWidget->hasFocus(); } -bool QtInstanceWidget::is_active() const { return true; } +bool QtInstanceWidget::is_active() const { return has_focus(); } bool QtInstanceWidget::has_child_focus() const { return true; } commit fcb6b33eafdc756d2c821a58c0e8cdc1f4cc352c Author: Michael Weghorn <[email protected]> AuthorDate: Tue Aug 6 17:54:45 2024 +0200 Commit: Michael Weghorn <[email protected]> CommitDate: Wed Aug 7 07:11:55 2024 +0200 tdf#130857 qt weld: Implement focus-related methods Change-Id: I064ff205ceb9d008667cf3a3a6e73047ea5ca3e0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171556 Tested-by: Jenkins Reviewed-by: Michael Weghorn <[email protected]> diff --git a/vcl/inc/qt5/QtInstanceWidget.hxx b/vcl/inc/qt5/QtInstanceWidget.hxx index ed0a41ac1c0b..733e3efeffab 100644 --- a/vcl/inc/qt5/QtInstanceWidget.hxx +++ b/vcl/inc/qt5/QtInstanceWidget.hxx @@ -36,7 +36,7 @@ public: virtual bool is_visible() const override; - virtual void set_can_focus(bool) override; + virtual void set_can_focus(bool bCanFocus) override; virtual void grab_focus() override; diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx index 602b278e8eb7..34dd3b611c74 100644 --- a/vcl/qt5/QtInstanceWidget.cxx +++ b/vcl/qt5/QtInstanceWidget.cxx @@ -42,11 +42,26 @@ bool QtInstanceWidget::is_visible() const return m_pWidget->isVisibleTo(pTopLevel) && pTopLevel->isVisible(); } -void QtInstanceWidget::set_can_focus(bool) {} +void QtInstanceWidget::set_can_focus(bool bCanFocus) +{ + assert(m_pWidget); + if (bCanFocus) + m_pWidget->setFocusPolicy(Qt::FocusPolicy::StrongFocus); + else + m_pWidget->setFocusPolicy(Qt::FocusPolicy::NoFocus); +} -void QtInstanceWidget::grab_focus() {} +void QtInstanceWidget::grab_focus() +{ + assert(m_pWidget); + m_pWidget->setFocus(); +} -bool QtInstanceWidget::has_focus() const { return true; } +bool QtInstanceWidget::has_focus() const +{ + assert(m_pWidget); + return m_pWidget->hasFocus(); +} bool QtInstanceWidget::is_active() const { return true; }
