fixed rectangle selection
This commit is contained in:
@@ -761,6 +761,65 @@ long Timeline::getTimelineFrameFromScreenPoint(int x) {
|
|||||||
return getFrameFromScreenPoint(zoom, x + scroll);
|
return getFrameFromScreenPoint(zoom, x + scroll);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVector<Clip *> Timeline::GetClipsInRectangleSelection(bool autoselect_links)
|
||||||
|
{
|
||||||
|
QVector<Clip*> 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;j<track_list->TrackCount();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;i<track->ClipCount();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<Clip*> 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;j<session_clips.size();j++) {
|
||||||
|
Clip* c = session_clips.at(j);
|
||||||
|
|
||||||
|
if (!selected_clips.contains(c)) {
|
||||||
|
selected_clips.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return selected_clips;
|
||||||
|
}
|
||||||
|
|
||||||
int Timeline::getTimelineScreenPointFromFrame(long frame) {
|
int Timeline::getTimelineScreenPointFromFrame(long frame) {
|
||||||
return getScreenPointFromFrame(zoom, frame) - scroll;
|
return getScreenPointFromFrame(zoom, frame) - scroll;
|
||||||
}
|
}
|
||||||
@@ -1018,9 +1077,11 @@ void Timeline::setup_ui() {
|
|||||||
splitter->setOrientation(Qt::Vertical);
|
splitter->setOrientation(Qt::Vertical);
|
||||||
|
|
||||||
video_area = new TimelineArea(this);
|
video_area = new TimelineArea(this);
|
||||||
|
areas.append(video_area);
|
||||||
splitter->addWidget(video_area);
|
splitter->addWidget(video_area);
|
||||||
|
|
||||||
audio_area = new TimelineArea(this);
|
audio_area = new TimelineArea(this);
|
||||||
|
areas.append(audio_area);
|
||||||
splitter->addWidget(audio_area);
|
splitter->addWidget(audio_area);
|
||||||
|
|
||||||
editAreaLayout->addWidget(splitter);
|
editAreaLayout->addWidget(splitter);
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public:
|
|||||||
int getDisplayScreenPointFromFrame(long frame);
|
int getDisplayScreenPointFromFrame(long frame);
|
||||||
long getDisplayFrameFromScreenPoint(int x);
|
long getDisplayFrameFromScreenPoint(int x);
|
||||||
|
|
||||||
|
QVector<Clip*> GetClipsInRectangleSelection(bool autoselect_links);
|
||||||
|
|
||||||
void set_marker();
|
void set_marker();
|
||||||
|
|
||||||
// shared information
|
// shared information
|
||||||
@@ -206,6 +208,7 @@ private:
|
|||||||
QWidget* timeline_area;
|
QWidget* timeline_area;
|
||||||
TimelineArea* video_area;
|
TimelineArea* video_area;
|
||||||
TimelineArea* audio_area;
|
TimelineArea* audio_area;
|
||||||
|
QVector<TimelineArea*> areas;
|
||||||
QWidget* editAreas;
|
QWidget* editAreas;
|
||||||
QPushButton* zoomInButton;
|
QPushButton* zoomInButton;
|
||||||
QPushButton* zoomOutButton;
|
QPushButton* zoomOutButton;
|
||||||
|
|||||||
@@ -80,6 +80,16 @@ void TimelineArea::SetAlignment(olive::timeline::Alignment alignment)
|
|||||||
RefreshLabels();
|
RefreshLabels();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TrackList *TimelineArea::track_list()
|
||||||
|
{
|
||||||
|
return track_list_;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimelineView *TimelineArea::view()
|
||||||
|
{
|
||||||
|
return view_;
|
||||||
|
}
|
||||||
|
|
||||||
void TimelineArea::wheelEvent(QWheelEvent *event)
|
void TimelineArea::wheelEvent(QWheelEvent *event)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ public:
|
|||||||
void SetTrackList(Sequence* sequence, Track::Type track_list);
|
void SetTrackList(Sequence* sequence, Track::Type track_list);
|
||||||
void SetAlignment(olive::timeline::Alignment alignment);
|
void SetAlignment(olive::timeline::Alignment alignment);
|
||||||
|
|
||||||
|
TrackList* track_list();
|
||||||
|
TimelineView* view();
|
||||||
|
|
||||||
virtual void wheelEvent(QWheelEvent *event) override;
|
virtual void wheelEvent(QWheelEvent *event) override;
|
||||||
public slots:
|
public slots:
|
||||||
void RefreshLabels();
|
void RefreshLabels();
|
||||||
|
|||||||
+28
-66
@@ -2402,54 +2402,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) {
|
|||||||
// (left/top were set to the starting drag position earlier)
|
// (left/top were set to the starting drag position earlier)
|
||||||
ParentTimeline()->rect_select_rect.setBottomRight(mapToGlobal(event->pos()));
|
ParentTimeline()->rect_select_rect.setBottomRight(mapToGlobal(event->pos()));
|
||||||
|
|
||||||
long frame_min = qMin(ParentTimeline()->drag_frame_start, ParentTimeline()->cursor_frame);
|
QVector<Clip*> selected_clips = ParentTimeline()->GetClipsInRectangleSelection(!alt);
|
||||||
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<Clip*> selected_clips;
|
|
||||||
for (int j=0;j<track_list_->TrackCount();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;i<track->ClipCount();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<Clip*> 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<session_clips.size();j++) {
|
|
||||||
Clip* c = session_clips.at(j);
|
|
||||||
|
|
||||||
if (!selected_clips.contains(c)) {
|
|
||||||
selected_clips.append(c);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add each of the selected clips to the main sequence's selections
|
// add each of the selected clips to the main sequence's selections
|
||||||
for (int i=0;i<selected_clips.size();i++) {
|
for (int i=0;i<selected_clips.size();i++) {
|
||||||
@@ -2500,7 +2453,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) {
|
|||||||
|
|
||||||
// used to determine how close the cursor is to a trim point
|
// used to determine how close the cursor is to a trim point
|
||||||
// (and more specifically, whether another point is closer or not)
|
// (and more specifically, whether another point is closer or not)
|
||||||
int closeness = INT_MAX;
|
long closeness = LONG_MAX;
|
||||||
|
|
||||||
// we default to selecting no transition, but set this accordingly if the cursor is on a transition
|
// we default to selecting no transition, but set this accordingly if the cursor is on a transition
|
||||||
ParentTimeline()->transition_select = kTransitionNone;
|
ParentTimeline()->transition_select = kTransitionNone;
|
||||||
@@ -2548,7 +2501,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) {
|
|||||||
if (c->timeline_in() > mouse_frame_lower && c->timeline_in() < mouse_frame_upper) {
|
if (c->timeline_in() > mouse_frame_lower && c->timeline_in() < mouse_frame_upper) {
|
||||||
|
|
||||||
// test how close this IN point is to the cursor
|
// 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
|
// and test whether it's closer than the last in/out point we found
|
||||||
if (nc < closeness) {
|
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) {
|
if (c->timeline_out() > mouse_frame_lower && c->timeline_out() < mouse_frame_upper) {
|
||||||
|
|
||||||
// test how close this OUT point is to the cursor
|
// 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
|
// and test whether it's closer than the last in/out point we found
|
||||||
if (nc < closeness) {
|
if (nc < closeness) {
|
||||||
@@ -2594,7 +2547,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) {
|
|||||||
if (transition_point > mouse_frame_lower && transition_point < mouse_frame_upper) {
|
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
|
// 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) {
|
if (nc < closeness) {
|
||||||
ParentTimeline()->trim_target = c;
|
ParentTimeline()->trim_target = c;
|
||||||
ParentTimeline()->trim_type = olive::timeline::TRIM_OUT;
|
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) {
|
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
|
// 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) {
|
if (nc < closeness) {
|
||||||
ParentTimeline()->trim_target = c;
|
ParentTimeline()->trim_target = c;
|
||||||
ParentTimeline()->trim_type = olive::timeline::TRIM_IN;
|
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
|
// check to see if we're resizing a track height
|
||||||
int mouse_pos = event->pos().y();
|
int mouse_pos = event->pos().y();
|
||||||
Track* hover_track = getTrackFromScreenPoint(mouse_pos);
|
|
||||||
|
|
||||||
if (hover_track != nullptr) {
|
// cursor range for resizing a track
|
||||||
int test_range = 10; // FIXME magic number
|
int test_range = 10; // FIXME magic number
|
||||||
|
|
||||||
int track_y_edge = getScreenPointFromTrack(hover_track);
|
for (int i=0;i<track_list_->TrackCount();i++) {
|
||||||
|
Track* track = track_list_->TrackAt(i);
|
||||||
|
|
||||||
if (mouse_pos > track_y_edge - test_range
|
int resize_point = getScreenPointFromTrackIndex(i + 1);
|
||||||
&& mouse_pos < track_y_edge + test_range) {
|
|
||||||
|
if (mouse_pos > resize_point - test_range
|
||||||
|
&& mouse_pos < resize_point + test_range) {
|
||||||
track_resizing = true;
|
track_resizing = true;
|
||||||
track_target = hover_track;
|
track_target = track;
|
||||||
setCursor(Qt::SizeVerCursor);
|
setCursor(Qt::SizeVerCursor);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3240,10 +3196,11 @@ void TimelineView::paintEvent(QPaintEvent*) {
|
|||||||
const Ghost& g = ParentTimeline()->ghosts.at(i);
|
const Ghost& g = ParentTimeline()->ghosts.at(i);
|
||||||
first_ghost = qMin(first_ghost, g.in);
|
first_ghost = qMin(first_ghost, g.in);
|
||||||
if (g.track->type() == track_list_->type()) {
|
if (g.track->type() == track_list_->type()) {
|
||||||
|
|
||||||
int ghost_x = ParentTimeline()->getTimelineScreenPointFromFrame(g.in);
|
int ghost_x = ParentTimeline()->getTimelineScreenPointFromFrame(g.in);
|
||||||
int ghost_y = getScreenPointFromTrackIndex(g.track->Index() + g.track_movement);
|
int ghost_y = getScreenPointFromTrackIndex(g.track->Index() + g.track_movement);
|
||||||
int ghost_width = ParentTimeline()->getTimelineScreenPointFromFrame(g.out) - ghost_x - 1;
|
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));
|
insert_points.append(ghost_y + (ghost_height>>1));
|
||||||
|
|
||||||
@@ -3373,11 +3330,7 @@ int TimelineView::getScreenPointFromTrackIndex(int track)
|
|||||||
int point = 0;
|
int point = 0;
|
||||||
|
|
||||||
for (int i=0;i<track;i++) {
|
for (int i=0;i<track;i++) {
|
||||||
if (i < track_list_->TrackCount()) {
|
point += getTrackHeightFromTrackIndex(i) + 1;
|
||||||
point += track_list_->TrackAt(i)->height() + 1;
|
|
||||||
} else {
|
|
||||||
point += olive::timeline::kTrackDefaultHeight + 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int screen_point = point - scroll;
|
int screen_point = point - scroll;
|
||||||
@@ -3390,6 +3343,15 @@ int TimelineView::getScreenPointFromTrackIndex(int track)
|
|||||||
return screen_point;
|
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()
|
Timeline *TimelineView::ParentTimeline()
|
||||||
{
|
{
|
||||||
return timeline_;
|
return timeline_;
|
||||||
|
|||||||
+8
-6
@@ -48,6 +48,14 @@ public:
|
|||||||
void SetAlignment(olive::timeline::Alignment alignment);
|
void SetAlignment(olive::timeline::Alignment alignment);
|
||||||
void SetTrackList(TrackList* tl);
|
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:
|
protected:
|
||||||
void paintEvent(QPaintEvent*);
|
void paintEvent(QPaintEvent*);
|
||||||
|
|
||||||
@@ -67,12 +75,6 @@ private:
|
|||||||
void init_ghosts();
|
void init_ghosts();
|
||||||
void update_ghosts(const QPoint& mouse_pos, bool lock_frame);
|
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();
|
Timeline* ParentTimeline();
|
||||||
Sequence* sequence();
|
Sequence* sequence();
|
||||||
void delete_area_under_ghosts(ComboAction* ca, Sequence *s);
|
void delete_area_under_ghosts(ComboAction* ca, Sequence *s);
|
||||||
|
|||||||
Reference in New Issue
Block a user