Commit 55afbb59 authored by Ulf Hermann's avatar Ulf Hermann

Timeline: Allow zooming with ctrl-wheel

Change-Id: I83f18af8394c9820e07e7bb41a627bf33e98d6c4
Reviewed-by: default avatarMaurice Kalinowski <maurice.kalinowski@theqtcompany.com>
parent 7c410663
......@@ -205,6 +205,33 @@ void TimelineRenderer::hoverMoveEvent(QHoverEvent *event)
event->setAccepted(false);
}
void TimelineRenderer::wheelEvent(QWheelEvent *event)
{
// ctrl-wheel means zoom
if (event->modifiers() & Qt::ControlModifier) {
event->setAccepted(true);
TimelineZoomControl *zoom = zoomer();
int degrees = (event->angleDelta().x() + event->angleDelta().y()) / 8;
const qint64 circle = 360;
qint64 mouseTime = event->pos().x() * zoom->windowDuration() / width() +
zoom->windowStart();
qint64 beforeMouse = (mouseTime - zoom->rangeStart()) * (circle - degrees) / circle;
qint64 afterMouse = (zoom->rangeEnd() - mouseTime) * (circle - degrees) / circle;
qint64 newStart = qBound(zoom->traceStart(), zoom->traceEnd(), mouseTime - beforeMouse);
if (newStart + zoom->minimumRangeLength() > zoom->traceEnd())
return; // too close to trace end
qint64 newEnd = qBound(newStart + zoom->minimumRangeLength(), zoom->traceEnd(),
mouseTime + afterMouse);
zoom->setRange(newStart, newEnd);
} else {
TimelineAbstractRenderer::wheelEvent(event);
}
}
void TimelineRenderer::TimelineRendererPrivate::manageClicked()
{
Q_Q(TimelineRenderer);
......
......@@ -66,6 +66,7 @@ protected:
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void hoverMoveEvent(QHoverEvent *event);
virtual void wheelEvent(QWheelEvent *event);
private:
class TimelineRendererPrivate;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment