SGL
gradiobutton.h
1 /*
2  * File: gradiobutton.h
3  * --------------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2021/04/03
9  * - removed dependency on custom collections
10  * @version 2019/04/23
11  * - added key event support
12  * @version 2018/10/06
13  * - added toggle()
14  * @version 2018/09/08
15  * - added doc comments for new documentation generation
16  * @version 2018/09/04
17  * - added double-click event support
18  * @version 2018/08/23
19  * - renamed to gradiobutton.h to replace Java version
20  * @version 2018/06/29
21  * - added change event
22  * @version 2018/06/25
23  * - initial version
24  */
25 
26 
27 #ifndef _gradiobutton_h
28 #define _gradiobutton_h
29 
30 #include <map>
31 #include <string>
32 #include <QButtonGroup>
33 #include <QRadioButton>
34 
35 #include "ginteractor.h"
36 
37 namespace sgl {
38 
39 class _Internal_QRadioButton;
40 
52 class GRadioButton : public GInteractor {
53 public:
61  GRadioButton(const string& text = "", const string& group = "default", bool checked = false, QWidget* parent = nullptr);
62 
66  ~GRadioButton() override;
67 
68  /* @inherit */
69  string getActionCommand() const override;
70 
71  /* @inherit */
72  _Internal_QWidget* getInternalWidget() const override;
73 
77  virtual string getText() const;
78 
79  /* @inherit */
80  string getType() const override;
81 
82  /* @inherit */
83  QWidget* getWidget() const override;
84 
89  virtual bool isChecked() const;
90 
95  virtual bool isSelected() const;
96 
101  virtual void setChecked(bool checked);
102 
107  virtual void setSelected(bool selected);
108 
112  virtual void setText(const string& text);
113 
118  virtual void toggle();
119 
120 protected:
124  string getActionEventType() const override;
125 
126 private:
127  Q_DISABLE_COPY(GRadioButton)
128 
129  static std::map<string, QButtonGroup*> _buttonGroups;
130  static QButtonGroup* getButtonGroup(const string& group);
131 
132  _Internal_QRadioButton* _iqradioButton;
133 
134  friend class _Internal_QRadioButton;
135 };
136 
137 
142 class _Internal_QRadioButton : public QRadioButton, public _Internal_QWidget {
143  Q_OBJECT
144 
145 public:
146  _Internal_QRadioButton(GRadioButton* gradioButton, bool checked = false, QWidget* parent = nullptr);
147  void detach() override;
148  void keyPressEvent(QKeyEvent* event) override;
149  void keyReleaseEvent(QKeyEvent* event) override;
150  QSize sizeHint() const override;
151 
152 signals:
153  void doubleClicked();
154 
155 public slots:
156  void handleClick();
157 
158 protected:
159  void mouseDoubleClickEvent(QMouseEvent* e) override;
160 
161 private:
162  GRadioButton* _gradioButton;
163 
164  friend class GRadioButton;
165 };
166 
167 } // namespace sgl
168 
169 #endif // _gradiobutton_h
virtual bool isChecked() const
Returns true if the radio button is currently checked.
Definition: gradiobutton.cpp:77
virtual string getText() const
Returns the text next to the radio button.
Definition: gradiobutton.cpp:65
GRadioButton(string text="", string group="default", bool checked=false, QWidget* parent=nullptr)
Creates a new radio button with the given text.
Definition: gradiobutton.cpp:33
This interactor subclass represents an onscreen radio button.
Definition: gradiobutton.h:52
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gradiobutton.cpp:73
virtual void toggle()
Reverses the checked state of the button, setting it to be checked if it was unchecked or to be unche...
Definition: gradiobutton.cpp:101
virtual bool isSelected() const
Returns true if the radio button is currently checked.
Definition: gradiobutton.cpp:81
Definition: console.h:45
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gradiobutton.cpp:61
string getActionCommand() const override
Returns an action command for this interactor, which is a semi-unique string you can use to identify ...
Definition: gradiobutton.cpp:49
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gradiobutton.cpp:69
virtual void setSelected(bool selected)
Sets whether the radio button should be checked.
Definition: gradiobutton.cpp:91
virtual void setChecked(bool checked)
Sets whether the radio button should be checked.
Definition: gradiobutton.cpp:85
~GRadioButton() override
Frees memory allocated internally by the radio button.
Definition: gradiobutton.cpp:43
virtual void setText(string text)
Sets the text that will appear next to the radio button.
Definition: gradiobutton.cpp:95