Files
Renderive/YSGraphic_Core/component/Table/scroll.h
T
2026-06-16 13:33:27 +08:00

75 lines
1.7 KiB
C++

#pragma once
#include <QColor>
#include <QPainter>
#include <QRect>
namespace Psc {
class Base_ScrollBar {
public:
// 距离控件起点的位置
int start = 0;
double get_view_pos() {
return this->_view_pos;
}
void set_view_pos(int view_pos) {
this->_view_pos = view_pos;
}
void resize(int bar_len, int view_len, int owner_len) {
this->_bar_len = bar_len;
this->view_len = view_len;
this->owner_len = owner_len;
}
bool show = true;
QColor background_color = Qt::gray;
QColor slider_color = Qt::black;
protected:
// 主位置情况
double owner_len = 1;
double _view_pos = 0;
double view_len = 1;
// 滚动条位置情况
double _bar_len = 1; //滚动条长度
public:
double rate() {
return _bar_len / owner_len;
}
double bar_len() {
return _bar_len;
}
double pos() {
return _view_pos * _bar_len / owner_len;
}
double view_pos() {
return _view_pos;
}
double slider_len() {
return view_len * _bar_len / owner_len;
}
};
// 向下
class V_ScrollBar : public Base_ScrollBar {
public:
double w = 8;
void draw(QPainter* painter);
QRect get_slider_rect(int ww, int hh);
QRect get_bar_rect(int ww, int hh);
};
// 向下
class H_ScrollBar : public Base_ScrollBar {
public:
double h = 8;
void draw(QPainter* painter);
QRect get_slider_rect(int ww, int hh);
QRect get_bar_rect(int ww, int hh);
};
}