Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Dial.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_DIAL_H_
21 #define OMNI_UI_DIAL_H_
22 
23 #include <QWidget>
24 #include <QDoubleSpinBox>
25 #include <QLabel>
26 #include <omni/ui/ColorSet.h>
28 #include <omni/ui/mixin/Editor.h>
29 
30 namespace omni {
31  namespace ui {
32  /// Circular dial widget with range value and editor
33  class Dial :
34  public QWidget,
35  public mixin::RangedValue<Dial, double>,
36  protected mixin::Editor<Dial, QDoubleSpinBox>{
37  Q_OBJECT
38 
39  public:
40  /// Editor mixin type
42 
43  /// Ranged value mixin type
46 
47  /// Construct with optional parent widget
48  Dial(QWidget * = nullptr);
49 
50  /// Construct with value and minimum and maximum values
51  Dial(value_type _value,
52  value_type _minimum,
53  value_type _maximum,
54  QWidget * = nullptr);
55 
56  /// Destructor
57  ~Dial();
58 
59  /// Return suffix string
60  QString const & suffix() const;
61 
62  /// Return letter shown in background
63  QChar letter() const;
64 
65  /// Return color set
66  ColorSet const& colorSet() const;
67 
68  /// Is moving when mouse button is pressed
69  bool isMoving() const;
70 
71  /// Show ticks
72  bool showTicks() const;
73 
74  public slots:
75  /// Set show ticks
76  void setShowTicks(bool);
77 
78  /// Set suffix string
79  void setSuffix(QString const&);
80 
81  /// Set letter
82  void setLetter(QChar);
83 
84  /// Set single step value
85  void setSingleStep(double);
86 
87  /// Set page step value
88  void setPageStep(double);
89 
90  /// Set minimum value
91  void setMinimum(double);
92 
93  /// Set maximum value
94  void setMaximum(double);
95 
96  /// Set range
97  void setRange(double,
98  double);
99 
100  /// Set value from integer
101  void setValue(int);
102 
103  /// Set value
104  void setValue(double);
105 
106  /// Set visibility of editor
107  void setEditorVisible(bool);
108 
109  signals:
110  void valueChanged();
111  void rangeChanged();
112 
113  protected:
114  /// Re-paint on resize
115  void resizeEvent(QResizeEvent *);
116  void paintEvent(QPaintEvent *);
117  void mousePressEvent(QMouseEvent *);
118  void mouseReleaseEvent(QMouseEvent *);
119  void mouseMoveEvent(QMouseEvent *);
120 
121  /**@brief Double click in center shows editor, double click on border reset to default value
122  **/
123  void mouseDoubleClickEvent(QMouseEvent *);
124 
125  /// Show editor when enter key is pressed
126  void keyPressEvent(QKeyEvent *);
127 
128  void valueChangedEvent();
129  void rangeChangedEvent();
130 
131  private:
132  bool isMoving_ = false;
133  bool showTicks_ = true;
134  QChar letter_ = 'X';
135  QString suffix_;
136  QLabel *valueLabel_;
138 
139  void init();
140  void editorSetup();
141  QPointF pos_;
142 
143  double radius() const;
144 
145  /// Get value from point on widget
146  double getValue(QPoint const&);
147 
148  /// Draw a tick with value and length
149  void paintTick(QPainter&,
150  double _value,
151  double _length);
152  };
153  }
154 }
155 
156 #endif /* OMNI_UI_DIAL_H_ */
Dial(QWidget *=nullptr)
Construct with optional parent widget.
Definition: Dial.cpp:30
QChar letter() const
Return letter shown in background.
double getValue(QPoint const &)
Get value from point on widget.
Definition: Dial.cpp:287
void keyPressEvent(QKeyEvent *)
Show editor when enter key is pressed.
Definition: Dial.cpp:263
void setMaximum(double)
Set maximum value.
Definition: Dial.cpp:142
mixin_range_type::value_type value_type
Definition: Dial.h:45
Simplies color access from a palette for a widget.
Definition: ColorSet.h:29
void valueChanged()
bool showTicks() const
Show ticks.
Definition: Dial.cpp:54
void resizeEvent(QResizeEvent *)
Re-paint on resize.
Definition: Dial.cpp:185
QChar letter_
Definition: Dial.h:134
void rangeChanged()
double radius() const
Definition: Dial.cpp:353
QPointF pos_
Definition: Dial.h:141
void valueChangedEvent()
Value changed event which is emitted on changed value.
Definition: Dial.cpp:171
void mouseReleaseEvent(QMouseEvent *)
Definition: Dial.cpp:208
mixin::RangedValue< Dial, double > mixin_range_type
Ranged value mixin type.
Definition: Dial.h:44
void paintTick(QPainter &, double _value, double _length)
Draw a tick with value and length.
Definition: Dial.cpp:360
ColorSet const & colorSet() const
Return color set.
Definition: Dial.cpp:166
void init()
Definition: Dial.cpp:75
void rangeChangedEvent()
Handler to emit rangeChanged signal in derived widgets.
Definition: Dial.cpp:178
void mouseMoveEvent(QMouseEvent *)
Definition: Dial.cpp:218
void setEditorVisible(bool)
Set visibility of editor.
Definition: Dial.cpp:89
QLabel * valueLabel_
Definition: Dial.h:136
bool showTicks_
Definition: Dial.h:133
double value_type
Definition: RangedValue.h:39
QString suffix_
Definition: Dial.h:135
void setRange(double, double)
Set range.
Definition: Dial.cpp:147
void setValue(int)
Set value from integer.
Definition: Dial.cpp:132
bool isMoving_
Definition: Dial.h:132
ColorSet colorSet_
Definition: Dial.h:137
void setSingleStep(double)
Set single step value.
Definition: Dial.cpp:152
void mousePressEvent(QMouseEvent *)
Definition: Dial.cpp:194
void paintEvent(QPaintEvent *)
Definition: Dial.cpp:296
void editorSetup()
Definition: Dial.cpp:102
void mouseDoubleClickEvent(QMouseEvent *)
Double click in center shows editor, double click on border reset to default value.
Definition: Dial.cpp:248
void setSuffix(QString const &)
Set suffix string.
Definition: Dial.cpp:120
void setShowTicks(bool)
Set show ticks.
Definition: Dial.cpp:69
bool isMoving() const
Is moving when mouse button is pressed.
Definition: Dial.cpp:59
~Dial()
Destructor.
Definition: Dial.cpp:51
Template class for a value within a certain min/max range.
Definition: RangedValue.h:33
Circular dial widget with range value and editor.
Definition: Dial.h:33
QString const & suffix() const
Return suffix string.
Definition: Dial.cpp:64
Mixin for a widget that holds an editor widget.
Definition: Editor.h:30
mixin::Editor< Dial, QDoubleSpinBox > mixin_editor_type
Editor mixin type.
Definition: Dial.h:41
void setMinimum(double)
Set minimum value.
Definition: Dial.cpp:137
void setLetter(QChar)
Set letter.
Definition: Dial.cpp:114
void setPageStep(double)
Set page step value.
Definition: Dial.cpp:159