when zooming any TimelineViewBase derivative, zoom towards the playhead
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <QGraphicsRectItem>
|
||||
#include <QMouseEvent>
|
||||
#include <QScrollBar>
|
||||
#include <QTimer>
|
||||
|
||||
#include "common/timecodefunctions.h"
|
||||
|
||||
@@ -31,12 +32,16 @@ void TimelineViewBase::SetScale(const double &scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
|
||||
// Force redraw for playhead
|
||||
viewport()->update();
|
||||
|
||||
end_item_->SetScale(scale_);
|
||||
|
||||
ScaleChangedEvent(scale_);
|
||||
|
||||
// Force redraw for playhead
|
||||
viewport()->update();
|
||||
|
||||
// Zoom towards the playhead
|
||||
// (using a hacky singleShot so the scroll occurs after the scene and its scrollbars have updated)
|
||||
QTimer::singleShot(0, this, &TimelineViewBase::CenterScrollOnPlayhead);
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetTimebase(const rational &timebase)
|
||||
@@ -62,7 +67,7 @@ void TimelineViewBase::drawForeground(QPainter *painter, const QRectF &rect)
|
||||
if (!timebase().isNull()) {
|
||||
double width = TimeToScene(timebase());
|
||||
|
||||
playhead_scene_left_ = TimeToScene(rational(playhead_ * timebase().numerator(), timebase().denominator()));
|
||||
playhead_scene_left_ = GetPlayheadX();
|
||||
playhead_scene_right_ = playhead_scene_left_ + width;
|
||||
|
||||
playhead_style_.Draw(painter, QRectF(playhead_scene_left_, rect.top(), width, rect.height()));
|
||||
@@ -105,6 +110,11 @@ bool TimelineViewBase::PlayheadRelease(QMouseEvent *event)
|
||||
return dragging_playhead_;
|
||||
}
|
||||
|
||||
qreal TimelineViewBase::GetPlayheadX()
|
||||
{
|
||||
return TimeToScene(rational(playhead_ * timebase().numerator(), timebase().denominator()));
|
||||
}
|
||||
|
||||
void TimelineViewBase::SetEndTime(const rational &length)
|
||||
{
|
||||
end_item_->SetEndTime(length);
|
||||
@@ -157,6 +167,11 @@ void TimelineViewBase::UpdateSceneRect()
|
||||
scene_.setSceneRect(bounding_rect);
|
||||
}
|
||||
|
||||
void TimelineViewBase::CenterScrollOnPlayhead()
|
||||
{
|
||||
horizontalScrollBar()->setValue(qRound(GetPlayheadX()) - viewport()->width()/2);
|
||||
}
|
||||
|
||||
void TimelineViewBase::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
QGraphicsView::resizeEvent(event);
|
||||
|
||||
@@ -43,6 +43,8 @@ protected:
|
||||
bool PlayheadRelease(QMouseEvent* event);
|
||||
|
||||
private:
|
||||
qreal GetPlayheadX();
|
||||
|
||||
int64_t playhead_;
|
||||
|
||||
TimelinePlayhead playhead_style_;
|
||||
@@ -64,6 +66,11 @@ private slots:
|
||||
*/
|
||||
void UpdateSceneRect();
|
||||
|
||||
/**
|
||||
* @brief Slot to center the horizontal scroll bar on the playhead's current position
|
||||
*/
|
||||
void CenterScrollOnPlayhead();
|
||||
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWBASE_H
|
||||
|
||||
Reference in New Issue
Block a user