diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-09-18 10:24:36 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-09-18 20:01:45 +0200 |
commit | 10590d4f1f072630238a1e62fe48afb20ab41644 (patch) | |
tree | e29d0ee9d460c50487c83459b58c31d620664125 /vcl | |
parent | 9b3a2996e710fee11145dcbbe38a6f1e6f646ec8 (diff) |
tdf#130857 qt weld: Move logic to find native Qt parent to helper
Move the logic to find a QWidget parent mostly introduced
in
commit 1e2836665a1839f61cd8bfa46c54687f010e7e9d
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Fri Aug 30 18:17:53 2024 +0200
tdf#162696 tdf#130857 qt weld: Get parent via SalInstanceWidget
to a helper method, for reuse in `QtInstance::CreateBuilder`
in an upcoming commit.
Change-Id: Ied41e7f5054f08382668292042f2a9978c6bed91
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173593
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/qt5/QtInstance.hxx | 2 | ||||
-rw-r--r-- | vcl/qt5/QtInstance.cxx | 43 |
2 files changed, 24 insertions, 21 deletions
diff --git a/vcl/inc/qt5/QtInstance.hxx b/vcl/inc/qt5/QtInstance.hxx index df4a5eeaf26a..f82def9c830c 100644 --- a/vcl/inc/qt5/QtInstance.hxx +++ b/vcl/inc/qt5/QtInstance.hxx @@ -74,6 +74,8 @@ class VCLPLUG_QT_PUBLIC QtInstance : public QObject, DECL_DLLPRIVATE_LINK(updateStyleHdl, Timer*, void); void AfterAppInit() override; + static QWidget* GetNativeParentFromWeldParent(weld::Widget* pParent); + private Q_SLOTS: bool ImplYield(bool bWait, bool bHandleAllCurrentEvents); static void deleteObjectLater(QObject* pObject); diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx index da28848d1520..fbfc06ac61ee 100644 --- a/vcl/qt5/QtInstance.cxx +++ b/vcl/qt5/QtInstance.cxx @@ -798,6 +798,27 @@ void QtInstance::setActivePopup(QtFrame* pFrame) m_pActivePopup = pFrame; } +QWidget* QtInstance::GetNativeParentFromWeldParent(weld::Widget* pParent) +{ + if (!pParent) + return nullptr; + + if (QtInstanceWidget* pQtInstanceWidget = dynamic_cast<QtInstanceWidget*>(pParent)) + return pQtInstanceWidget->getQWidget(); + + // the parent is not welded/not a native Qt widget; get QWidget via frame + if (SalInstanceWidget* pSalWidget = dynamic_cast<SalInstanceWidget*>(pParent)) + { + if (vcl::Window* pWindow = pSalWidget->getWidget()) + { + if (QtFrame* pFrame = static_cast<QtFrame*>(pWindow->ImplGetFrame())) + return pFrame->GetQWidget(); + } + } + + return nullptr; +} + std::unique_ptr<weld::Builder> QtInstance::CreateBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile) { @@ -829,27 +850,7 @@ weld::MessageDialog* QtInstance::CreateMessageDialog(weld::Widget* pParent, } else { - QWidget* pQtParent = nullptr; - if (pParent) - { - if (QtInstanceWidget* pQtInstanceWidget = dynamic_cast<QtInstanceWidget*>(pParent)) - { - pQtParent = pQtInstanceWidget->getQWidget(); - } - else - { - // the parent is not welded/not a native Qt widget; get QWidget via frame - if (SalInstanceWidget* pSalWidget = dynamic_cast<SalInstanceWidget*>(pParent)) - { - if (vcl::Window* pWindow = pSalWidget->getWidget()) - { - if (QtFrame* pFrame = static_cast<QtFrame*>(pWindow->ImplGetFrame())) - pQtParent = pFrame->GetQWidget(); - } - } - } - } - + QWidget* pQtParent = GetNativeParentFromWeldParent(pParent); QMessageBox* pMessageBox = new QMessageBox(pQtParent); pMessageBox->setText(toQString(rPrimaryMessage)); pMessageBox->setIcon(vclMessageTypeToQtIcon(eMessageType)); |