TSI_Config/rangeslider.h

49 lines
1.3 KiB
C
Raw Normal View History

2025-04-17 14:06:21 +08:00
#ifndef RANGESLIDER_H
#define RANGESLIDER_H
#include <QWidget>
class RangeSlider : public QWidget {
Q_OBJECT
public:
2025-04-19 16:25:33 +08:00
explicit RangeSlider(int style_ = 0,QWidget *parent = nullptr);
2025-04-17 14:06:21 +08:00
void setRange(int min, int max);
void setSliderWidth(int width); // 新增方法:设置宽度
float lowerValue() const;
float upperValue() const;
void setLowerValue(float val);
void setUpperValue(float val);
float m_lower = 3.5;
float m_upper = 6.5;
2025-04-19 16:25:33 +08:00
int style = 0;
2025-04-17 14:06:21 +08:00
signals:
void rangeChanged(float lower, float upper);
protected:
void paintEvent(QPaintEvent *) override;
void mousePressEvent(QMouseEvent *) override;
void mouseMoveEvent(QMouseEvent *) override;
void mouseReleaseEvent(QMouseEvent *) override;
private:
float m_min = 0;
float m_max = 10;
2025-04-19 16:25:33 +08:00
int sliderWidth = 10; // 默认宽度(可以根据需求调整)
2025-04-17 14:06:21 +08:00
int handleRadius = 8;
enum HandleType { NoHandle, LowerHandle, UpperHandle };
HandleType currentHandle = NoHandle;
float valueToY(float value) const;
float yToValue(float y) const;
HandleType handleHitTest(float y) const;
2025-04-19 16:25:33 +08:00
int niceStep(int range, int maxLabels);
2025-04-17 14:06:21 +08:00
void drawTicks(QPainter *p);
void drawTemperatureStyle(QPainter *p);
};
#endif // RANGESLIDER_H