various: moved time from viewer UI to viewer node

This commit is contained in:
itsmattkc
2022-10-23 20:56:04 -07:00
parent fc56058e8a
commit d1545745d8
47 changed files with 259 additions and 418 deletions
+26 -15
View File
@@ -38,7 +38,8 @@ TimeBasedView::TimeBasedView(QWidget *parent) :
snapped_(false),
snap_service_(nullptr),
y_axis_enabled_(false),
y_scale_(1.0)
y_scale_(1.0),
viewer_(nullptr)
{
// Sets scene to our scene
setScene(&scene_);
@@ -142,12 +143,17 @@ void TimeBasedView::SetYScale(const double &y_scale)
}
}
void TimeBasedView::SetTime(const rational &time)
void TimeBasedView::SetViewerNode(ViewerOutput *v)
{
playhead_ = time;
if (viewer_) {
disconnect(viewer_, &ViewerOutput::PlayheadChanged, viewport(), static_cast<void(QWidget::*)()>(&TimeBasedView::update));
}
// Force redraw for playhead
viewport()->update();
viewer_ = v;
if (viewer_) {
connect(viewer_, &ViewerOutput::PlayheadChanged, viewport(), static_cast<void(QWidget::*)()>(&TimeBasedView::update));
}
}
void TimeBasedView::drawForeground(QPainter *painter, const QRectF &rect)
@@ -203,20 +209,21 @@ bool TimeBasedView::PlayheadMove(QMouseEvent *event)
return false;
}
QPointF scene_pos = mapToScene(event->pos());
rational mouse_time = qMax(rational(0), SceneToTime(scene_pos.x()));
if (viewer_) {
QPointF scene_pos = mapToScene(event->pos());
rational mouse_time = qMax(rational(0), SceneToTime(scene_pos.x()));
if (Core::instance()->snapping() && snap_service_) {
rational movement;
if (Core::instance()->snapping() && snap_service_) {
rational movement;
snap_service_->SnapPoint({mouse_time}, &movement, TimeBasedWidget::kSnapAll & ~TimeBasedWidget::kSnapToPlayhead);
snap_service_->SnapPoint({mouse_time}, &movement, TimeBasedWidget::kSnapAll & ~TimeBasedWidget::kSnapToPlayhead);
mouse_time += movement;
mouse_time += movement;
}
viewer_->SetPlayhead(mouse_time);
}
SetTime(mouse_time);
emit TimeChanged(mouse_time);
return true;
}
@@ -237,7 +244,11 @@ bool TimeBasedView::PlayheadRelease(QMouseEvent*)
qreal TimeBasedView::GetPlayheadX()
{
return TimeToScene(playhead_);
if (viewer_) {
return TimeToScene(viewer_->GetPlayhead());
} else {
return 0;
}
}
void TimeBasedView::SetEndTime(const rational &length)