25 #include <QStylePainter> 27 #include <tulip/tulipconf.h> 38 class TLP_QT_SCOPE RangeSlider :
public QSlider {
40 Q_PROPERTY(
int lowerValue READ lowerValue WRITE setLowerValue)
41 Q_PROPERTY(
int upperValue READ upperValue WRITE setUpperValue)
43 HandleMovementMode handleMovementMode READ handleMovementMode WRITE setHandleMovementMode)
44 Q_ENUMS(HandleMovementMode)
47 explicit RangeSlider(QWidget *parent =
nullptr);
48 explicit RangeSlider(Qt::Orientation orientation, QWidget *parent =
nullptr);
49 ~RangeSlider()
override {}
51 enum HandleMovementMode { FreeMovement, NoCrossing, NoOverlapping };
53 HandleMovementMode handleMovementMode()
const;
54 void setHandleMovementMode(HandleMovementMode mode);
56 int lowerValue()
const;
57 int upperValue()
const;
59 int lowerPosition()
const;
60 int upperPosition()
const;
63 void setLowerValue(
int lower);
64 void setUpperValue(
int upper);
65 void setRange(
int lower,
int upper);
67 void setLowerPosition(
int lower);
68 void setUpperPosition(
int upper);
71 void rangeChanged(
int lower,
int upper);
72 void lowerValueChanged(
int lower);
73 void upperValueChanged(
int upper);
75 void lowerPositionChanged(
int lower);
76 void upperPositionChanged(
int upper);
79 void keyPressEvent(QKeyEvent *event)
override;
80 void mousePressEvent(QMouseEvent *event)
override;
81 void mouseMoveEvent(QMouseEvent *event)
override;
82 void mouseReleaseEvent(QMouseEvent *event)
override;
83 void paintEvent(QPaintEvent *event)
override;
86 enum RangeHandle { NoHandle, LowerHandle, UpperHandle };
88 Q_PROPERTY(
int lowerPosition READ lowerPosition WRITE setLowerPosition)
89 Q_PROPERTY(
int upperPosition READ upperPosition WRITE setUpperPosition)
91 void initStyleOption(QStyleOptionSlider *option, RangeHandle handle = UpperHandle)
const;
92 int pick(
const QPoint &pt)
const {
93 return orientation() == Qt::Horizontal ? pt.x() : pt.y();
95 int pixelPosToRangeValue(
int pos)
const;
96 void handleMousePress(
const QPoint &pos, QStyle::SubControl &control,
int value,
98 void drawHandle(QStylePainter *painter, RangeHandle handle)
const;
99 void setupPainter(QPainter *painter, Qt::Orientation orientation, qreal x1, qreal y1, qreal x2,
101 void drawRange(QStylePainter *painter,
const QRect &rect)
const;
102 void triggerAction(QAbstractSlider::SliderAction action,
bool main);
111 RangeHandle lastPressed;
112 RangeHandle mainControl;
113 QStyle::SubControl lowerPressed;
114 QStyle::SubControl upperPressed;
115 HandleMovementMode movement;
120 void updateRange(
int min,
int max);
121 void movePressedHandle();
125 #endif // RANGESLIDER_H