SGL
gcheckbox.h
1 /*
2  * File: gcheckbox.h
3  * -----------------
4  *
5  * @author Marty Stepp
6  * @version 2019/04/23
7  * - added key event support
8  * @version 2018/10/06
9  * - added toggle()
10  * @version 2018/09/07
11  * - added doc comments for new documentation generation
12  * @version 2018/09/04
13  * - added double-click event support
14  * @version 2018/08/23
15  * - renamed to gcheckbox.h to replace Java version
16  * @version 2018/06/29
17  * - added change event
18  * @version 2018/06/25
19  * - initial version
20  */
21 
22 
23 #ifndef _gcheckbox_h
24 #define _gcheckbox_h
25 
26 #include <string>
27 #include <QCheckBox>
28 
29 #include "ginteractor.h"
30 
31 class _Internal_QCheckBox;
32 
39 class GCheckBox : public GInteractor {
40 public:
45  GCheckBox(const string& text = "", bool checked = false, QWidget* parent = nullptr);
46 
50  ~GCheckBox() override;
51 
52  /* @inherit */
53  string getActionCommand() const override;
54 
55  /* @inherit */
56  _Internal_QWidget* getInternalWidget() const override;
57 
61  virtual string getText() const;
62 
63  /* @inherit */
64  string getType() const override;
65 
66  /* @inherit */
67  QWidget* getWidget() const override;
68 
73  virtual bool isChecked() const;
74 
79  virtual bool isSelected() const;
80 
85  virtual void setChecked(bool checked);
86 
91  virtual void setSelected(bool selected);
92 
96  virtual void setText(const string& text);
97 
102  virtual void toggle();
103 
104 protected:
108  string getActionEventType() const override;
109 
110 private:
111  Q_DISABLE_COPY(GCheckBox)
112 
113  _Internal_QCheckBox* _iqcheckBox;
114 
115  friend class _Internal_QCheckBox;
116 };
117 
122 class _Internal_QCheckBox : public QCheckBox, public _Internal_QWidget {
123  Q_OBJECT
124 
125 public:
126  _Internal_QCheckBox(GCheckBox* gcheckBox, bool checked = false, QWidget* parent = nullptr);
127  void detach() override;
128  void keyPressEvent(QKeyEvent* event) override;
129  void keyReleaseEvent(QKeyEvent* event) override;
130  QSize sizeHint() const override;
131 
132 signals:
133  void doubleClicked();
134 
135 public slots:
136  void handleStateChange(int);
137 
138 protected:
139  void mouseDoubleClickEvent(QMouseEvent* e) override;
140 
141 private:
142  GCheckBox* _gcheckBox;
143 
144  friend class GCheckBox;
145 };
146 
147 #endif // _gcheckbox_h
GCheckBox(string text="", bool checked=false, QWidget* parent=nullptr)
Creates a checkbox with the given text.
Definition: gcheckbox.cpp:25
virtual void setChecked(bool checked)
Sets whether the checkbox should be checked.
Definition: gcheckbox.cpp:75
virtual string getText() const
Returns the text next to the checkbox.
Definition: gcheckbox.cpp:55
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:91
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:39
virtual void setText(string text)
Sets the text that will appear next to the checkbox.
Definition: gcheckbox.cpp:85
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gcheckbox.cpp:51
~GCheckBox() override
Frees memory allocated internally by the checkbox.
Definition: gcheckbox.cpp:33
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gcheckbox.cpp:59
virtual bool isSelected() const
Returns true if the checkbox is currently checked.
Definition: gcheckbox.cpp:71
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gcheckbox.cpp:63
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:48
This interactor subclass represents an onscreen check box.
Definition: gcheckbox.h:39
virtual void setSelected(bool selected)
Sets whether the checkbox should be checked.
Definition: gcheckbox.cpp:81
virtual bool isChecked() const
Returns true if the checkbox is currently checked.
Definition: gcheckbox.cpp:67