From 16ccb4d9c32b061ce7e3fb0ab55a88f64bf1d89e Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 24 Nov 2018 11:27:17 +1100 Subject: [PATCH] more validator corrections and deleting shared transitions --- panels/timeline.cpp | 22 ++++++++++++++++------ panels/timeline.h | 1 + ui/timelinewidget.cpp | 32 ++++++++++++++------------------ 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 06d53deb9..305e289cd 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -743,6 +743,20 @@ void Timeline::clean_up_selections(QVector& areas) { } } +bool selection_contains_transition(const Selection& s, Clip* c, int type) { + if (type == TA_OPENING_TRANSITION) { + return c->get_opening_transition() != NULL + && s.out == c->timeline_in + c->get_opening_transition()->length + && ((c->get_opening_transition()->secondary_clip == NULL && s.in == c->timeline_in) + || (c->get_opening_transition()->secondary_clip != NULL && s.in == c->timeline_in - c->get_opening_transition()->length)); + } else { + return c->get_closing_transition() != NULL + && s.in == c->timeline_out - c->get_closing_transition()->length + && ((c->get_closing_transition()->secondary_clip == NULL && s.out == c->timeline_out) + || (c->get_closing_transition()->secondary_clip != NULL && s.out == c->timeline_out + c->get_closing_transition()->length)); + } +} + void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& areas) { clean_up_selections(areas); @@ -754,14 +768,10 @@ void Timeline::delete_areas_and_relink(ComboAction* ca, QVector& area for (int j=0;jclips.size();j++) { Clip* c = sequence->clips.at(j); if (c != NULL && c->track == s.track && !c->undeletable) { - if (c->get_opening_transition() != NULL - && s.in == c->timeline_in - && s.out == c->timeline_in + c->get_opening_transition()->length) { + if (selection_contains_transition(s, c, TA_OPENING_TRANSITION)) { // delete opening transition ca->append(new DeleteTransitionCommand(c, TA_OPENING_TRANSITION)); - } else if (c->get_closing_transition() != NULL - && s.out == c->timeline_out - && s.in == c->timeline_out - c->get_closing_transition()->length) { + } else if (selection_contains_transition(s, c, TA_CLOSING_TRANSITION)) { // delete closing transition ca->append(new DeleteTransitionCommand(c, TA_CLOSING_TRANSITION)); } else if (c->timeline_in >= s.in && c->timeline_out <= s.out) { diff --git a/panels/timeline.h b/panels/timeline.h index 779029108..96c2f97be 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -33,6 +33,7 @@ long refactor_frame_number(long framenumber, double source_frame_rate, double ta int getScreenPointFromFrame(double zoom, long frame); long getFrameFromScreenPoint(double zoom, int x); void draw_selection_rectangle(QPainter& painter, const QRect& rect); +bool selection_contains_transition(const Selection& s, Clip* c, int type); struct Ghost { int clip; diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 7d64f7986..ec5693d3a 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -1315,7 +1315,7 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } else if (panel_timeline->tool == TIMELINE_TOOL_TRANSITION) { bool flipped = false; - if (frame_diff < 0) { + if (frame_diff < 0 && panel_timeline->transition_tool_post_clip > -1) { frame_diff = -frame_diff; flipped = true; } @@ -1332,17 +1332,19 @@ void TimelineWidget::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { if (otc != NULL) { validator = otc->timeline_in + frame_diff; - if (validator < 0) { // prevent from going below 0 on the timeline - frame_diff -= validator; - } + if (validator < 0) frame_diff -= validator; // prevent from going below 0 on the timeline - validator = otc->clip_in - frame_diff; - if (validator < 0) { // prevent from going below 0 for the media - frame_diff += validator; - } + if (panel_timeline->transition_tool_post_clip > -1) { + validator = otc->clip_in - frame_diff; + if (validator < 0) frame_diff += validator; // prevent from going below 0 for the media - if (validator > otc->getMaximumLength()) { // prevent transition from exceeding media length - frame_diff -= (validator - otc->getMaximumLength()); + validator = otc->clip_in + frame_diff - otc->getMaximumLength(); + dout << validator << otc->getMaximumLength(); + if (validator > 0) frame_diff -= validator; // prevent transition from exceeding media length + } else { + validator = otc->clip_in + frame_diff; + if (validator < 0) frame_diff -= validator; // prevent from going below 0 for the media + if (validator > otc->getMaximumLength()) frame_diff -= (validator - otc->getMaximumLength()); // prevent transition from exceeding media length } } @@ -1604,17 +1606,11 @@ void TimelineWidget::mouseMoveEvent(QMouseEvent *event) { for (int j=0;jselections.size();j++) { const Selection& s = sequence->selections.at(j); if (s.track == c->track) { - if (c->get_opening_transition() != NULL - && s.out == c->timeline_in + c->get_opening_transition()->length - && ((c->get_opening_transition()->secondary_clip == NULL && s.in == c->timeline_in) - || (c->get_opening_transition()->secondary_clip != NULL && s.in == c->timeline_in - c->get_opening_transition()->length))) { + if (selection_contains_transition(s, c, TA_OPENING_TRANSITION)) { g.transition = c->get_opening_transition(); add = true; break; - } else if (c->get_closing_transition() != NULL - && s.in == c->timeline_out - c->get_closing_transition()->length - && ((c->get_closing_transition()->secondary_clip == NULL && s.out == c->timeline_out) - || (c->get_closing_transition()->secondary_clip != NULL && s.out == c->timeline_out + c->get_closing_transition()->length))) { + } else if (selection_contains_transition(s, c, TA_CLOSING_TRANSITION)) { g.transition = c->get_closing_transition(); add = true; break;