From c038b4fd162abb780ab0f9bcafb1421c5ec5786e Mon Sep 17 00:00:00 2001 From: Michael Weghorn Date: Thu, 25 Jan 2024 09:20:41 +0100 Subject: [PATCH] tdf#159323 qt weld: Set standard buttons via weld API Instead of mapping the `VclButtonsType` to the corresponding `QMessageBox::StandardButtons` and using that to set the standard buttons for the `QMessageBox` using `QMessageBox::setStandardButtons`, use `weld::MessageDialog::add_button` to add all of the buttons manually, using their standard button texts. While the former is somewhat nicer, it depends on the ability to map between the VCL response code and a `QMessageBox::ButtonRole`. While there is currently a mapping in place (s. `lcl_vclResponseTypeToQtMessageBoxButtonRole` and `lcl_qtMessageBoxButtonRoleToVclResponseType`), this turned out to not be sufficient, since the VCL return code cannot only be one of the enum values in `VclResponseType` (which are currently handled) but any int. This commit is in preparation of an upcoming one that will replace the current mapping to support arbitrary int response codes. Change-Id: Icca68f2ccec182f8ff6ae3c64680a4d28bd687d0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162559 Tested-by: Jenkins Reviewed-by: Omkar Acharekar Reviewed-by: Michael Weghorn --- vcl/inc/qt5/QtTools.hxx | 1 - vcl/qt5/QtInstance.cxx | 34 ++++++++++++++++++++++++++++++++-- vcl/qt5/QtTools.cxx | 29 ----------------------------- 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/vcl/inc/qt5/QtTools.hxx b/vcl/inc/qt5/QtTools.hxx index b419c1fd3da9..bc4a12d483a2 100644 --- a/vcl/inc/qt5/QtTools.hxx +++ b/vcl/inc/qt5/QtTools.hxx @@ -155,7 +155,6 @@ QImage toQImage(const Image& rImage); QMessageBox::Icon vclMessageTypeToQtIcon(VclMessageType eType); QString vclMessageTypeToQtTitle(VclMessageType eType); -QMessageBox::StandardButtons vclButtonsTypeToQtButton(VclButtonsType eButtonType); int qtResponseTypeToVclResponseType(int ret); /** Converts a string potentially containing a '~' character to indicate an accelerator diff --git a/vcl/qt5/QtInstance.cxx b/vcl/qt5/QtInstance.cxx index 718279f51496..43af2541a7ce 100644 --- a/vcl/qt5/QtInstance.cxx +++ b/vcl/qt5/QtInstance.cxx @@ -52,6 +52,7 @@ #include #include #include +#include #include #include #include @@ -99,6 +100,34 @@ public: virtual void doAcquire(sal_uInt32 nLockCount) override; virtual sal_uInt32 doRelease(bool const bUnlockAll) override; }; + +void lcl_setStandardButtons(QtInstanceMessageDialog& rMessageDialog, VclButtonsType eButtonType) +{ + switch (eButtonType) + { + case VclButtonsType::NONE: + break; + case VclButtonsType::Ok: + rMessageDialog.add_button(GetStandardText(StandardButtonType::OK), RET_OK); + break; + case VclButtonsType::Close: + rMessageDialog.add_button(GetStandardText(StandardButtonType::Close), RET_CLOSE); + break; + case VclButtonsType::Cancel: + rMessageDialog.add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL); + break; + case VclButtonsType::YesNo: + rMessageDialog.add_button(GetStandardText(StandardButtonType::Yes), RET_YES); + rMessageDialog.add_button(GetStandardText(StandardButtonType::No), RET_NO); + break; + case VclButtonsType::OkCancel: + rMessageDialog.add_button(GetStandardText(StandardButtonType::OK), RET_OK); + rMessageDialog.add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL); + break; + default: + assert(false && "Unhandled VCLButtonsType"); + } +} } bool QtYieldMutex::IsCurrentThread() const @@ -767,8 +796,9 @@ weld::MessageDialog* QtInstance::CreateMessageDialog(weld::Widget* pParent, pMessageBox->setText(toQString(rPrimaryMessage)); pMessageBox->setIcon(vclMessageTypeToQtIcon(eMessageType)); pMessageBox->setWindowTitle(vclMessageTypeToQtTitle(eMessageType)); - pMessageBox->setStandardButtons(vclButtonsTypeToQtButton(eButtonsType)); - return new QtInstanceMessageDialog(pMessageBox); + QtInstanceMessageDialog* pDialog = new QtInstanceMessageDialog(pMessageBox); + lcl_setStandardButtons(*pDialog, eButtonsType); + return pDialog; } } diff --git a/vcl/qt5/QtTools.cxx b/vcl/qt5/QtTools.cxx index e4000f9a99c1..f9ca85137754 100644 --- a/vcl/qt5/QtTools.cxx +++ b/vcl/qt5/QtTools.cxx @@ -170,35 +170,6 @@ QString vclMessageTypeToQtTitle(VclMessageType eType) return title; } -QMessageBox::StandardButtons vclButtonsTypeToQtButton(VclButtonsType eButtonType) -{ - QMessageBox::StandardButtons buttons = QMessageBox::NoButton; - switch (eButtonType) - { - case VclButtonsType::NONE: - buttons = QMessageBox::NoButton; - break; - case VclButtonsType::Ok: - buttons = QMessageBox::Ok; - break; - case VclButtonsType::Close: - buttons = QMessageBox::Close; - break; - case VclButtonsType::Cancel: - buttons = QMessageBox::Cancel; - break; - case VclButtonsType::YesNo: - buttons = QMessageBox::Yes | QMessageBox::No; - break; - case VclButtonsType::OkCancel: - buttons = QMessageBox::Ok | QMessageBox::Cancel; - break; - default: - assert(false && "Unhandled VCLButtonsType"); - } - return buttons; -} - int qtResponseTypeToVclResponseType(int ret) { if (ret == QDialog::Accepted)