Merge branch 'move-time-to-viewer'
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -45,8 +45,6 @@ public:
|
||||
return snapped_;
|
||||
}
|
||||
|
||||
const rational &GetTime() const { return playhead_; }
|
||||
|
||||
TimeBasedWidget *GetSnapService() const { return snap_service_; }
|
||||
void SetSnapService(TimeBasedWidget* service) { snap_service_ = service; }
|
||||
|
||||
@@ -62,9 +60,11 @@ public:
|
||||
virtual void SelectionManagerSelectEvent(void *obj){}
|
||||
virtual void SelectionManagerDeselectEvent(void *obj){}
|
||||
|
||||
public slots:
|
||||
void SetTime(const rational &time);
|
||||
ViewerOutput *GetViewerNode() const { return viewer_; }
|
||||
|
||||
void SetViewerNode(ViewerOutput *v);
|
||||
|
||||
public slots:
|
||||
void SetEndTime(const rational& length);
|
||||
|
||||
/**
|
||||
@@ -73,8 +73,6 @@ public slots:
|
||||
void UpdateSceneRect();
|
||||
|
||||
signals:
|
||||
void TimeChanged(const rational& time);
|
||||
|
||||
void ScaleChanged(double scale);
|
||||
|
||||
protected:
|
||||
@@ -109,8 +107,6 @@ protected:
|
||||
private:
|
||||
qreal GetPlayheadX();
|
||||
|
||||
rational playhead_;
|
||||
|
||||
double playhead_scene_left_;
|
||||
double playhead_scene_right_;
|
||||
|
||||
@@ -129,6 +125,8 @@ private:
|
||||
|
||||
double y_scale_;
|
||||
|
||||
ViewerOutput *viewer_;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ TimeBasedWidget::TimeBasedWidget(bool ruler_text_visible, bool ruler_cache_statu
|
||||
connect(scrollbar_, &ResizableScrollBar::ResizeMoved, this, &TimeBasedWidget::ScrollBarResizeMoved);
|
||||
|
||||
ruler_ = new TimeRuler(ruler_text_visible, ruler_cache_status_visible, this);
|
||||
ConnectTimelineView(ruler_, true);
|
||||
ConnectTimelineView(ruler_);
|
||||
ruler()->SetSnapService(this);
|
||||
connect(ruler(), &TimeRuler::DragReleased, this, static_cast<void(TimeBasedWidget::*)()>(&TimeBasedWidget::StopCatchUpScrollTimer));
|
||||
|
||||
@@ -66,11 +66,6 @@ void TimeBasedWidget::SetScaleAndCenterOnPlayhead(const double &scale)
|
||||
QTimer::singleShot(0, this, &TimeBasedWidget::CenterScrollOnPlayhead);
|
||||
}
|
||||
|
||||
const rational &TimeBasedWidget::GetTime() const
|
||||
{
|
||||
return ruler_->GetTime();
|
||||
}
|
||||
|
||||
ViewerOutput *TimeBasedWidget::GetConnectedNode() const
|
||||
{
|
||||
return viewer_node_;
|
||||
@@ -94,6 +89,7 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
|
||||
// Disconnect length changed signal
|
||||
disconnect(old, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
|
||||
disconnect(old, &ViewerOutput::RemovedFromGraph, this, &TimeBasedWidget::ConnectedNodeRemovedFromGraph);
|
||||
disconnect(old, &ViewerOutput::PlayheadChanged, this, &TimeBasedWidget::PlayheadTimeChanged);
|
||||
|
||||
// Disconnect rate change signals if they were connected
|
||||
disconnect(old, &ViewerOutput::FrameRateChanged, this, &TimeBasedWidget::AutoUpdateTimebase);
|
||||
@@ -108,12 +104,16 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
|
||||
}
|
||||
|
||||
// Call derivatives
|
||||
for (TimeBasedView *view : timeline_views_) {
|
||||
view->SetViewerNode(viewer_node_);
|
||||
}
|
||||
ConnectedNodeChangeEvent(viewer_node_);
|
||||
|
||||
if (viewer_node_) {
|
||||
// Connect length changed signal
|
||||
connect(viewer_node_, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
|
||||
connect(viewer_node_, &ViewerOutput::RemovedFromGraph, this, &TimeBasedWidget::ConnectedNodeRemovedFromGraph);
|
||||
connect(viewer_node_, &ViewerOutput::PlayheadChanged, this, &TimeBasedWidget::PlayheadTimeChanged);
|
||||
|
||||
// Connect ruler and scrollbar to timeline points
|
||||
ConnectWorkArea(viewer_node_->GetWorkArea());
|
||||
@@ -207,12 +207,16 @@ void TimeBasedWidget::ScrollBarResizeMoved(int movement)
|
||||
|
||||
void TimeBasedWidget::PageScrollToPlayhead()
|
||||
{
|
||||
PageScrollInternal(qRound(TimeToScene(GetTime())), true);
|
||||
if (GetConnectedNode()) {
|
||||
PageScrollInternal(qRound(TimeToScene(GetConnectedNode()->GetPlayhead())), true);
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::CatchUpScrollToPlayhead()
|
||||
{
|
||||
CatchUpScrollToPoint(qRound(TimeToScene(GetTime())));
|
||||
if (GetConnectedNode()) {
|
||||
CatchUpScrollToPoint(qRound(TimeToScene(GetConnectedNode()->GetPlayhead())));
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::CatchUpScrollToPoint(int point)
|
||||
@@ -298,12 +302,8 @@ void TimeBasedWidget::resizeEvent(QResizeEvent *event)
|
||||
UpdateMaximumScroll();
|
||||
}
|
||||
|
||||
void TimeBasedWidget::ConnectTimelineView(TimeBasedView *base, bool connect_time_change_event)
|
||||
void TimeBasedWidget::ConnectTimelineView(TimeBasedView *base)
|
||||
{
|
||||
if (connect_time_change_event) {
|
||||
connect(base, &TimeBasedView::TimeChanged, this, &TimeBasedWidget::SetTimeAndSignal);
|
||||
}
|
||||
|
||||
// Connect scale
|
||||
connect(base, &TimeBasedView::ScaleChanged, this, &TimeBasedWidget::SetScale);
|
||||
|
||||
@@ -350,7 +350,7 @@ void TimeBasedWidget::StopCatchUpScrollTimer(QScrollBar *b)
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::SetTime(const rational &time)
|
||||
void TimeBasedWidget::PlayheadTimeChanged(const rational &time)
|
||||
{
|
||||
if (UserIsDraggingPlayhead()) {
|
||||
// If the user is dragging the playhead, we will simply nudge over and not use autoscroll rules.
|
||||
@@ -370,8 +370,6 @@ void TimeBasedWidget::SetTime(const rational &time)
|
||||
}
|
||||
}
|
||||
|
||||
ruler_->SetTime(time);
|
||||
|
||||
TimeChangedEvent(time);
|
||||
}
|
||||
|
||||
@@ -405,7 +403,7 @@ void TimeBasedWidget::GoToPrevCut()
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetTime().isNull()) {
|
||||
if (GetConnectedNode()->GetPlayhead().isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -415,7 +413,7 @@ void TimeBasedWidget::GoToPrevCut()
|
||||
rational this_track_closest_cut = 0;
|
||||
|
||||
for (Block* block : track->Blocks()) {
|
||||
if (block->out() < GetTime()) {
|
||||
if (block->out() < GetConnectedNode()->GetPlayhead()) {
|
||||
this_track_closest_cut = block->out();
|
||||
} else {
|
||||
break;
|
||||
@@ -425,7 +423,7 @@ void TimeBasedWidget::GoToPrevCut()
|
||||
closest_cut = qMax(closest_cut, this_track_closest_cut);
|
||||
}
|
||||
|
||||
SetTimeAndSignal(closest_cut);
|
||||
GetConnectedNode()->SetPlayhead(closest_cut);
|
||||
}
|
||||
|
||||
void TimeBasedWidget::GoToNextCut()
|
||||
@@ -442,12 +440,12 @@ void TimeBasedWidget::GoToNextCut()
|
||||
for (Track* track : sequence->GetTracks()) {
|
||||
rational this_track_closest_cut = track->track_length();
|
||||
|
||||
if (this_track_closest_cut <= GetTime()) {
|
||||
if (this_track_closest_cut <= GetConnectedNode()->GetPlayhead()) {
|
||||
this_track_closest_cut = RATIONAL_MAX;
|
||||
}
|
||||
|
||||
for (Block* block : track->Blocks()) {
|
||||
if (block->in() > GetTime()) {
|
||||
if (block->in() > GetConnectedNode()->GetPlayhead()) {
|
||||
this_track_closest_cut = block->in();
|
||||
break;
|
||||
}
|
||||
@@ -457,57 +455,51 @@ void TimeBasedWidget::GoToNextCut()
|
||||
}
|
||||
|
||||
if (closest_cut < RATIONAL_MAX) {
|
||||
SetTimeAndSignal(closest_cut);
|
||||
GetConnectedNode()->SetPlayhead(closest_cut);
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::GoToStart()
|
||||
{
|
||||
if (viewer_node_) {
|
||||
SetTimeAndSignal(0);
|
||||
viewer_node_->SetPlayhead(0);
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::PrevFrame()
|
||||
{
|
||||
if (viewer_node_) {
|
||||
rational proposed_time = Timecode::snap_time_to_timebase(GetTime() - timebase(), timebase(), Timecode::kCeil);
|
||||
if (proposed_time == GetTime()) {
|
||||
rational proposed_time = Timecode::snap_time_to_timebase(GetConnectedNode()->GetPlayhead() - timebase(), timebase(), Timecode::kCeil);
|
||||
if (proposed_time == GetConnectedNode()->GetPlayhead()) {
|
||||
// Catch rounding error, assume this time is snapped and just subtract a timebase
|
||||
proposed_time -= timebase();
|
||||
}
|
||||
SetTimeAndSignal(qMax(rational(0), proposed_time));
|
||||
viewer_node_->SetPlayhead(qMax(rational(0), proposed_time));
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::NextFrame()
|
||||
{
|
||||
if (viewer_node_) {
|
||||
rational proposed_time = Timecode::snap_time_to_timebase(GetTime() + timebase(), timebase(), Timecode::kFloor);
|
||||
if (proposed_time == GetTime()) {
|
||||
rational proposed_time = Timecode::snap_time_to_timebase(GetConnectedNode()->GetPlayhead() + timebase(), timebase(), Timecode::kFloor);
|
||||
if (proposed_time == GetConnectedNode()->GetPlayhead()) {
|
||||
// Catch rounding error, assume this time is snapped and just add a timebase
|
||||
proposed_time += timebase();
|
||||
}
|
||||
SetTimeAndSignal(proposed_time);
|
||||
viewer_node_->SetPlayhead(proposed_time);
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::GoToEnd()
|
||||
{
|
||||
if (viewer_node_) {
|
||||
SetTimeAndSignal(viewer_node_->GetLength());
|
||||
viewer_node_->SetPlayhead(viewer_node_->GetLength());
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::SetTimeAndSignal(const rational &t)
|
||||
{
|
||||
SetTime(t);
|
||||
emit TimeChanged(t);
|
||||
}
|
||||
|
||||
void TimeBasedWidget::CenterScrollOnPlayhead()
|
||||
{
|
||||
scrollbar_->setValue(qRound(TimeToScene(ruler_->GetTime())) - scrollbar_->width()/2);
|
||||
scrollbar_->setValue(qRound(TimeToScene(GetConnectedNode()->GetPlayhead())) - scrollbar_->width()/2);
|
||||
}
|
||||
|
||||
void TimeBasedWidget::SetAutoSetTimebase(bool e)
|
||||
@@ -608,10 +600,6 @@ void TimeBasedWidget::PageScrollInternal(int screen_position, bool whole_page_sc
|
||||
|
||||
bool TimeBasedWidget::UserIsDraggingPlayhead() const
|
||||
{
|
||||
if (ruler_->IsDraggingPlayhead()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach (TimeBasedView* view, timeline_views_) {
|
||||
if (view->IsDraggingPlayhead()) {
|
||||
return true;
|
||||
@@ -623,12 +611,12 @@ bool TimeBasedWidget::UserIsDraggingPlayhead() const
|
||||
|
||||
void TimeBasedWidget::SetInAtPlayhead()
|
||||
{
|
||||
SetPoint(Timeline::kTrimIn, GetTime());
|
||||
SetPoint(Timeline::kTrimIn, GetConnectedNode()->GetPlayhead());
|
||||
}
|
||||
|
||||
void TimeBasedWidget::SetOutAtPlayhead()
|
||||
{
|
||||
SetPoint(Timeline::kTrimOut, GetTime());
|
||||
SetPoint(Timeline::kTrimOut, GetConnectedNode()->GetPlayhead());
|
||||
}
|
||||
|
||||
void TimeBasedWidget::ResetIn()
|
||||
@@ -658,14 +646,14 @@ void TimeBasedWidget::SetMarker()
|
||||
|
||||
TimelineMarkerList *markers = GetConnectedNode()->GetMarkers();
|
||||
|
||||
if (TimelineMarker *existing = markers->GetMarkerAtTime(GetTime())) {
|
||||
if (TimelineMarker *existing = markers->GetMarkerAtTime(GetConnectedNode()->GetPlayhead())) {
|
||||
// We already have a marker here, so pop open the edit dialog
|
||||
MarkerPropertiesDialog mpd({existing}, timebase(), this);
|
||||
mpd.exec();
|
||||
} else {
|
||||
// Create a new marker and place it here
|
||||
int color;
|
||||
if (TimelineMarker *closest = markers->GetClosestMarkerToTime(GetTime())) {
|
||||
if (TimelineMarker *closest = markers->GetClosestMarkerToTime(GetConnectedNode()->GetPlayhead())) {
|
||||
// Copy color of closest marker to this time
|
||||
color = closest->color();
|
||||
} else {
|
||||
@@ -673,7 +661,7 @@ void TimeBasedWidget::SetMarker()
|
||||
color = OLIVE_CONFIG("MarkerColor").toInt();
|
||||
}
|
||||
|
||||
TimelineMarker *marker = new TimelineMarker(color, TimeRange(GetTime(), GetTime()));
|
||||
TimelineMarker *marker = new TimelineMarker(color, TimeRange(GetConnectedNode()->GetPlayhead(), GetConnectedNode()->GetPlayhead()));
|
||||
|
||||
if (OLIVE_CONFIG("SetNameWithMarker").toBool()) {
|
||||
MarkerPropertiesDialog mpd({marker}, timebase(), this);
|
||||
@@ -709,8 +697,6 @@ void TimeBasedWidget::ToggleShowAll()
|
||||
w = timeline_views_.first()->width();
|
||||
}
|
||||
|
||||
|
||||
|
||||
toggle_show_all_old_scale_ = GetScale();
|
||||
toggle_show_all_old_scroll_ = scrollbar_->value();
|
||||
|
||||
@@ -726,7 +712,7 @@ void TimeBasedWidget::GoToIn()
|
||||
{
|
||||
if (GetConnectedNode()) {
|
||||
if (GetConnectedNode()->GetWorkArea()->enabled()) {
|
||||
SetTimeAndSignal(GetConnectedNode()->GetWorkArea()->in());
|
||||
GetConnectedNode()->SetPlayhead(GetConnectedNode()->GetWorkArea()->in());
|
||||
} else {
|
||||
GoToStart();
|
||||
}
|
||||
@@ -737,7 +723,7 @@ void TimeBasedWidget::GoToOut()
|
||||
{
|
||||
if (GetConnectedNode()) {
|
||||
if (GetConnectedNode()->GetWorkArea()->enabled()) {
|
||||
SetTimeAndSignal(GetConnectedNode()->GetWorkArea()->out());
|
||||
GetConnectedNode()->SetPlayhead(GetConnectedNode()->GetWorkArea()->out());
|
||||
} else {
|
||||
GoToEnd();
|
||||
}
|
||||
@@ -783,7 +769,7 @@ bool TimeBasedWidget::SnapPoint(const std::vector<rational> &start_times, ration
|
||||
std::vector<SnapData> potential_snaps;
|
||||
|
||||
if (snap_points & kSnapToPlayhead) {
|
||||
rational playhead_abs_time = GetTime();
|
||||
rational playhead_abs_time = GetConnectedNode()->GetPlayhead();
|
||||
qreal playhead_pos = TimeToScene(playhead_abs_time);
|
||||
AttemptSnap(potential_snaps, screen_pt, playhead_pos, start_times, playhead_abs_time);
|
||||
}
|
||||
|
||||
@@ -41,8 +41,6 @@ class TimeBasedWidget : public TimelineScaledWidget
|
||||
public:
|
||||
TimeBasedWidget(bool ruler_text_visible = true, bool ruler_cache_status_visible = false, QWidget* parent = nullptr);
|
||||
|
||||
const rational &GetTime() const;
|
||||
|
||||
void ZoomIn();
|
||||
|
||||
void ZoomOut();
|
||||
@@ -82,8 +80,6 @@ public:
|
||||
virtual bool Paste();
|
||||
|
||||
public slots:
|
||||
void SetTime(const rational &time);
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
void SetScale(const double& scale);
|
||||
@@ -142,7 +138,7 @@ protected:
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *event) override;
|
||||
|
||||
void ConnectTimelineView(TimeBasedView* base, bool connect_time_change_event = true);
|
||||
void ConnectTimelineView(TimeBasedView* base);
|
||||
|
||||
void SetCatchUpScrollValue(QScrollBar *b, int v, int maximum);
|
||||
void SetCatchUpScrollValue(int v);
|
||||
@@ -168,16 +164,12 @@ protected slots:
|
||||
|
||||
static void PageScrollInternal(QScrollBar* bar, int maximum, int screen_position, bool whole_page_scroll);
|
||||
|
||||
void SetTimeAndSignal(const olive::rational& t);
|
||||
|
||||
void StopCatchUpScrollTimer()
|
||||
{
|
||||
StopCatchUpScrollTimer(scrollbar_);
|
||||
}
|
||||
|
||||
signals:
|
||||
void TimeChanged(const rational&);
|
||||
|
||||
void TimebaseChanged(const rational&);
|
||||
|
||||
void ConnectedNodeChanged(ViewerOutput* old, ViewerOutput* now);
|
||||
@@ -265,6 +257,8 @@ private slots:
|
||||
|
||||
void ConnectedNodeRemovedFromGraph();
|
||||
|
||||
void PlayheadTimeChanged(const rational &time);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user