SGL
gslider.h
1 /*
2  * File: gslider.h
3  * ---------------
4  *
5  * @author Marty Stepp
6  * @version 2021/04/09
7  * - added sgl namespace
8  * @version 2019/04/23
9  * - added key events
10  * @version 2018/09/08
11  * - added doc comments for new documentation generation
12  * @version 2018/08/23
13  * - renamed to gslider.h to replace Java version
14  * @version 2018/06/29
15  * - initial version
16  */
17 
18 
19 #ifndef _gslider_h
20 #define _gslider_h
21 
22 #include <string>
23 #include <QSlider>
24 
25 #include "ginteractor.h"
26 
27 namespace sgl {
28 
29 class _Internal_QSlider;
30 
35 class GSlider : public GInteractor {
36 public:
40  enum Orientation {
43  };
44 
48  static const int DEFAULT_MIN_VALUE;
49 
53  static const int DEFAULT_MAX_VALUE;
54 
58  static const int DEFAULT_INITIAL_VALUE;
59 
64  GSlider(int min = 0, int max = 100, int value = 50, QWidget* parent = nullptr);
65 
70  GSlider(Orientation orientation, int min = 0, int max = 100, int value = 50, QWidget* parent = nullptr);
71 
75  ~GSlider() override;
76 
77  /* @inherit */
78  _Internal_QWidget* getInternalWidget() const override;
79 
84  virtual int getMajorTickSpacing() const;
85 
89  virtual int getMax() const;
90 
94  virtual int getMin() const;
95 
100  virtual int getMinorTickSpacing() const;
101 
105  virtual Orientation getOrientation() const;
106 
112  virtual bool getPaintLabels() const;
113 
118  virtual bool getPaintTicks() const;
119 
125  virtual bool getSnapToTicks() const;
126 
127  /* @inherit */
128  string getType() const override;
129 
133  virtual int getValue() const;
134 
135  /* @inherit */
136  QWidget* getWidget() const override;
137 
142  virtual void setMajorTickSpacing(int value);
143 
148  virtual void setMax(int max);
149 
154  virtual void setMin(int min);
155 
160  virtual void setMinorTickSpacing(int value);
161 
167  virtual void setPaintLabels(bool value);
168 
173  virtual void setPaintTicks(bool value);
174 
179  virtual void setRange(int min, int max);
180 
186  virtual void setSnapToTicks(bool value);
187 
192  virtual void setState(int min, int max, int value);
193 
198  virtual void setValue(int value);
199 
200 protected:
204  string getActionEventType() const override;
205 
206 private:
207  Q_DISABLE_COPY(GSlider)
208 
209  _Internal_QSlider* _iqslider;
210 
211  friend class _Internal_QSlider;
212 };
213 
218 class _Internal_QSlider : public QSlider, public _Internal_QWidget {
219  Q_OBJECT
220 
221 public:
222  _Internal_QSlider(GSlider* qgslider, Qt::Orientation orientation = Qt::Horizontal, QWidget* parent = nullptr);
223  void detach() override;
224  void keyPressEvent(QKeyEvent* event) override;
225  void keyReleaseEvent(QKeyEvent* event) override;
226  QSize sizeHint() const override;
227 
228 public slots:
229  void handleChange(int value);
230 
231 private:
232  GSlider* _gslider;
233 
234  friend class GSlider;
235 };
236 
237 } // namespace sgl
238 
239 #endif // _gslider_h
Definition: gslider.h:42
static const int DEFAULT_MIN_VALUE
Default minimum value for a slider (0).
Definition: gslider.h:48
string getType() const override
Returns a string representing the class name of this interactor, such as "GButton" or "GCheckBox"...
Definition: gslider.cpp:114
virtual void setValue(int value)
Sets the current value of the slider.
Definition: gslider.cpp:194
GSlider(int min=0, int max=100, int value=50, QWidget* parent=nullptr)
Creates a new horizontal slider with the given value range.
Definition: gslider.cpp:31
static const int DEFAULT_MAX_VALUE
Default maximum value for a slider (100).
Definition: gslider.h:53
Definition: console.h:45
This abstract class is the superclass for all graphical interactors.
Definition: ginteractor.h:52
virtual int getValue() const
Returns the slider&#39;s current value.
Definition: gslider.cpp:118
virtual Orientation getOrientation() const
Returns the orientation of the slider, either HORIZONTAL or VERTICAL.
Definition: gslider.cpp:95
QWidget* getWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gslider.cpp:122
~GSlider() override
Frees memory allocated internally by the slider.
Definition: gslider.cpp:65
_Internal_QWidget* getInternalWidget() const override
Returns a direct pointer to the internal Qt widget being wrapped by this interactor.
Definition: gslider.cpp:75
This interactor subclass represents an onscreen slider.
Definition: gslider.h:35
virtual int getMax() const
Returns the maximum allowed value of the slider.
Definition: gslider.cpp:83
Orientation
The two valid orientations of sliders.
Definition: gslider.h:40
Definition: gslider.h:41
virtual void setRange(int min, int max)
Sets the min-max range of the slider.
Definition: gslider.cpp:168
virtual void setState(int min, int max, int value)
Sets all of the relevant state of the slider.
Definition: gslider.cpp:181
virtual int getMin() const
Returns the minimum allowed value of the slider.
Definition: gslider.cpp:87
virtual void setMax(int max)
Sets the maximum allowed value of the slider.
Definition: gslider.cpp:132
virtual void setMin(int min)
Sets the minimum allowed value of the slider.
Definition: gslider.cpp:142
static const int DEFAULT_INITIAL_VALUE
Default initial value for a slider (50).
Definition: gslider.h:58