Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParameterWidget.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_PARAMETERWIDGET_H_
21 #define OMNI_UI_PARAMETERWIDGET_H_
22 
23 #include <set>
24 #include <QWidget>
25 #include <QCheckBox>
26 #include <omni/ui/mixin/Scale.h>
27 #include <omni/ui/RangedFloat.h>
28 #include <omni/ui/RangedInt.h>
29 #include <omni/ui/Rotation.h>
31 #include <omni/util.h>
32 
33 namespace omni {
34  namespace ui {
35  /**@brief A widget which holds sub-widgets for manipulating parameters
36  **/
38  public QWidget,
39  public mixin::Scale<omni::ui::RangedFloat>{
40  Q_OBJECT
41  public:
42  /// Default constructor
43  ParameterWidget(QWidget *_parent = nullptr);
44 
45  /// Default Constructor
46  virtual ~ParameterWidget();
47 
48  /// Adds a widget with a name, a value and min-max range
49  RangedFloat* addWidget(QString const&,
50  float,
51  float,
52  float);
53 
54  /// Adds a integer widget with a name, a value and min-max range
55  RangedInt* addIntegerWidget(QString const&,
56  int,
57  int,
58  int);
59 
60  /// Adds an angle widget with a name, a value and min-max range
61  RangedFloat* addAngleWidget(QString const&,
62  float,
63  float,
64  float);
65 
66  /// Adds an offset widget with a name, a value and min-max range
67  RangedFloat* addOffsetWidget(QString const&,
68  float,
69  float,
70  float);
71 
72  /// Adds an Rotation widget with three dials for X,Y and Z axis
73  Rotation * addRotationWidget(QString const&);
74 
75  /// Add a new affine transform widget with an id
77  omni::AffineTransform *);
78 
79  /// Adds a checkbox
80  QCheckBox* addCheckBox(QString const&,
81  bool _checked = false);
82 
83  /// Return id of focused parameter, -1 if no parameter is focused
84  int focusId() const;
85 
86  public slots:
87  /// Removes all parameter widgets
88  void clear();
89 
90  virtual void updateParameters();
91 
92  /// Utility method for retrieving the value from a slider with id
93  double getParamAsFloat(QString const&) const;
94 
95  /// Set slider value from given value
96  void setParamAsFloat(QString const& _str,
97  double _value);
98 
99  /// Utility method for retrieving the value from a slider with id
100  int getParamAsInt(QString const&) const;
101 
102  /// Set slider value from given value
103  void setParamAsInt(QString const& _str,
104  int _value);
105 
106  /// Utility method for retrieving the value from checkbox with id
107  bool getParamAsBool(QString const&) const;
108 
109  /// Get parameter widget from parameter map with Id
110  QWidget* getWidget(QString const&);
111 
112  /// Show / hide parameter widgets
113  void setParametersVisible(bool);
114 
115  /**@brief Put focus on next element
116  @param _circular Selects first parameter when last parameter has been
117  reached
118  @returns True if last parameter has been reached, always returns true
119  when in circular mode
120  **/
121  bool focusNext(bool _circular = false);
122 
123  /**@brief Put focus on prev element
124  @param _circular Selects last parameter when first parameter has been
125  reached
126  @returns True if first parameter has been reached, always returns
127  true
128  when in circular mode
129  **/
130  bool focusPrev(bool _circular = false);
131 
132  /// Focus item in layout with index
133  void focus(int _index);
134 
135  /// Set focus on first widget in parameter list
136  void focusFirst();
137 
138  /// Set focus on last widget in parameter list
139  void focusLast();
140 
141  /// Set slider ranges
142  virtual void setScale(float);
143 
144  /// Set slider ranges
145  virtual void setUnit(QString const&);
146 
147  signals:
148  void parametersUpdated();
149 
150  protected:
151  /// Id of first focussed widget
152  inline virtual int firstFocusId() const {
153  return 0;
154  }
155 
156  void keyPressEvent(QKeyEvent *_event);
157 
158  /// Slider parameter widgets
159  std::vector<QUniquePtr<QWidget> > parameters_;
160 
161  /// Slider widgets, sorted by their label
162  std::map<QString, QWidget *> parameterMap_;
163  };
164  }
165 }
166 
167 #endif /* OMNI_UI_PARAMETERWIDGET_H_ */
virtual void setUnit(QString const &)
Set slider ranges.
Definition: ParameterWidget.cpp:234
virtual void setScale(float)
Set slider ranges.
Definition: ParameterWidget.cpp:230
double getParamAsFloat(QString const &) const
Utility method for retrieving the value from a slider with id.
Definition: ParameterWidget.cpp:152
virtual int firstFocusId() const
Id of first focussed widget.
Definition: ParameterWidget.h:152
Rotation widget has three dials for rotation in X,Y,Z direction.
Definition: Rotation.h:30
std::map< QString, QWidget * > parameterMap_
Slider widgets, sorted by their label.
Definition: ParameterWidget.h:162
QCheckBox * addCheckBox(QString const &, bool _checked=false)
Adds a checkbox.
Definition: ParameterWidget.cpp:131
int focusId() const
Return id of focused parameter, -1 if no parameter is focused.
Definition: ParameterWidget.cpp:204
bool focusNext(bool _circular=false)
Put focus on next element.
Definition: ParameterWidget.cpp:247
Rotation * addRotationWidget(QString const &)
Adds an Rotation widget with three dials for X,Y and Z axis.
Definition: ParameterWidget.cpp:277
int getParamAsInt(QString const &) const
Utility method for retrieving the value from a slider with id.
Definition: ParameterWidget.cpp:169
QWidget * getWidget(QString const &)
Get parameter widget from parameter map with Id.
Definition: ParameterWidget.cpp:192
bool focusPrev(bool _circular=false)
Put focus on prev element.
Definition: ParameterWidget.cpp:262
virtual ~ParameterWidget()
Default Constructor.
Definition: ParameterWidget.cpp:33
void keyPressEvent(QKeyEvent *_event)
Definition: ParameterWidget.cpp:238
RangedFloat * addWidget(QString const &, float, float, float)
Adds a widget with a name, a value and min-max range.
Definition: ParameterWidget.cpp:59
A widget for editing an affine transformation.
Definition: AffineTransform.h:37
RangedFloat * addAngleWidget(QString const &, float, float, float)
Adds an angle widget with a name, a value and min-max range.
Definition: ParameterWidget.cpp:105
std::vector< QUniquePtr< QWidget > > parameters_
Slider parameter widgets.
Definition: ParameterWidget.h:159
void setParamAsFloat(QString const &_str, double _value)
Set slider value from given value.
Definition: ParameterWidget.cpp:161
A widget which holds sub-widgets for manipulating parameters.
Definition: ParameterWidget.h:37
omni::ui::AffineTransform * addAffineTransformWidget(QString const &, omni::AffineTransform *)
Add a new affine transform widget with an id.
Definition: ParameterWidget.cpp:300
A slider with float value within a minimum and maximum.
Definition: RangedFloat.h:30
void setParametersVisible(bool)
Show / hide parameter widgets.
Definition: ParameterWidget.cpp:198
bool getParamAsBool(QString const &) const
Utility method for retrieving the value from checkbox with id.
Definition: ParameterWidget.cpp:184
Integer slider.
Definition: RangedInt.h:30
void setParamAsInt(QString const &_str, int _value)
Set slider value from given value.
Definition: ParameterWidget.cpp:176
ParameterWidget(QWidget *_parent=nullptr)
Default constructor.
Definition: ParameterWidget.cpp:28
void clear()
Removes all parameter widgets.
Definition: ParameterWidget.cpp:38
Scales a set of sliders and sets a common unit suffix.
Definition: Scale.h:30
RangedFloat * addOffsetWidget(QString const &, float, float, float)
Adds an offset widget with a name, a value and min-max range.
Definition: ParameterWidget.cpp:117
virtual void updateParameters()
Definition: ParameterWidget.cpp:54
void focusLast()
Set focus on last widget in parameter list.
Definition: ParameterWidget.cpp:226
RangedInt * addIntegerWidget(QString const &, int, int, int)
Adds a integer widget with a name, a value and min-max range.
Definition: ParameterWidget.cpp:80
void focusFirst()
Set focus on first widget in parameter list.
Definition: ParameterWidget.cpp:222
void focus(int _index)
Focus item in layout with index.
Definition: ParameterWidget.cpp:216