diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 26bce0857..bb09bb5b0 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -761,6 +761,65 @@ long Timeline::getTimelineFrameFromScreenPoint(int x) { return getFrameFromScreenPoint(zoom, x + scroll); } +QVector Timeline::GetClipsInRectangleSelection(bool autoselect_links) +{ + QVector selected_clips; + + TimelineArea* area; + + long frame_min = qMin(drag_frame_start, cursor_frame); + long frame_max = qMax(drag_frame_start, cursor_frame); + + foreach (area, areas) { + QPoint relative_tl = area->mapFromGlobal(rect_select_rect.topLeft()); + QPoint relative_br = area->mapFromGlobal(rect_select_rect.bottomRight()); + + int rect_top = qMin(relative_tl.y(), relative_br.y()); + int rect_bottom = qMax(relative_tl.y(), relative_br.y()); + + // determine which clips are in this rectangular selection + TrackList* track_list = area->track_list(); + for (int j=0;jTrackCount();j++) { + Track* track = track_list->TrackAt(j); + + int track_top = area->view()->getScreenPointFromTrack(track); + int track_bottom = track_top + track->height(); + + // See if this track touches this rectangle at all + if (!(track_bottom < rect_top + || track_top > rect_bottom)) { + + // Loop through track's clips for clips touching this rectangle + for (int i=0;iClipCount();i++) { + Clip* clip = track->GetClip(i).get(); + if (!(clip->timeline_out() < frame_min || clip->timeline_in() > frame_max) ) { + + // create a group of the clip (and its links if alt is not pressed) + QVector session_clips; + session_clips.append(clip); + + if (autoselect_links) { + session_clips.append(clip->linked); + } + + // for each of these clips, see if clip has already been added - + // this can easily happen due to adding linked clips + for (int j=0;jsetOrientation(Qt::Vertical); video_area = new TimelineArea(this); + areas.append(video_area); splitter->addWidget(video_area); audio_area = new TimelineArea(this); + areas.append(audio_area); splitter->addWidget(audio_area); editAreaLayout->addWidget(splitter); diff --git a/panels/timeline.h b/panels/timeline.h index ff8c1c836..db6c45930 100644 --- a/panels/timeline.h +++ b/panels/timeline.h @@ -63,6 +63,8 @@ public: int getDisplayScreenPointFromFrame(long frame); long getDisplayFrameFromScreenPoint(int x); + QVector GetClipsInRectangleSelection(bool autoselect_links); + void set_marker(); // shared information @@ -206,6 +208,7 @@ private: QWidget* timeline_area; TimelineArea* video_area; TimelineArea* audio_area; + QVector areas; QWidget* editAreas; QPushButton* zoomInButton; QPushButton* zoomOutButton; diff --git a/ui/timelinearea.cpp b/ui/timelinearea.cpp index d2a3000ed..86d12a205 100644 --- a/ui/timelinearea.cpp +++ b/ui/timelinearea.cpp @@ -80,6 +80,16 @@ void TimelineArea::SetAlignment(olive::timeline::Alignment alignment) RefreshLabels(); } +TrackList *TimelineArea::track_list() +{ + return track_list_; +} + +TimelineView *TimelineArea::view() +{ + return view_; +} + void TimelineArea::wheelEvent(QWheelEvent *event) { diff --git a/ui/timelinearea.h b/ui/timelinearea.h index d3778a3a0..50e499e71 100644 --- a/ui/timelinearea.h +++ b/ui/timelinearea.h @@ -17,6 +17,9 @@ public: void SetTrackList(Sequence* sequence, Track::Type track_list); void SetAlignment(olive::timeline::Alignment alignment); + TrackList* track_list(); + TimelineView* view(); + virtual void wheelEvent(QWheelEvent *event) override; public slots: void RefreshLabels(); diff --git a/ui/timelineview.cpp b/ui/timelineview.cpp index 09e937ffd..b545c4e9a 100644 --- a/ui/timelineview.cpp +++ b/ui/timelineview.cpp @@ -2402,54 +2402,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { // (left/top were set to the starting drag position earlier) ParentTimeline()->rect_select_rect.setBottomRight(mapToGlobal(event->pos())); - long frame_min = qMin(ParentTimeline()->drag_frame_start, ParentTimeline()->cursor_frame); - long frame_max = qMax(ParentTimeline()->drag_frame_start, ParentTimeline()->cursor_frame); - - QPoint relative_tl = mapFromGlobal(ParentTimeline()->rect_select_rect.topLeft()); - QPoint relative_br = mapFromGlobal(ParentTimeline()->rect_select_rect.bottomRight()); - - int rect_top = qMin(relative_tl.y(), relative_br.y()); - int rect_bottom = qMax(relative_tl.y(), relative_br.y()); - - // determine which clips are in this rectangular selection - QVector selected_clips; - for (int j=0;jTrackCount();j++) { - Track* track = track_list_->TrackAt(j); - - int track_top = getScreenPointFromTrack(track); - int track_bottom = track_top + track->height(); - - // See if this track touches this rectangle at all - if (!(track_bottom < rect_top - || track_top > rect_bottom)) { - - // Loop through track's clips for clips touching this rectangle - for (int i=0;iClipCount();i++) { - Clip* clip = track->GetClip(i).get(); - if (!(clip->timeline_out() < frame_min || clip->timeline_in() > frame_max) ) { - - // create a group of the clip (and its links if alt is not pressed) - QVector session_clips; - session_clips.append(clip); - - if (!alt) { - session_clips.append(clip->linked); - } - - // for each of these clips, see if clip has already been added - - // this can easily happen due to adding linked clips - for (int j=0;j selected_clips = ParentTimeline()->GetClipsInRectangleSelection(!alt); // add each of the selected clips to the main sequence's selections for (int i=0;itransition_select = kTransitionNone; @@ -2548,7 +2501,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { if (c->timeline_in() > mouse_frame_lower && c->timeline_in() < mouse_frame_upper) { // test how close this IN point is to the cursor - int nc = qAbs(c->timeline_in() + 1 - ParentTimeline()->cursor_frame); + long nc = qAbs(c->timeline_in() + 1 - ParentTimeline()->cursor_frame); // and test whether it's closer than the last in/out point we found if (nc < closeness) { @@ -2566,7 +2519,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { if (c->timeline_out() > mouse_frame_lower && c->timeline_out() < mouse_frame_upper) { // test how close this OUT point is to the cursor - int nc = qAbs(c->timeline_out() - 1 - ParentTimeline()->cursor_frame); + long nc = qAbs(c->timeline_out() - 1 - ParentTimeline()->cursor_frame); // and test whether it's closer than the last in/out point we found if (nc < closeness) { @@ -2594,7 +2547,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { if (transition_point > mouse_frame_lower && transition_point < mouse_frame_upper) { // similar to above, test how close it is and if it's closer, make this active - int nc = qAbs(transition_point - 1 - ParentTimeline()->cursor_frame); + long nc = qAbs(transition_point - 1 - ParentTimeline()->cursor_frame); if (nc < closeness) { ParentTimeline()->trim_target = c; ParentTimeline()->trim_type = olive::timeline::TRIM_OUT; @@ -2615,7 +2568,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { if (transition_point > mouse_frame_lower && transition_point < mouse_frame_upper) { // similar to above, test how close it is and if it's closer, make this active - int nc = qAbs(transition_point + 1 - ParentTimeline()->cursor_frame); + long nc = qAbs(transition_point + 1 - ParentTimeline()->cursor_frame); if (nc < closeness) { ParentTimeline()->trim_target = c; ParentTimeline()->trim_type = olive::timeline::TRIM_IN; @@ -2646,18 +2599,21 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) { // check to see if we're resizing a track height int mouse_pos = event->pos().y(); - Track* hover_track = getTrackFromScreenPoint(mouse_pos); - if (hover_track != nullptr) { - int test_range = 10; // FIXME magic number + // cursor range for resizing a track + int test_range = 10; // FIXME magic number - int track_y_edge = getScreenPointFromTrack(hover_track); + for (int i=0;iTrackCount();i++) { + Track* track = track_list_->TrackAt(i); - if (mouse_pos > track_y_edge - test_range - && mouse_pos < track_y_edge + test_range) { + int resize_point = getScreenPointFromTrackIndex(i + 1); + + if (mouse_pos > resize_point - test_range + && mouse_pos < resize_point + test_range) { track_resizing = true; - track_target = hover_track; + track_target = track; setCursor(Qt::SizeVerCursor); + break; } } @@ -3240,10 +3196,11 @@ void TimelineView::paintEvent(QPaintEvent*) { const Ghost& g = ParentTimeline()->ghosts.at(i); first_ghost = qMin(first_ghost, g.in); if (g.track->type() == track_list_->type()) { + int ghost_x = ParentTimeline()->getTimelineScreenPointFromFrame(g.in); int ghost_y = getScreenPointFromTrackIndex(g.track->Index() + g.track_movement); int ghost_width = ParentTimeline()->getTimelineScreenPointFromFrame(g.out) - ghost_x - 1; - int ghost_height = g.track->height() - 1; + int ghost_height = getTrackHeightFromTrackIndex(g.track->Index() + g.track_movement) - 1; insert_points.append(ghost_y + (ghost_height>>1)); @@ -3373,11 +3330,7 @@ int TimelineView::getScreenPointFromTrackIndex(int track) int point = 0; for (int i=0;iTrackCount()) { - point += track_list_->TrackAt(i)->height() + 1; - } else { - point += olive::timeline::kTrackDefaultHeight + 1; - } + point += getTrackHeightFromTrackIndex(i) + 1; } int screen_point = point - scroll; @@ -3390,6 +3343,15 @@ int TimelineView::getScreenPointFromTrackIndex(int track) return screen_point; } +int TimelineView::getTrackHeightFromTrackIndex(int track) +{ + if (track < track_list_->TrackCount()) { + return track_list_->TrackAt(track)->height(); + } else { + return olive::timeline::kTrackDefaultHeight; + } +} + Timeline *TimelineView::ParentTimeline() { return timeline_; diff --git a/ui/timelineview.h b/ui/timelineview.h index 21b7a0acd..364ea42ee 100644 --- a/ui/timelineview.h +++ b/ui/timelineview.h @@ -48,6 +48,14 @@ public: void SetAlignment(olive::timeline::Alignment alignment); void SetTrackList(TrackList* tl); + Track* getTrackFromScreenPoint(int y); + int getScreenPointFromTrack(Track* track); + + int getTrackIndexFromScreenPoint(int y); + int getScreenPointFromTrackIndex(int track); + + int getTrackHeightFromTrackIndex(int track); + protected: void paintEvent(QPaintEvent*); @@ -67,12 +75,6 @@ private: void init_ghosts(); void update_ghosts(const QPoint& mouse_pos, bool lock_frame); - Track* getTrackFromScreenPoint(int y); - int getScreenPointFromTrack(Track* track); - - int getTrackIndexFromScreenPoint(int y); - int getScreenPointFromTrackIndex(int track); - Timeline* ParentTimeline(); Sequence* sequence(); void delete_area_under_ghosts(ComboAction* ca, Sequence *s);