OpenHantek
levelslider.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0+
2 
3 #pragma once
4 
5 #include <QWidget>
6 
7 class QColor;
8 
11  QColor color;
12  QString text;
13  bool visible;
14 
15  double minimum;
16  double maximum;
17  double step;
18  double value;
19 
20  // Needed for moving and drawing
21  QRect rect;
22 };
23 
28 class LevelSlider : public QWidget {
29  Q_OBJECT
30 
31  public:
32  LevelSlider( Qt::ArrowType direction = Qt::RightArrow, QWidget *parent = nullptr );
33  ~LevelSlider();
34 
35  QSize sizeHint() const;
36 
37  int preMargin() const;
38  int postMargin() const;
39 
40  int addSlider( int index = -1 );
41  int addSlider( const QString &text, int index = -1 );
42  int removeSlider( int index = -1 );
43 
44  // Parameters for a specific slider
45  const QColor color( int index ) const;
46  void setColor( unsigned index, QColor color );
47  const QString text( int index ) const;
48  int setText( int index, const QString &text );
49  bool visible( int index ) const;
50  void setIndexVisible( unsigned index, bool visible );
51 
52  double minimum( int index ) const;
53  double maximum( int index ) const;
54  void setLimits( int index, double minimum, double maximum );
55  double step( int index ) const;
56  double setStep( int index, double step );
57  double value( int index ) const;
58  void setValue( int index, double value );
59 
60  // Parameters for all sliders
61  Qt::ArrowType direction() const;
62  int setDirection( Qt::ArrowType direction );
63 
64  protected:
65  void mouseMoveEvent( QMouseEvent *event );
66  void mousePressEvent( QMouseEvent *event );
67  void mouseReleaseEvent( QMouseEvent *event );
68 
69  void paintEvent( QPaintEvent *event );
70  void resizeEvent( QResizeEvent *event );
71 
72  QRect calculateRect( int sliderId );
73  int calculateWidth();
74  void fixValue( int index );
75 
76  QList< LevelSliderParameters * > slider;
79  int needleWidth;
81 
82  Qt::ArrowType _direction;
83  int _preMargin;
85 
86  signals:
87  void valueChanged( int index, double value, bool pressed = false );
88 };
double step
The distance between selectable slider positions.
Definition: levelslider.h:17
LevelSlider(Qt::ArrowType direction=Qt::RightArrow, QWidget *parent=nullptr)
Initializes the slider container.
Definition: levelslider.cpp:37
double step(int index) const
Return the step width of the sliders.
Definition: levelslider.cpp:231
void mouseReleaseEvent(QMouseEvent *event)
Movement is done if the left mouse button is released.
Definition: levelslider.cpp:360
int preMargin() const
Return the margin before the slider.
Definition: levelslider.cpp:53
int setDirection(Qt::ArrowType direction)
Set the direction of the sliders.
Definition: levelslider.cpp:288
QString text
The text beside the slider, a empty string disables text.
Definition: levelslider.h:12
double maximum
Maximum (right/bottom) value for the slider.
Definition: levelslider.h:16
~LevelSlider()
Cleans up the widget.
Definition: levelslider.cpp:49
void mouseMoveEvent(QMouseEvent *event)
Move the slider if it&#39;s pressed.
Definition: levelslider.cpp:307
QColor color
The color of the slider and font.
Definition: levelslider.h:11
int setText(int index, const QString &text)
Set the text for a slider.
Definition: levelslider.cpp:154
Slider widget for multiple level sliders. These are used for the trigger levels, offsets and so on...
Definition: levelslider.h:28
const QString text(int index) const
Return the text shown beside a slider.
Definition: levelslider.cpp:143
double setStep(int index, double step)
Set the step width of the sliders.
Definition: levelslider.cpp:242
const QColor color(int index) const
Return the color of a slider.
Definition: levelslider.cpp:121
void setValue(int index, double value)
Set the current position of a slider.
Definition: levelslider.cpp:266
void fixValue(int index)
Fix the value if it&#39;s outside the limits.
Definition: levelslider.cpp:576
void setLimits(int index, double minimum, double maximum)
Set the min-max values of the sliders, correct the value if changed.
Definition: levelslider.cpp:208
int postMargin() const
Return the margin after the slider.
Definition: levelslider.cpp:57
QRect rect
The area where the slider is drawn.
Definition: levelslider.h:21
int _postMargin
The margin after the maximum slider position.
Definition: levelslider.h:84
int pressedSlider
The currently pressed (moved) slider.
Definition: levelslider.h:77
double minimum
Minimum (left/top) value for the slider.
Definition: levelslider.h:15
int sliderWidth
Definition: levelslider.h:78
QSize sizeHint() const
Size hint for the widget.
Definition: levelslider.cpp:111
int _preMargin
The margin before the minimum slider position.
Definition: levelslider.h:83
int needleWidth
Width of the needle (parallel to sliding direction)
Definition: levelslider.h:80
double value(int index) const
Return the current position of a slider.
Definition: levelslider.cpp:255
int removeSlider(int index=-1)
Remove a slider from the slider container.
Definition: levelslider.cpp:93
void mousePressEvent(QMouseEvent *event)
Prepare slider for movement if the left mouse button is pressed.
Definition: levelslider.cpp:338
void resizeEvent(QResizeEvent *event)
Resize the widget and adapt the slider positions.
Definition: levelslider.cpp:472
Qt::ArrowType direction() const
Return the direction of the sliders.
Definition: levelslider.cpp:283
QList< LevelSliderParameters *> slider
The parameters for each slider.
Definition: levelslider.h:76
Contains the color, text and value of one slider.
Definition: levelslider.h:10
int addSlider(int index=-1)
Add a new slider to the slider container.
Definition: levelslider.cpp:62
void valueChanged(int index, double value, bool pressed=false)
The value of a slider has changed.
Qt::ArrowType _direction
The direction the sliders point to.
Definition: levelslider.h:82
void paintEvent(QPaintEvent *event)
Paint the widget.
Definition: levelslider.cpp:373
double maximum(int index) const
Return the maximal value of the sliders.
Definition: levelslider.cpp:197
double value
The current value of the slider.
Definition: levelslider.h:18
double minimum(int index) const
Return the minimal value of the sliders.
Definition: levelslider.cpp:188
int calculateWidth()
Search for the widest slider element.
Definition: levelslider.cpp:553
void setColor(unsigned index, QColor color)
Set the color of the slider.
Definition: levelslider.cpp:132
bool visible(int index) const
Return the visibility of a slider.
Definition: levelslider.cpp:167
void setIndexVisible(unsigned index, bool visible)
Set the visibility of a slider.
Definition: levelslider.cpp:178
QRect calculateRect(int sliderId)
Calculate the drawing area for the slider for it&#39;s current value.
Definition: levelslider.cpp:484
bool visible
Visibility of the slider.
Definition: levelslider.h:13