SGL
gradiobutton.h
1 /*
2  * File: gradiobutton.h
3  * --------------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/03
7  * - removed dependency on custom collections
8  * @version 2019/04/23
9  * - added key event support
10  * @version 2018/10/06
11  * - added toggle()
12  * @version 2018/09/08
13  * - added doc comments for new documentation generation
14  * @version 2018/09/04
15  * - added double-click event support
16  * @version 2018/08/23
17  * - renamed to gradiobutton.h to replace Java version
18  * @version 2018/06/29
19  * - added change event
20  * @version 2018/06/25
21  * - initial version
22  */
23 
24 
25 #ifndef _gradiobutton_h
26 #define _gradiobutton_h
27 
28 #include <map>
29 #include <string>
30 #include <QButtonGroup>
31 #include <QRadioButton>
32 
33 #include "ginteractor.h"
34 
35 class _Internal_QRadioButton;
36 
48 class GRadioButton : public GInteractor {
49 public:
57  GRadioButton(const string& text = "", const string& group = "default", bool checked = false, QWidget* parent = nullptr);
58 
62  ~GRadioButton() override;
63 
64  /* @inherit */
65  string getActionCommand() const override;
66 
67  /* @inherit */
68  _Internal_QWidget* getInternalWidget() const override;
69 
73  virtual string getText() const;
74 
75  /* @inherit */
76  string getType() const override;
77 
78  /* @inherit */
79  QWidget* getWidget() const override;
80 
85  virtual bool isChecked() const;
86 
91  virtual bool isSelected() const;
92 
97  virtual void setChecked(bool checked);
98 
103  virtual void setSelected(bool selected);
104 
108  virtual void setText(const string& text);
109 
114  virtual void toggle();
115 
116 protected:
120  string getActionEventType() const override;
121 
122 private:
123  Q_DISABLE_COPY(GRadioButton)
124 
125  static std::map<string, QButtonGroup*> _buttonGroups;
126  static QButtonGroup* getButtonGroup(const string& group);
127 
128  _Internal_QRadioButton* _iqradioButton;
129 
130  friend class _Internal_QRadioButton;
131 };
132 
133 
138 class _Internal_QRadioButton : public QRadioButton, public _Internal_QWidget {
139  Q_OBJECT
140 
141 public:
142  _Internal_QRadioButton(GRadioButton* gradioButton, bool checked = false, QWidget* parent = nullptr);
143  void detach() override;
144  void keyPressEvent(QKeyEvent* event) override;
145  void keyReleaseEvent(QKeyEvent* event) override;
146  QSize sizeHint() const override;
147 
148 signals:
149  void doubleClicked();
150 
151 public slots:
152  void handleClick();
153 
154 protected:
155  void mouseDoubleClickEvent(QMouseEvent* e) override;
156 
157 private:
158  GRadioButton* _gradioButton;
159 
160  friend class GRadioButton;
161 };
162 
163 #endif // _gradiobutton_h
virtual string getText() const
Returns the text next to the radio button.
Definition: gradiobutton.cpp:61
virtual bool isSelected() const
Returns true if the radio button is currently checked.
Definition: gradiobutton.cpp:77
virtual void setText(string text)
Sets the text that will appear next to the radio button.
Definition: gradiobutton.cpp:91
GRadioButton(string text="", string group="default", bool checked=false, QWidget* parent=nullptr)
Creates a new radio button with the given text.
Definition: gradiobutton.cpp:29
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:97
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gradiobutton.cpp:69
This interactor subclass represents an onscreen radio button.
Definition: gradiobutton.h:48
virtual bool isChecked() const
Returns true if the radio button is currently checked.
Definition: gradiobutton.cpp:73
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:45
virtual void setSelected(bool selected)
Sets whether the radio button should be checked.
Definition: gradiobutton.cpp:87
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gradiobutton.cpp:57
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:48
virtual void setChecked(bool checked)
Sets whether the radio button should be checked.
Definition: gradiobutton.cpp:81
~GRadioButton() override
Frees memory allocated internally by the radio button.
Definition: gradiobutton.cpp:39
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gradiobutton.cpp:65