Tracing: Fix assert when wheel zooming

The wheel handling code was triggering an assert in qBound when
calculating the newStart, when using a touch pad.

Rewrite the wheel handling to get rid of the assert and make it more
similar to the text editor wheel handling.

Change-Id: I0c1306d00be6b3054fb8dba9628b7758880675b0
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Eike Ziller
2023-09-11 15:13:36 +02:00
parent 305a1a6ed1
commit 5d02b4df71

View File

@@ -183,23 +183,28 @@ void TimelineRenderer::wheelEvent(QWheelEvent *event)
// ctrl-wheel means zoom // ctrl-wheel means zoom
if (event->modifiers() & Qt::ControlModifier) { if (event->modifiers() & Qt::ControlModifier) {
event->setAccepted(true); event->setAccepted(true);
if (event->angleDelta().y() == 0)
return;
TimelineZoomControl *zoom = zoomer(); TimelineZoomControl *zoom = zoomer();
int degrees = (event->angleDelta().x() + event->angleDelta().y()) / 8; // Handle similar to text editor, but avoid floats.
const qint64 circle = 360; // angleDelta of 120 is considered a 10% change in zoom.
qint64 mouseTime = event->position().toPoint().x() * zoom->windowDuration() / width() + const qint64 delta = event->angleDelta().y();
zoom->windowStart(); const qint64 newDuration = qBound(zoom->minimumRangeLength(),
qint64 beforeMouse = (mouseTime - zoom->rangeStart()) * (circle - degrees) / circle; zoom->rangeDuration() * 1200 / (1200 + delta),
qint64 afterMouse = (zoom->rangeEnd() - mouseTime) * (circle - degrees) / circle; std::max(zoom->minimumRangeLength(),
zoom->traceDuration()));
qint64 newStart = qBound(zoom->traceStart(), zoom->traceEnd(), mouseTime - beforeMouse); const qint64 mouseTime = event->position().toPoint().x() * zoom->windowDuration() / width()
if (newStart + zoom->minimumRangeLength() > zoom->traceEnd()) + zoom->windowStart();
return; // too close to trace end // Try to keep mouseTime where it was in relation to the shown range,
// but keep within traceStart/End
qint64 newEnd = qBound(newStart + zoom->minimumRangeLength(), zoom->traceEnd(), const qint64 newStart
mouseTime + afterMouse); = qBound(zoom->traceStart(),
mouseTime
zoom->setRange(newStart, newEnd); - newDuration * /*rest is mouse time position [0,1] in range:*/
(mouseTime - zoom->rangeStart()) / zoom->rangeDuration(),
std::max(zoom->traceStart(), zoom->traceEnd() - newDuration));
zoom->setRange(newStart, newStart + newDuration);
} else { } else {
TimelineAbstractRenderer::wheelEvent(event); TimelineAbstractRenderer::wheelEvent(event);
} }