Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Slots | Signals | Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes
omni::ui::RangedInt Class Reference

Integer slider. More...

#include <RangedInt.h>

Inheritance diagram for omni::ui::RangedInt:
Inheritance graph
[legend]
Collaboration diagram for omni::ui::RangedInt:
Collaboration graph
[legend]

Public Types

typedef QSpinBox editor_type
 
typedef mixin::RangedValue
< RangedInt, int > 
mixin_range_type
 
- Public Types inherited from omni::ui::AbstractInputWidget
typedef mixin::Editor
< AbstractInputWidget, QWidget > 
mixin_editor_type
 
- Public Types inherited from omni::ui::mixin::RangedValue< RangedInt, int >
typedef Range< int > range_type
 
typedef Step< int > step_type
 
typedef int value_type
 
- Public Types inherited from omni::ui::mixin::Range< int >
typedef int value_type
 
- Public Types inherited from omni::ui::mixin::Step< int >
typedef int value_type
 

Public Slots

void setValue (int)
 
void setMinimum (int)
 
void setMaximum (int)
 
void setRange (int, int)
 
void setEditorVisible (bool)
 
void setUseDefaultValue (bool)
 Use Default Value and show it. More...
 
void setDrawTicks (bool)
 
- Public Slots inherited from omni::ui::AbstractInputWidget
virtual void setEditorVisible (bool)
 Set editor visible. More...
 
void showEditor ()
 Show editor. More...
 
void hideEditor ()
 Hide editor. More...
 

Signals

void valueChanged ()
 
void rangeChanged ()
 
- Signals inherited from omni::ui::AbstractInputWidget
void valueChanged ()
 Value changed event. More...
 

Public Member Functions

 RangedInt (QWidget *=nullptr)
 
 RangedInt (QString const &_label, int _value, int _min, int _max, QWidget *=nullptr)
 
 ~RangedInt ()
 
bool useDefaultValue () const
 Return flag if default value is used. More...
 
bool drawTicks () const
 
- Public Member Functions inherited from omni::ui::AbstractInputWidget
 AbstractInputWidget (QWidget *=nullptr)
 
virtual ~AbstractInputWidget ()
 
- Public Member Functions inherited from omni::ui::Widget
 Widget (QWidget *=nullptr)
 
 Widget (QString const &_label, QWidget *=nullptr)
 
virtual ~Widget ()
 
QString label () const
 Return label text of widget. More...
 
void setLabel (QString const &)
 Set label text of widget. More...
 
ColorSet const & colorSet () const
 
double zoomFactor () const
 Zoom factor of widget. More...
 
- Public Member Functions inherited from omni::ui::mixin::RangedValue< RangedInt, int >
 RangedValue ()
 Default constructor. More...
 
 RangedValue (value_type _value, value_type _minimum, value_type _maximum, value_type _singleStep=1.0, value_type _pageStep=10.0)
 Constructor from user defined value and range. More...
 
qreal ratio () const
 Returns ratio of current value. More...
 
value_type value () const
 Return value. More...
 
value_type defaultValue () const
 Return default value. More...
 
value_type pivot () const
 Return pivot value. More...
 
void increase ()
 Increate value by single step value. More...
 
void decrease ()
 Decrease value by single step value. More...
 
void setValue (value_type _value)
 Set new value and emit value changed event. More...
 
void reset ()
 Reset value to default value. More...
 
void setDefaultValue (value_type _value)
 Set new default value. More...
 
void setPivot (value_type _pivot)
 Set pivot value (0.0 by default) More...
 
- Public Member Functions inherited from omni::ui::mixin::Range< int >
 Range (value_type _minimum=0.0, value_type _maximum=100.0)
 
qreal ratio (value_type _v) const
 Return ratio of value v. More...
 
value_type range () const
 Return range (difference between maximum and minimum) More...
 
value_type minimum () const
 Return minimum value. More...
 
value_type maximum () const
 Return maximum value. More...
 
void setMinimum (value_type _minimum)
 Set new minimum value and value and emit rangeChanged event. More...
 
