fixed scrollbar thumb not moving

This commit is contained in:
fourtf 2020-04-21 20:57:16 +02:00
parent 354ad6a362
commit 370e6dc61b

View file

@ -276,8 +276,7 @@ void Scrollbar::paintEvent(QPaintEvent *)
int w = this->width(); int w = this->width();
float y = 0; float y = 0;
float dY = float dY = float(this->height()) / float(snapshotLength);
float(this->height()) / std::max<float>(1.0f, float(snapshotLength));
int highlightHeight = int highlightHeight =
int(std::ceil(std::max<float>(this->scale() * 2, dY))); int(std::ceil(std::max<float>(this->scale() * 2, dY)));
@ -357,10 +356,10 @@ void Scrollbar::mouseMoveEvent(QMouseEvent *event)
{ {
int delta = event->pos().y() - this->lastMousePosition_.y(); int delta = event->pos().y() - this->lastMousePosition_.y();
setDesiredValue( setDesiredValue(this->desiredValue_ +
this->desiredValue_ + qreal(delta) /
qreal(delta) / std::max<qreal>(0.00000002, this->trackHeight_ *
std::max<qreal>(0.02, this->trackHeight_ * this->maximum_)); this->maximum_));
} }
this->lastMousePosition_ = event->pos(); this->lastMousePosition_ = event->pos();
@ -445,11 +444,14 @@ void Scrollbar::updateScroll()
this->trackHeight_ = this->height() - this->buttonHeight_ - this->trackHeight_ = this->height() - this->buttonHeight_ -
this->buttonHeight_ - MIN_THUMB_HEIGHT - 1; this->buttonHeight_ - MIN_THUMB_HEIGHT - 1;
auto div = std::max<qreal>(0.01, this->maximum_ * this->trackHeight_); auto div = std::max<qreal>(0.0000001, this->maximum_);
this->thumbRect_ = this->thumbRect_ = QRect(
QRect(0, int(this->currentValue_ / div) + 1 + this->buttonHeight_, 0,
this->width(), int(this->largeChange_ / div) + MIN_THUMB_HEIGHT); int(this->currentValue_ / div * this->trackHeight_) + 1 +
this->buttonHeight_,
this->width(),
int(this->largeChange_ / div * this->trackHeight_) + MIN_THUMB_HEIGHT);
this->update(); this->update();
} }