SGL
gbutton.h
1 /*
2  * File: gbutton.h
3  * ---------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2019/04/23
9  * - moved some event-handling code to GInteractor superclass
10  * @version 2019/04/22
11  * - added setIcon with QIcon and QPixmap
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 gbutton.h to replace Java version
18  * @version 2018/06/25
19  * - initial version
20  */
21 
22 
23 #ifndef _gbutton_h
24 #define _gbutton_h
25 
26 #include <string>
27 #include <QToolButton>
28 
29 #include "ginteractor.h"
30 
31 namespace sgl {
32 
33 class _Internal_QPushButton;
34 
40 class GButton : public GInteractor {
41 public:
45  GButton(const string& text = "", const string& iconFileName = "", QWidget* parent = nullptr);
46 
50  GButton(const string& text, const QIcon& icon, QWidget* parent = nullptr);
51 
55  GButton(const string& text, const QPixmap& icon, QWidget* parent = nullptr);
56 
60  ~GButton() override;
61 
62  /* @inherit */
63  string getAccelerator() const override;
64 
65  /* @inherit */
66  string getActionCommand() const override;
67 
68  /* @inherit */
69  _Internal_QWidget* getInternalWidget() const override;
70 
75  virtual string getText() const;
76 
83 
84  /* @inherit */
85  string getType() const override;
86 
87  /* @inherit */
88  QWidget* getWidget() const override;
89 
90  /* @inherit */
91  void setAccelerator(const string& accelerator) override;
92 
93  /* @inherit */
94  void setIcon(const QIcon& icon) override;
95 
96  /* @inherit */
97  void setIcon(const QPixmap& icon) override;
98 
99  /* @inherit */
100  void setIcon(const string& filename, bool retainIconSize = true) override;
101 
105  virtual void setText(const string& text);
106 
111  virtual void setTextPosition(GInteractor::TextPosition position);
112 
119  virtual void setTextPosition(SwingConstants horizontal, SwingConstants vertical) (deprecated);
120 
121 private:
122  Q_DISABLE_COPY(GButton)
123  _Internal_QPushButton* _iqpushbutton;
124 
125  friend class _Internal_QPushButton;
126 };
127 
132 class _Internal_QPushButton : public QToolButton, public _Internal_QWidget {
133  Q_OBJECT
134 
135 public:
136  _Internal_QPushButton(GButton* button, QWidget* parent = nullptr);
137  void detach() override;
138  QSize sizeHint() const override;
139 
140 signals:
141  void doubleClicked();
142 
143 public slots:
144  void handleClick();
145 
146 protected:
147  void mouseDoubleClickEvent(QMouseEvent* e) override;
148 
149 private:
150  GButton* _gbutton;
151 
152  friend class GButton;
153 };
154 
155 } // namespace sgl
156 
157 #endif // _gbutton_h
SwingConstants
Constants for alignments and icon positions.
Definition: gtypes.h:159
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gbutton.cpp:104
TextPosition
The places where an interactor can place its text relative to its icon.
Definition: ginteractor.h:57
GButton(string text="", string iconFileName="", QWidget* parent=nullptr)
Creates a button with the specified text label and optional icon.
Definition: gbutton.cpp:33
This interactor subclass represents an onscreen button.
Definition: gbutton.h:40
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gbutton.cpp:100
void setIcon(const QIcon &icon) override
Sets the icon associated with this interactor.
Definition: gbutton.cpp:115
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gbutton.cpp:80
virtual void setTextPosition(GInteractor::TextPosition position)
Sets the button&#39;s text position relative to its icon.
Definition: gbutton.cpp:167
virtual string getText() const
Returns the button&#39;s text.
Definition: gbutton.cpp:84
Definition: console.h:45
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
virtual GInteractor::TextPosition getTextPosition() const
Returns the button&#39;s text position relative to its icon.
Definition: gbutton.cpp:88
string getActionCommand() const override
Returns an action command for this interactor, which is a semi-unique string you can use to identify ...
Definition: gbutton.cpp:72
void setAccelerator(string accelerator) override
Sets an accelerator hotkey for this interactor, such as "Ctrl-S".
Definition: gbutton.cpp:108
virtual void setText(string text)
Sets the text on the button to be the given text.
Definition: gbutton.cpp:160
string getAccelerator() const override
Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has ...
Definition: gbutton.cpp:68
~GButton() override
Frees memory allocated internally by the button.
Definition: gbutton.cpp:62