Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RangedFloat.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2015 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_UI_RANGEDFLOAT_H_
21 #define OMNI_UI_RANGEDFLOAT_H_
22 
23 #include <QDoubleSpinBox>
24 #include "mixin/RangedValue.h"
25 #include "AbstractInputWidget.h"
26 
27 namespace omni {
28  namespace ui {
29  /// A slider with float value within a minimum and maximum
30  class RangedFloat :
31  public AbstractInputWidget,
32  private mixin::RangedValue<RangedFloat, double>{
33  Q_OBJECT
34  public:
35  enum class Scale {
36  LINEAR,
38  };
39 
41  typedef QDoubleSpinBox editor_type;
46 
47  /// Construct from parent widget
48  RangedFloat(QWidget * = nullptr);
49 
50  /**@brief Construct with input parameters
51  * @param _label Label of widget
52  * @param _value Initial value
53  * @param _min Minimal value
54  * @param _max Maximal value
55  **/
56  RangedFloat(QString const& _label,
57  double _value,
58  double _min,
59  double _max,
60  QWidget * = nullptr);
61  virtual ~RangedFloat();
62 
67 
68  /// Return suffix
69  QString suffix() const;
70 
71  /// Return precision
72  int precision() const;
73 
74  /// Return grip size
75  int gripSize() const;
76 
77  /// Return flag if default value is used
78  bool useDefaultValue() const;
79 
80  bool drawTicks() const;
81 
82  Scale scale() const;
83 
84  public slots:
85  /// Set value, valueChanged() signal will be emitted
86  void setValue(double);
87 
88  /// Set minimal value, rangeChanged() signal will be emitted
89  void setMinimum(double);
90 
91  /// Set maximum value, rangeChanged() signal will be emitted
92  void setMaximum(double);
93 
94  /// Set range (minimum/maximum), rangeChanged() signel will be emitted
95  void setRange(double,
96  double);
97 
98  /// Show/hide editor
99  void setEditorVisible(bool);
100 
101  /// Toggle value snap on/off
102  void setSnap(bool);
103 
104  void setGripSize(int);
105 
106  /// Use Default Value and show it
107  void setUseDefaultValue(bool);
108 
109  void setDrawTicks(bool);
110 
111  /// Set precision
112  void setPrecision(int);
113 
114  /// Set Suffix
115  void setSuffix(QString const&);
116 
117  /// Set pivot
118  void setPivot(double);
119 
120  void setDefaultValue(double);
121 
122  void setSingleStep(double);
123 
124  void setPageStep(double);
125 
126  void setScale(Scale);
127 
128  signals:
129  void valueChanged();
130  void rangeChanged();
131 
132  protected:
133  void paintEvent(QPaintEvent *);
134  void keyPressEvent(QKeyEvent *);
135  void mouseMoveEvent(QMouseEvent *);
136  void mousePressEvent(QMouseEvent *);
137  void mouseReleaseEvent(QMouseEvent *);
138  void mouseDoubleClickEvent(QMouseEvent *);
139  void wheelEvent(QWheelEvent *);
140 
141  void valueChangedEvent();
142  void rangeChangedEvent();
143 
144  private:
145  void init();
146  void editorSetup();
147 
148  /// Get value from x mouse position
149  double valueFromPos(double) const;
150 
151  /// Calculate position from value
152  double valueToPos() const;
153 
154  /// Calculate position from value
155  double valueToPos(double) const;
156 
158  bool moving_ = false;
159  bool drawTicks_ = false;
160  bool useDefaultValue_ = false;
161  QString suffix_;
162  int gripSize_ = 0;
163  int precision_ = 2;
164  };
165  }
166 }
167 
168 #endif /* OMNI_UI_RANGEDFLOAT_H_ */
int gripSize() const
Return grip size.
Definition: RangedFloat.cpp:367
value_type value() const
Return value.
Definition: RangedValue.h:65
value_type pageStep() const
Return value for page step.
Definition: Step.h:73
void keyPressEvent(QKeyEvent *)
Show editor when enter key is pressed.
Definition: RangedFloat.cpp:271
Input widget with an editor widget.
Definition: AbstractInputWidget.h:30
void mouseMoveEvent(QMouseEvent *)
Definition: RangedFloat.cpp:290
void setEditorVisible(bool)
Show/hide editor.
Definition: RangedFloat.cpp:334
void paintEvent(QPaintEvent *)
Definition: RangedFloat.cpp:235
Scale scale_
Definition: RangedFloat.h:157
void mouseReleaseEvent(QMouseEvent *)
Definition: RangedFloat.cpp:309
void valueChangedEvent()
Value changed event which is emitted on changed value.
Definition: RangedFloat.cpp:60
void setDefaultValue(double)
Definition: RangedFloat.cpp:112
void editorSetup()
Definition: RangedFloat.cpp:355
void mousePressEvent(QMouseEvent *)
Hide editor and set focus on click.
Definition: RangedFloat.cpp:298
void setValue(double)
Set value, valueChanged() signal will be emitted.
Definition: RangedFloat.cpp:80
void setRange(double, double)
Set range (minimum/maximum), rangeChanged() signel will be emitted.
Definition: RangedFloat.cpp:95
void init()
Definition: RangedFloat.cpp:340
void setMaximum(double)
Set maximum value, rangeChanged() signal will be emitted.
Definition: RangedFloat.cpp:90
RangedFloat(QWidget *=nullptr)
Construct from parent widget.
Definition: RangedFloat.cpp:29
void setPageStep(double)
Definition: RangedFloat.cpp:126
bool moving_
Definition: RangedFloat.h:158
virtual ~RangedFloat()
Definition: RangedFloat.cpp:47
void setMinimum(double)
Set minimal value, rangeChanged() signal will be emitted.
Definition: RangedFloat.cpp:85
int precision_
Definition: RangedFloat.h:163
Scale scale() const
Definition: RangedFloat.cpp:346
value_type singleStep() const
Return value for single step.
Definition: Step.h:67
bool snap() const
Snap value (align to single step value)
Definition: Step.h:55
void setSingleStep(double)
Definition: RangedFloat.cpp:119
void setPrecision(int)
Set precision.
Definition: RangedFloat.cpp:155
void wheelEvent(QWheelEvent *)
Definition: RangedFloat.cpp:328
void setGripSize(int)
Definition: RangedFloat.cpp:371
A slider with float value within a minimum and maximum.
Definition: RangedFloat.h:30
bool useDefaultValue() const
Return flag if default value is used.
Definition: RangedFloat.cpp:133
void mouseDoubleClickEvent(QMouseEvent *)
Show editor on double click.
Definition: RangedFloat.cpp:314
value_type maximum() const
Return maximum value.
Definition: Range.h:60
value_type defaultValue() const
Return default value.
Definition: RangedValue.h:71
bool drawTicks_
Definition: RangedFloat.h:159
value_type minimum() const
Return minimum value.
Definition: Range.h:54
QString suffix_
Definition: RangedFloat.h:161
mixin::RangedValue< RangedFloat, double > mixin_range_type
Definition: RangedFloat.h:40
void setSnap(bool)
Toggle value snap on/off.
Definition: RangedFloat.cpp:100
Template class for a value within a certain min/max range.
Definition: RangedValue.h:33
bool useDefaultValue_
Definition: RangedFloat.h:160
double valueToPos() const
Calculate position from value.
Definition: RangedFloat.cpp:208
value_type pivot() const
Return pivot value.
Definition: RangedValue.h:77
void setDrawTicks(bool)
Definition: RangedFloat.cpp:149
void setSuffix(QString const &)
Set Suffix.
Definition: RangedFloat.cpp:162
bool drawTicks() const
Definition: RangedFloat.cpp:144
void setScale(Scale)
Definition: RangedFloat.cpp:350
double valueFromPos(double) const
Get value from x mouse position.
Definition: RangedFloat.cpp:169
Scale
Definition: RangedFloat.h:35
QString suffix() const
Return suffix.
Definition: RangedFloat.cpp:50
QDoubleSpinBox editor_type
Definition: RangedFloat.h:41
void setPivot(double)
Set pivot.
Definition: RangedFloat.cpp:105
int gripSize_
Definition: RangedFloat.h:162
void setUseDefaultValue(bool)
Use Default Value and show it.
Definition: RangedFloat.cpp:138
int precision() const
Return precision.
Definition: RangedFloat.cpp:55
void rangeChangedEvent()
Handler to emit rangeChanged signal in derived widgets.
Definition: RangedFloat.cpp:74