From 17231ae41f5c5ba8d08618ab2d1f83ed868508b9 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 18 May 2020 11:17:36 +0200 Subject: [PATCH] [libcalamaresui] Sanitize API of PrettyRadioButton - Don't expose internals - Drop unnecessary virtual - Offer new API to do the things, for which internals were exposed --- .../widgets/PrettyRadioButton.cpp | 21 ++++++++++++--- .../widgets/PrettyRadioButton.h | 27 ++++++++++++++----- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/libcalamaresui/widgets/PrettyRadioButton.cpp b/src/libcalamaresui/widgets/PrettyRadioButton.cpp index 31b74e9e2..1cf348315 100644 --- a/src/libcalamaresui/widgets/PrettyRadioButton.cpp +++ b/src/libcalamaresui/widgets/PrettyRadioButton.cpp @@ -21,6 +21,7 @@ #include "utils/CalamaresUtilsGui.h" #include "widgets/ClickableLabel.h" +#include #include #include #include @@ -80,12 +81,26 @@ PrettyRadioButton::iconSize() const } -QRadioButton* -PrettyRadioButton::buttonWidget() const +void +PrettyRadioButton::setChecked( bool checked ) { - return m_radio; + m_radio->setChecked( checked ); } + +bool +PrettyRadioButton::isChecked() const +{ + return m_radio->isChecked(); +} + +void +PrettyRadioButton::addToGroup( QButtonGroup* group, int id ) +{ + group->addButton( m_radio, id ); +} + + void PrettyRadioButton::addOptionsComboBox( QComboBox* box ) { diff --git a/src/libcalamaresui/widgets/PrettyRadioButton.h b/src/libcalamaresui/widgets/PrettyRadioButton.h index dbaa88707..9c7139526 100644 --- a/src/libcalamaresui/widgets/PrettyRadioButton.h +++ b/src/libcalamaresui/widgets/PrettyRadioButton.h @@ -23,6 +23,7 @@ #include +class QButtonGroup; class QComboBox; class QGridLayout; class QHBoxLayout; @@ -32,6 +33,9 @@ namespace Calamares class ClickableLabel; /** @brief A radio button with fancy label next to it. + * + * The fancy label is used so that the text alongside the radio + * button can word-wrap, be multi-line, and support rich text. * * The radio button itself can be retrieved with buttonWidget(), * and the whole behaves a lot like a label. Extra options can be @@ -45,17 +49,26 @@ public: explicit PrettyRadioButton( QWidget* parent = nullptr ); virtual ~PrettyRadioButton() { } - virtual void setText( const QString& text ); + /// @brief Passes @p text on to the ClickableLabel + void setText( const QString& text ); - virtual void setIconSize( const QSize& size ); + // Icon applies to the radio-button part + void setIconSize( const QSize& size ); + QSize iconSize() const; + void setIcon( const QIcon& icon ); - virtual void setIcon( const QIcon& icon ); + // Applies to the radio-button part + void setChecked( bool checked ); + bool isChecked() const; - virtual QSize iconSize() const; + /** @brief Adds the radio-button part to the given @p group + * + * For managing the pretty-radio-button in button groups like normal + * radio buttons, call addToGroup() rather that group->addButton(). + */ + void addToGroup( QButtonGroup* group, int id = -1 ); - virtual QRadioButton* buttonWidget() const; - - /** @brief Add an options drop-down to this button. */ + /// @brief Add an options drop-down to this button. void addOptionsComboBox( QComboBox* ); protected slots: