From 6c826a7e160c18b148153c63ce01064f37d862c3 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Sat, 6 Apr 2019 01:55:27 +1100 Subject: [PATCH] use selection cache for more intuitive selections --- panels/timeline.h | 2 +- ui/timelineview.cpp | 80 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 75 insertions(+), 7 deletions(-) diff --git a/panels/timeline.h b/panels/timeline.h index b3dc3517b..ff8c1c836 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -78,7 +78,7 @@ public: // selecting functions bool selecting; - int selection_offset; + QVector selection_cache; void select_all(); bool rect_select_init; bool rect_select_proc; diff --git a/ui/timelineview.cpp b/ui/timelineview.cpp index c7c471158..23bc328ee 100644 --- a/ui/timelineview.cpp +++ b/ui/timelineview.cpp @@ -620,9 +620,9 @@ void TimelineView::mousePressEvent(QMouseEvent *event) { // to the existing selections. `selection_offset` is the index to change selections from (and we don't touch // any prior to that) if (shift) { - ParentTimeline()->selection_offset = sequence()->Selections().size(); + ParentTimeline()->selection_cache = sequence()->Selections(); } else { - ParentTimeline()->selection_offset = 0; + ParentTimeline()->selection_cache.clear(); } // if the user is creating an object @@ -2017,6 +2017,7 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) { } void TimelineView::mouseMoveEvent(QMouseEvent *event) { + // interrupt any potential tooltip about to show tooltip_timer.stop(); @@ -2062,9 +2063,72 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { if (ParentTimeline()->selecting) { + QVector selections = ParentTimeline()->selection_cache; + + if (ParentTimeline()->drag_track_start != nullptr || ParentTimeline()->cursor_track != nullptr) { + + long selection_in = qMin(ParentTimeline()->drag_frame_start, ParentTimeline()->cursor_frame); + long selection_out = qMax(ParentTimeline()->drag_frame_start, ParentTimeline()->cursor_frame); + + int start_track = (ParentTimeline()->drag_track_start == nullptr) + ? track_list_->TrackCount() - 1 + : ParentTimeline()->drag_track_start->Index(); + + int end_track = (ParentTimeline()->cursor_track == nullptr) + ? track_list_->TrackCount() - 1 + : ParentTimeline()->cursor_track->Index(); + + int min_track = qMin(start_track, end_track); + int max_track = qMax(start_track, end_track); + + for (int i=min_track;i<=max_track;i++) { + + Track* track = track_list_->TrackAt(i); + + selections.append(Selection(selection_in, selection_out, track)); + + // If the config is set to select links as well with the edit tool + if (olive::config.edit_tool_selects_links) { + + for (int j=0;jClipCount();j++) { + + Clip* c = track->GetClip(j).get(); + + // See if this selection contains this clip + if (!(c->timeline_in() > selection_out || c->timeline_out() < selection_in)) { + + // If so, select its links as well + for (int k=0;klinked.size();k++) { + Clip* link = c->linked.at(k); + + // Make sure there isn't already a selection for this link + bool found = false; + for (int l=0;ltrack()) { + found = true; + break; + } + } + // If not, make one now + if (!found) { + selections.append(Selection(selection_in, selection_out, link->track())); + } + } + } + } + } + } + } + + sequence()->SetSelections(selections); + /* // get number of selections based on tracks in selection area - int selection_tool_count = 1 + qMax(ParentTimeline()->cursor_track, ParentTimeline()->drag_track_start) - qMin(ParentTimeline()->cursor_track, ParentTimeline()->drag_track_start); + int selection_tool_count = 1 + + qMax(ParentTimeline()->cursor_track->Index(), ParentTimeline()->drag_track_start->Index()) + - qMin(ParentTimeline()->cursor_track->Index(), ParentTimeline()->drag_track_start->Index()); // add count to selection offset for the total number of selection objects // (offset is usually 0, unless the user is holding shift in which case we add to existing selections) @@ -2120,6 +2184,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { } } } + */ // if the config is set to seek with the edit too, do so now if (olive::config.edit_tool_also_seeks) { @@ -2127,8 +2192,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { } else { // if not, repaint (seeking will trigger a repaint) ParentTimeline()->repaint_timeline(); - } - */ + } } else if (ParentTimeline()->hand_moving) { @@ -2400,6 +2464,8 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { // we're currently rectangle selecting + QVector selections = ParentTimeline()->selection_cache; + // set the right/bottom coords to the current mouse position // (left/top were set to the starting drag position earlier) ParentTimeline()->rect_select_rect.setBottomRight(mapToGlobal(event->pos())); @@ -2455,9 +2521,11 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { // add each of the selected clips to the main sequence's selections for (int i=0;itrack()->SelectClip(selected_clips.at(i)); + selections.append(selected_clips.at(i)->ToSelection()); } + sequence()->SetSelections(selections); + ParentTimeline()->repaint_timeline(); } else {