SGL
gcheckbox.h
1 /*
2  * File: gcheckbox.h
3  * -----------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2019/04/23
9  * - added key event support
10  * @version 2018/10/06
11  * - added toggle()
12  * @version 2018/09/07
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 gcheckbox.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 _gcheckbox_h
26 #define _gcheckbox_h
27 
28 #include <string>
29 #include <QCheckBox>
30 
31 #include "ginteractor.h"
32 
33 namespace sgl {
34 
35 class _Internal_QCheckBox;
36 
43 class GCheckBox : public GInteractor {
44 public:
49  GCheckBox(const string& text = "", bool checked = false, QWidget* parent = nullptr);
50 
54  ~GCheckBox() override;
55 
56  /* @inherit */
57  string getActionCommand() const override;
58 
59  /* @inherit */
60  _Internal_QWidget* getInternalWidget() const override;
61 
65  virtual string getText() const;
66 
67  /* @inherit */
68  string getType() const override;
69 
70  /* @inherit */
71  QWidget* getWidget() const override;
72 
77  virtual bool isChecked() const;
78 
83  virtual bool isSelected() const;
84 
89  virtual void setChecked(bool checked);
90 
95  virtual void setSelected(bool selected);
96 
100  virtual void setText(const string& text);
101 
106  virtual void toggle();
107 
108 protected:
112  string getActionEventType() const override;
113 
114 private:
115  Q_DISABLE_COPY(GCheckBox)
116 
117  _Internal_QCheckBox* _iqcheckBox;
118 
119  friend class _Internal_QCheckBox;
120 };
121 
126 class _Internal_QCheckBox : public QCheckBox, public _Internal_QWidget {
127  Q_OBJECT
128 
129 public:
130  _Internal_QCheckBox(GCheckBox* gcheckBox, bool checked = false, QWidget* parent = nullptr);
131  void detach() override;
132  void keyPressEvent(QKeyEvent* event) override;
133  void keyReleaseEvent(QKeyEvent* event) override;
134  QSize sizeHint() const override;
135 
136 signals:
137  void doubleClicked();
138 
139 public slots:
140  void handleStateChange(int);
141 
142 protected:
143  void mouseDoubleClickEvent(QMouseEvent* e) override;
144 
145 private:
146  GCheckBox* _gcheckBox;
147 
148  friend class GCheckBox;
149 };
150 
151 } // namespace sgl
152 
153 #endif // _gcheckbox_h
virtual void setChecked(bool checked)
Sets whether the checkbox should be checked.
Definition: gcheckbox.cpp:79
virtual void setSelected(bool selected)
Sets whether the checkbox should be checked.
Definition: gcheckbox.cpp:85
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gcheckbox.cpp:63
virtual bool isSelected() const
Returns true if the checkbox is currently checked.
Definition: gcheckbox.cpp:75
virtual void setText(string text)
Sets the text that will appear next to the checkbox.
Definition: gcheckbox.cpp:89
virtual bool isChecked() const
Returns true if the checkbox is currently checked.
Definition: gcheckbox.cpp:71
Definition: console.h:45
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gcheckbox.cpp:67
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gcheckbox.cpp:55
string getActionCommand() const override
Returns an action command for this interactor, which is a semi-unique string you can use to identify ...
Definition: gcheckbox.cpp:43
virtual string getText() const
Returns the text next to the checkbox.
Definition: gcheckbox.cpp:59
virtual void toggle()
Reverses the checked state of the box, setting it to be checked if it was unchecked or to be unchecke...
Definition: gcheckbox.cpp:95
~GCheckBox() override
Frees memory allocated internally by the checkbox.
Definition: gcheckbox.cpp:37
This interactor subclass represents an onscreen check box.
Definition: gcheckbox.h:43
GCheckBox(string text="", bool checked=false, QWidget* parent=nullptr)
Creates a checkbox with the given text.
Definition: gcheckbox.cpp:29