SGL
gbutton.h
1 /*
2  * File: gbutton.h
3  * ---------------
4  *
5  * @author Marty Stepp
6  * @version 2019/04/23
7  * - moved some event-handling code to GInteractor superclass
8  * @version 2019/04/22
9  * - added setIcon with QIcon and QPixmap
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 gbutton.h to replace Java version
16  * @version 2018/06/25
17  * - initial version
18  */
19 
20 
21 #ifndef _gbutton_h
22 #define _gbutton_h
23 
24 #include <string>
25 #include <QToolButton>
26 
27 #include "ginteractor.h"
28 
29 class _Internal_QPushButton;
30 
36 class GButton : public GInteractor {
37 public:
41  GButton(const string& text = "", const string& iconFileName = "", QWidget* parent = nullptr);
42 
46  GButton(const string& text, const QIcon& icon, QWidget* parent = nullptr);
47 
51  GButton(const string& text, const QPixmap& icon, QWidget* parent = nullptr);
52 
56  ~GButton() override;
57 
58  /* @inherit */
59  string getAccelerator() const override;
60 
61  /* @inherit */
62  string getActionCommand() const override;
63 
64  /* @inherit */
65  _Internal_QWidget* getInternalWidget() const override;
66 
71  virtual string getText() const;
72 
79 
80  /* @inherit */
81  string getType() const override;
82 
83  /* @inherit */
84  QWidget* getWidget() const override;
85 
86  /* @inherit */
87  void setAccelerator(const string& accelerator) override;
88 
89  /* @inherit */
90  void setIcon(const QIcon& icon) override;
91 
92  /* @inherit */
93  void setIcon(const QPixmap& icon) override;
94 
95  /* @inherit */
96  void setIcon(const string& filename, bool retainIconSize = true) override;
97 
101  virtual void setText(const string& text);
102 
107  virtual void setTextPosition(GInteractor::TextPosition position);
108 
115  virtual void setTextPosition(SwingConstants horizontal, SwingConstants vertical) (deprecated);
116 
117 private:
118  Q_DISABLE_COPY(GButton)
119  _Internal_QPushButton* _iqpushbutton;
120 
121  friend class _Internal_QPushButton;
122 };
123 
128 class _Internal_QPushButton : public QToolButton, public _Internal_QWidget {
129  Q_OBJECT
130 
131 public:
132  _Internal_QPushButton(GButton* button, QWidget* parent = nullptr);
133  void detach() override;
134  QSize sizeHint() const override;
135 
136 signals:
137  void doubleClicked();
138 
139 public slots:
140  void handleClick();
141 
142 protected:
143  void mouseDoubleClickEvent(QMouseEvent* e) override;
144 
145 private:
146  GButton* _gbutton;
147 
148  friend class GButton;
149 };
150 
151 #endif // _gbutton_h
virtual void setText(string text)
Sets the text on the button to be the given text.
Definition: gbutton.cpp:156
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gbutton.cpp:100
virtual string getText() const
Returns the button&#39;s text.
Definition: gbutton.cpp:80
virtual GInteractor::TextPosition getTextPosition() const
Returns the button&#39;s text position relative to its icon.
Definition: gbutton.cpp:84
This interactor subclass represents an onscreen button.
Definition: gbutton.h:36
~GButton() override
Frees memory allocated internally by the button.
Definition: gbutton.cpp:58
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gbutton.cpp:96
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:48
virtual void setTextPosition(GInteractor::TextPosition position)
Sets the button&#39;s text position relative to its icon.
Definition: gbutton.cpp:163
string getAccelerator() const override
Returns a string representing a hotkey for this interactor, or an empty string if no accelerator has ...
Definition: gbutton.cpp:64
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gbutton.cpp:76
void setAccelerator(string accelerator) override
Sets an accelerator hotkey for this interactor, such as "Ctrl-S".
Definition: gbutton.cpp:104
void setIcon(const QIcon &icon) override
Sets the icon associated with this interactor.
Definition: gbutton.cpp:111
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:68
TextPosition
The places where an interactor can place its text relative to its icon.
Definition: ginteractor.h:53
GButton(string text="", string iconFileName="", QWidget* parent=nullptr)
Creates a button with the specified text label and optional icon.
Definition: gbutton.cpp:29