From 32c5e18db0e75833e9ad599694edc0d040c9ae22 Mon Sep 17 00:00:00 2001 From: Artem Grinev Date: Mon, 6 Dec 2021 02:26:13 +0400 Subject: [PATCH] [libcalamaresui] Add QDialogButtonBox translation fix --- src/libcalamaresui/widgets/TranslationFix.cpp | 35 +++++++++++++------ src/libcalamaresui/widgets/TranslationFix.h | 3 ++ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/widgets/TranslationFix.cpp b/src/libcalamaresui/widgets/TranslationFix.cpp index 1262fceb5..b73bd0e16 100644 --- a/src/libcalamaresui/widgets/TranslationFix.cpp +++ b/src/libcalamaresui/widgets/TranslationFix.cpp @@ -10,21 +10,16 @@ #include "TranslationFix.h" #include +#include #include #include +#include namespace Calamares { -void -fixButtonLabels( QMessageBox* box ) -{ - if ( !box ) - { - return; - } - - static std::pair< decltype( QMessageBox::Ok ), const char* > maps[] = { +//Using QMessageBox's StandardButton enum here but according to headers they should be kept in-sync between multiple classes. +static std::pair< decltype( QMessageBox::Ok ), const char* > maps[] = { { QMessageBox::Ok, QT_TRANSLATE_NOOP( "StandardButtons", "&OK" ) }, { QMessageBox::Yes, QT_TRANSLATE_NOOP( "StandardButtons", "&Yes" ) }, { QMessageBox::No, QT_TRANSLATE_NOOP( "StandardButtons", "&No" ) }, @@ -32,9 +27,17 @@ fixButtonLabels( QMessageBox* box ) { QMessageBox::Close, QT_TRANSLATE_NOOP( "StandardButtons", "&Close" ) }, }; +template +void fixButtonLabels ( TButtonBox* box ) +{ + if ( !box ) + { + return; + } + for ( auto [ sb, label ] : maps ) { - auto* button = box->button( sb ); + auto* button = box->button( static_cast(int(sb)) ); if ( button ) { button->setText( QCoreApplication::translate( "StandardButtons", label ) ); @@ -42,4 +45,16 @@ fixButtonLabels( QMessageBox* box ) } } +void +fixButtonLabels( QMessageBox* box ) +{ + fixButtonLabels(box); +} + +void +fixButtonLabels(QDialogButtonBox *box) +{ + fixButtonLabels(box); +} + } // namespace Calamares diff --git a/src/libcalamaresui/widgets/TranslationFix.h b/src/libcalamaresui/widgets/TranslationFix.h index 107dad67d..89ee9a51a 100644 --- a/src/libcalamaresui/widgets/TranslationFix.h +++ b/src/libcalamaresui/widgets/TranslationFix.h @@ -13,6 +13,7 @@ #include "DllMacro.h" class QMessageBox; +class QDialogButtonBox; namespace Calamares { @@ -26,6 +27,8 @@ namespace Calamares * guess the context. */ void UIDLLEXPORT fixButtonLabels( QMessageBox* ); + +void UIDLLEXPORT fixButtonLabels( QDialogButtonBox* ); } // namespace Calamares #endif