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  <omkaracharekar12@gmail.com>
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
This commit is contained in:
Michael Weghorn 2024-01-25 09:20:41 +01:00
parent f921a66d31
commit c038b4fd16
3 changed files with 32 additions and 32 deletions

View file

@ -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

View file

@ -52,6 +52,7 @@
#include <tools/debug.hxx>
#include <comphelper/flagguard.hxx>
#include <dndhelper.hxx>
#include <vcl/stdtext.hxx>
#include <vcl/sysdata.hxx>
#include <sal/log.hxx>
#include <osl/process.h>
@ -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;
}
}

View file

@ -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)