void disableMinimum ()
 Disable minimum by setting the value to infinite. More...
 
void setMaximum (value_type _maximum)
 Set new maximum value and value and emit rangeChanged event. More...
 
void disableMaximum ()
 Disable maximum by setting maximum to infinite value. More...
 
void setRange (value_type _minimum, value_type _maximum)
 Set range and validate. More...
 
void disableRange ()
 Disable range by setting minimum and maximum to infinite value. More...
 
bool minimumUsed () const
 
bool maximumUsed () const
 
- Public Member Functions inherited from omni::ui::mixin::Step< int >
 Step (value_type _singleStep=1.0, value_type _pageStep=10.0, bool _snap=false)
 Construct with a single step, page step value. More...
 
qreal snapped (value_type _v) const
 Return snapped value. More...
 
bool snap () const
 Snap value (align to single step value) More...
 
void setSnap (bool _snap)
 Set boolean if value is to be snapped. More...
 
value_type singleStep () const
 Return value for single step. More...
 
value_type pageStep () const
 Return value for page step. More...
 
void setSingleStep (value_type _singleStep)
 Set new single step value. More...
 
void setPageStep (value_type _pageStep)
 Set new value for page step. More...
 

Protected Member Functions

void paintEvent (QPaintEvent *)
 
void keyPressEvent (QKeyEvent *)
 Show editor when enter key is pressed. More...
 
void mouseMoveEvent (QMouseEvent *)
 
void mousePressEvent (QMouseEvent *)
 Hide editor and set focus on click. More...
 
void mouseReleaseEvent (QMouseEvent *)
 
void wheelEvent (QWheelEvent *)
 
void valueChangedEvent ()
 Value changed event which is emitted on changed value. More...
 
void rangeChangedEvent ()
 Handler to emit rangeChanged signal in derived widgets. More...
 
- Protected Member Functions inherited from omni::ui::AbstractInputWidget
virtual void mouseDoubleClickEvent (QMouseEvent *)
 Show editor on double click. More...
 
void drawHandle (QPainter &_p, double _pos, double _heightFactor=1.0) const
 Draw slider handle. More...
 
void drawTrack (QPainter &_p, double _pos) const
 
void drawTrack (QPainter &_p, double _left, double _right) const
 
void init ()
 
- Protected Member Functions inherited from omni::ui::Widget
void drawBorder (QPainter &)
 
void drawBorder (QPainter &, bool _focus)
 
- Protected Member Functions inherited from omni::ui::mixin::Editor< AbstractInputWidget, QWidget >
 Editor (widget_type *_widget)
 
T * createEditor ()
 Create editor with type. More...
 
editor_type const * editor () const
 Return pointer editor (const version) More...
 
editor_typeeditor ()
 Return pointer editor. More...
 
T * editorAs ()
 Return editor as type T. More...
 
T const * editorAs () const
 Return editor as type T (const version) More...
 
virtual void setEditorVisible (bool _visible)
 Set editor visibility and set focus. More...
 
void showEditor ()
 Show editor and set focus. More...
 
void hideEditor ()
 Hide editor. More...
 
- Protected Member Functions inherited from omni::ui::mixin::RangedValue< RangedInt, int >
void apply (WIDGET *_widget) const
 Apply ranged value to widget. More...
 
void for_each_step (F f)
 Functor to apply for each step. More...
 
void validate ()
 Validate minimum, maximum and value. More...
 
- Protected Member Functions inherited from omni::ui::mixin::Range< int >
void apply (WIDGET *_widget) const
 Apply range to widget. More...
 
void apply (WIDGET *_widget, V _value) const
 Applay range to widget and set value. More...
 
- Protected Member Functions inherited from omni::ui::mixin::Step< int >
void for_each_step (MIN _min, MAX _max, F f)
 Functor to be applied for each step between min and maximum. More...
 

Private Member Functions

void init ()
 
void editorSetup ()
 
int valueFromPos (double) const
 
int valueToPos () const
 
double valueToPos (int) const
 Calculate position from value. More...
 

Private Attributes

bool drawTicks_ = true
 
bool useDefaultValue_ = false
 
bool moving_ = false
 

Additional Inherited Members

- Protected Types inherited from omni::ui::mixin::Editor< AbstractInputWidget, QWidget >
typedef AbstractInputWidget widget_type
 Widget type. More...
 
typedef QWidget editor_type
 Editor widget type, e.g. QDoubleSpinBox. More...
 
- Protected Attributes inherited from omni::ui::AbstractInputWidget
QLabel * valueLabel_ = nullptr
 
- Protected Attributes inherited from omni::ui::Widget
QLabel * label_
 

Detailed Description

Integer slider.

Member Typedef Documentation

Constructor & Destructor Documentation

omni::ui::RangedInt::RangedInt ( QWidget *  _parent = nullptr)
30  :
31  AbstractInputWidget(_parent)
32  {
33  init();
34  }
void init()
Definition: RangedInt.cpp:219
AbstractInputWidget(QWidget *=nullptr)
Definition: AbstractInputWidget.cpp:28
omni::ui::RangedInt::RangedInt ( QString const &  _label,
int  _value,
int  _min,
int  _max,
QWidget *  _parent = nullptr 
)
37  :
38  AbstractInputWidget(_parent),
39  mixin_range_type(_value, _min, _max)
40  {
41  setLabel(_label);
42  init();
43  }
void init()
Definition: RangedInt.cpp:219
mixin::RangedValue< RangedInt, int > mixin_range_type
Definition: RangedInt.h:36
void setLabel(QString const &)
Set label text of widget.
Definition: Widget.cpp:50
AbstractInputWidget(QWidget *=nullptr)
Definition: AbstractInputWidget.cpp:28
omni::ui::RangedInt::~RangedInt ( )
46  {}

Member Function Documentation

bool omni::ui::RangedInt::drawTicks ( ) const
83  {
84  return drawTicks_;
85  }
bool drawTicks_
Definition: RangedInt.h:88
void omni::ui::RangedInt::editorSetup ( )
privatevirtual

Implements omni::ui::mixin::Editor< AbstractInputWidget, QWidget >.

225  {
226  auto _editor = this->editorAs<editor_type>();
227 
228  connect(_editor, SIGNAL(valueChanged(int)), this,
229  SLOT(setValue(int)));
230  _editor->setFrame(false);
231  _editor->setAlignment(Qt::AlignRight);
232  _editor->setButtonSymbols(QAbstractSpinBox::PlusMinus);
233  mixin_range_type::apply(_editor);
235  }
void setValue(int)
Definition: RangedInt.cpp:48
void apply(WIDGET *_widget) const
Apply ranged value to widget.
Definition: RangedValue.h:136
void valueChangedEvent()
Value changed event which is emitted on changed value.
Definition: RangedInt.cpp:93
void omni::ui::RangedInt::init ( )
private
220  {
221  setSingleStep(1.0);
222  AbstractInputWidget::createEditor<editor_type>();
223  }
void setSingleStep(value_type _singleStep)
Set new single step value.
Definition: Step.h:79
void omni::ui::RangedInt::keyPressEvent ( QKeyEvent *  e)
protectedvirtual

Show editor when enter key is pressed.

Reimplemented from omni::ui::AbstractInputWidget.

166  {
167  float _step = pageStep();
168 
169  if (_event->modifiers() & Qt::ShiftModifier) {
170  _step = singleStep();
171  }
172  if (_event->modifiers() & Qt::ControlModifier) {
173  _step *= 10.0;
174  }
175 
176  if (_event->key() == Qt::Key_Left) {
177  setValue(value() - _step);
178  }
179  if (_event->key() == Qt::Key_Right) {
180  setValue(value() + _step);
181  }
182  }
value_type value() const
Return value.
Definition: RangedValue.h:65
value_type pageStep() const
Return value for page step.
Definition: Step.h:73
void setValue(int)
Definition: RangedInt.cpp:48
value_type singleStep() const
Return value for single step.
Definition: Step.h:67
void omni::ui::RangedInt::mouseMoveEvent ( QMouseEvent *  e)
protected
185  {
186  if (moving_)
187  {
188  setValue(valueFromPos(e->pos().x()));
189  }
190  }
bool moving_
Definition: RangedInt.h:90
void setValue(int)
Definition: RangedInt.cpp:48
int valueFromPos(double) const
Definition: RangedInt.cpp:108
void omni::ui::RangedInt::mousePressEvent ( QMouseEvent *  )
protectedvirtual

Hide editor and set focus on click.

Reimplemented from omni::ui::AbstractInputWidget.

193  {
195 
196  if (abs(e->pos().x() - valueToPos()) <= 4)
197  {
198  moving_ = true;
199  }
200  }
bool moving_
Definition: RangedInt.h:90
virtual void mousePressEvent(QMouseEvent *)
Hide editor and set focus on click.
Definition: AbstractInputWidget.cpp:68
int valueToPos() const
Definition: RangedInt.cpp:114
void omni::ui::RangedInt::mouseReleaseEvent ( QMouseEvent *  e)
protected
203  {
204  moving_ = false;
205  }
bool moving_
Definition: RangedInt.h:90
void omni::ui::RangedInt::paintEvent ( QPaintEvent *  _paintEvent)
protected
128  {
129  QStylePainter _p(this);
130 
131  _p.setRenderHint(QPainter::Antialiasing);
132  QStyleOption _option;
133  _option.initFrom(this);
134 
135  double _pos = valueToPos();
136 
138  valueToPos(
139  defaultValue()),
140  0.5);
141 
142 
144 
145  if (drawTicks())
146  {
147  mixin_range_type::for_each_step([&](int _step, double i,
148  bool _isPage)
149  {
150  _p.setPen(QPen(i >= mixin_range_type::value() ?
151  colorSet().shadow() :
152  colorSet().windowText(), 1));
153 
154  double _pos = valueToPos(i);
155  double _sizeFactor = _isPage ? 0.3 : 0.15;
156  _p.drawLine(
157  QPointF(_pos,
158  rect().bottom() - rect().height() * _sizeFactor),
159  QPointF(_pos, rect().bottom()));
160  });
161  }
163  hasFocus() || editor()->hasFocus());
164  }
editor_type const * editor() const
Return pointer editor (const version)
Definition: Editor.h:58
value_type value() const
Return value.
Definition: RangedValue.h:65
void drawBorder(QPainter &)
Definition: Widget.cpp:79
bool drawTicks() const
Definition: RangedInt.cpp:82
void drawHandle(QPainter &_p, double _pos, double _heightFactor=1.0) const
Draw slider handle.
Definition: AbstractInputWidget.cpp:87
bool useDefaultValue() const
Return flag if default value is used.
Definition: RangedInt.cpp:71
ColorSet const & colorSet() const
Definition: Widget.cpp:56
value_type defaultValue() const
Return default value.
Definition: RangedValue.h:71
int valueToPos() const
Definition: RangedInt.cpp:114
void for_each_step(F f)
Functor to apply for each step.
Definition: RangedValue.h:145
void drawTrack(QPainter &_p, double _pos) const
Definition: AbstractInputWidget.cpp:119
void omni::ui::RangedInt::rangeChanged ( )
signal
void omni::ui::RangedInt::rangeChangedEvent ( )
protectedvirtual

Handler to emit rangeChanged signal in derived widgets.

Reimplemented from omni::ui::mixin::Range< int >.

103  {
104  mixin_range_type::apply(editorAs<editor_type>());
105  emit rangeChanged();
106  }
void apply(WIDGET *_widget) const
Apply ranged value to widget.
Definition: RangedValue.h:136
void omni::ui::RangedInt::setDrawTicks ( bool  _ticks)
slot
88  {
89  drawTicks_ = _ticks;
90  update();
91  }
bool drawTicks_
Definition: RangedInt.h:88
void omni::ui::RangedInt::setEditorVisible ( bool  _visible)
slot
214  {
216  mixin_range_type::apply(editorAs<editor_type>());
217  }
virtual void setEditorVisible(bool)
Set editor visible.
Definition: AbstractInputWidget.cpp:45
void apply(WIDGET *_widget) const
Apply ranged value to widget.
Definition: RangedValue.h:136
void omni::ui::RangedInt::setMaximum ( int  _max)
slot
62  {
64  }
void setMaximum(value_type _maximum)
Set new maximum value and value and emit rangeChanged event.
Definition: Range.h:80
void omni::ui::RangedInt::setMinimum ( int  _min)
slot
57  {
59  }
void setMinimum(value_type _minimum)
Set new minimum value and value and emit rangeChanged event.
Definition: Range.h:66
void omni::ui::RangedInt::setRange ( int  _min,
int  _max 
)
slot
67  {
68  mixin_range_type::setRange(_min, _max);
69  }
void setRange(value_type _minimum, value_type _maximum)
Set range and validate.
Definition: Range.h:94
void omni::ui::RangedInt::setUseDefaultValue ( bool  _defaultValue)
slot

Use Default Value and show it.

77  {
78  useDefaultValue_ = _defaultValue;
79  update();
80  }
bool useDefaultValue_
Definition: RangedInt.h:89
void omni::ui::RangedInt::setValue ( int  _value)
slot
49  {
51  emit valueChanged();
52 
53  update();
54  }
void setValue(value_type _value)
Set new value and emit value changed event.
Definition: RangedValue.h:105
bool omni::ui::RangedInt::useDefaultValue ( ) const

Return flag if default value is used.

72  {
73  return useDefaultValue_;
74  }
bool useDefaultValue_
Definition: RangedInt.h:89
void omni::ui::RangedInt::valueChanged ( )
signal
void omni::ui::RangedInt::valueChangedEvent ( )
protectedvirtual

Value changed event which is emitted on changed value.

Reimplemented from omni::ui::mixin::RangedValue< RangedInt, int >.

94  {
95  mixin_range_type::apply(editorAs<editor_type>());
96  AbstractInputWidget::valueLabel_->setText(QString("%1").arg(value()));
97 
98  update();
99  emit valueChanged();
100  }
value_type value() const
Return value.
Definition: RangedValue.h:65
void apply(WIDGET *_widget) const
Apply ranged value to widget.
Definition: RangedValue.h:136
QLabel * valueLabel_
Definition: AbstractInputWidget.h:78
int omni::ui::RangedInt::valueFromPos ( double  _pos) const
private
109  {
110  auto && _rect = rect();
111  return (_pos - _rect.left()) / _rect.width() * range() + minimum();
112  }
value_type range() const
Return range (difference between maximum and minimum)
Definition: Range.h:49
value_type minimum() const
Return minimum value.
Definition: Range.h:54
int omni::ui::RangedInt::valueToPos ( ) const
private
115  {
116  auto && _rect = rect();
117  return _rect.left() + ratio() * float(_rect.width());
118  }
qreal ratio() const
Returns ratio of current value.
Definition: RangedValue.h:59
double omni::ui::RangedInt::valueToPos ( int  _value) const
private

Calculate position from value.

121  {
122  auto && _rect = rect();
123  return _rect.left() + mixin::Range<int>::ratio(_value) *
124  double(_rect.width());
125  }
qreal ratio(value_type _v) const
Return ratio of value v.
Definition: Range.h:43
void omni::ui::RangedInt::wheelEvent ( QWheelEvent *  e)
protected
208  {
209  if (hasFocus()) setValue(
210  value() + e->delta() / 15.0 / 8.0 * singleStep());
211  }
value_type value() const
Return value.
Definition: RangedValue.h:65
void setValue(int)
Definition: RangedInt.cpp:48
value_type singleStep() const
Return value for single step.
Definition: Step.h:67

Field Documentation

bool omni::ui::RangedInt::drawTicks_ = true
private
bool omni::ui::RangedInt::moving_ = false
private
bool omni::ui::RangedInt::useDefaultValue_ = false
private

The documentation for this class was generated from the following files: