1 /* === This file is part of Calamares - <https://calamares.io> === 2 * 3 * SPDX-FileCopyrightText: 2014 Teo Mrnjavac <teo@kde.org> 4 * SPDX-License-Identifier: GPL-3.0-or-later 5 * 6 * Calamares is Free Software: see the License-Identifier above. 7 * 8 */ 9 10 #ifndef LIBCALAMARESUI_PRETTYRADIOBUTTON_H 11 #define LIBCALAMARESUI_PRETTYRADIOBUTTON_H 12 13 #include "DllMacro.h" 14 15 #include <QRadioButton> 16 17 class QButtonGroup; 18 class QComboBox; 19 class QGridLayout; 20 class QHBoxLayout; 21 22 namespace Calamares 23 { 24 class ClickableLabel; 25 26 /** @brief A radio button with fancy label next to it. 27 * 28 * The fancy label is used so that the text alongside the radio 29 * button can word-wrap, be multi-line, and support rich text. 30 * 31 * The radio button itself can be retrieved with buttonWidget(), 32 * and the whole behaves a lot like a label. Extra options can be 33 * added to the display (options are hidden when the button is 34 * not selected) with addOptionsComboBox(). 35 */ 36 class UIDLLEXPORT PrettyRadioButton : public QWidget 37 { 38 Q_OBJECT 39 public: 40 explicit PrettyRadioButton( QWidget* parent = nullptr ); ~PrettyRadioButton()41 ~PrettyRadioButton() override {} 42 43 /// @brief Passes @p text on to the ClickableLabel 44 void setText( const QString& text ); 45 46 // Icon applies to the radio-button part 47 void setIconSize( const QSize& size ); 48 QSize iconSize() const; 49 void setIcon( const QIcon& icon ); 50 51 // Applies to the radio-button part 52 void setChecked( bool checked ); 53 bool isChecked() const; 54 55 /** @brief Adds the radio-button part to the given @p group 56 * 57 * For managing the pretty-radio-button in button groups like normal 58 * radio buttons, call addToGroup() rather that group->addButton(). 59 */ 60 void addToGroup( QButtonGroup* group, int id = -1 ); 61 62 /// @brief Add an options drop-down to this button. 63 void addOptionsComboBox( QComboBox* ); 64 65 protected slots: 66 /// Options are hidden when the radio button is off 67 void toggleOptions( bool checked ); 68 69 protected: 70 ClickableLabel* m_label; 71 QRadioButton* m_radio; 72 QGridLayout* m_mainLayout; 73 QHBoxLayout* m_optionsLayout; 74 }; 75 76 } // namespace Calamares 77 #endif // LIBCALAMARESUI_PRETTYRADIOBUTTON_H 78