pointertool: reused insert code from importtool

This commit is contained in:
itsmattkc
2020-03-03 16:34:09 +11:00
parent e3759bb704
commit a9577d72ee
4 changed files with 90 additions and 58 deletions
@@ -126,6 +126,12 @@ private:
*/
bool SnapPoint(QList<rational> start_times, rational *movement, int snap_points = kSnapAll);
void InsertGapsAt(const rational& time, const rational& length, QUndoCommand* command);
void GetGhostData(const QVector<TimelineViewGhostItem*>& ghosts, rational *earliest_point, rational *latest_point);
void InsertGapsAtGhostDestination(const QVector<TimelineViewGhostItem*>& ghosts, QUndoCommand* command);
QList<rational> snap_points_;
bool dragging_;
+1 -58
View File
@@ -273,64 +273,7 @@ void TimelineWidget::ImportTool::DragDrop(TimelineViewMouseEvent *event)
// Check if we're inserting
if (event->GetModifiers() & Qt::ControlModifier) {
// Get earliest point
rational earliest_point = RATIONAL_MAX;
rational latest_point = RATIONAL_MIN;
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
earliest_point = qMin(earliest_point, ghost->GetAdjustedIn());
latest_point = qMax(latest_point, ghost->GetAdjustedOut());
}
rational insert_length = latest_point - earliest_point;
QVector<Block*> blocks_to_split;
QList<Block*> blocks_to_append_gap_to;
QList<Block*> gaps_to_extend;
foreach (TrackOutput* track, parent()->GetConnectedNode()->Tracks()) {
if (track->IsLocked()) {
continue;
}
foreach (Block* b, track->Blocks()) {
if (b->out() >= earliest_point) {
if (b->type() == Block::kClip) {
if (b->out() > earliest_point) {
blocks_to_split.append(b);
}
blocks_to_append_gap_to.append(b);
} else if (b->type() == Block::kGap) {
gaps_to_extend.append(b);
}
break;
}
}
}
// Extend gaps that already exist
foreach (Block* gap, gaps_to_extend) {
new BlockResizeCommand(gap, gap->length() + insert_length, command);
}
// Split clips here
new BlockSplitPreservingLinksCommand(blocks_to_split, {earliest_point}, command);
// Insert gaps that don't exist yet
foreach (Block* b, blocks_to_append_gap_to) {
GapBlock* gap = new GapBlock();
gap->set_length_and_media_out(insert_length);
new NodeAddCommand(static_cast<NodeGraph*>(parent()->GetConnectedNode()->parent()), gap, command);
new TrackInsertBlockAfterCommand(TrackOutput::TrackFromBlock(b), gap, b, command);
qDebug() << "Inserting block on" << TrackOutput::TrackFromBlock(b);
}
InsertGapsAtGhostDestination(parent()->ghost_items_, command);
}
for (int i=0;i<parent()->ghost_items_.size();i++) {
@@ -219,6 +219,11 @@ void TimelineWidget::PointerTool::MouseReleaseInternal(TimelineViewMouseEvent *e
// If there are any blocks to remove, remove them
parent()->DeleteSelectedInternal(blocks_to_temp_remove, false, false, command);
if (event->GetModifiers() & Qt::ControlModifier) {
// Make room to insert clips to
InsertGapsAtGhostDestination(parent()->ghost_items_, command);
}
// Now we place the clips back in the timeline where the user moved them. It's legal for them to overwrite parts or
// all of the gaps we inserted earlier
for (int i=0;i<parent()->ghost_items_.size();i++) {
+78
View File
@@ -24,6 +24,7 @@
#include "common/range.h"
#include "node/block/transition/transition.h"
#include "widget/nodeview/nodeviewundo.h"
TimelineWidget::Tool::Tool(TimelineWidget *parent) :
dragging_(false),
@@ -195,3 +196,80 @@ bool TimelineWidget::Tool::SnapPoint(QList<rational> start_times, rational* move
return (diff < DBL_MAX);
}
void TimelineWidget::Tool::InsertGapsAt(const rational &earliest_point, const rational &insert_length, QUndoCommand *command)
{
QVector<Block*> blocks_to_split;
QList<Block*> blocks_to_append_gap_to;
QList<Block*> gaps_to_extend;
foreach (TrackOutput* track, parent()->GetConnectedNode()->Tracks()) {
if (track->IsLocked()) {
continue;
}
foreach (Block* b, track->Blocks()) {
if (b->out() >= earliest_point) {
if (b->type() == Block::kClip) {
if (b->out() > earliest_point) {
blocks_to_split.append(b);
}
blocks_to_append_gap_to.append(b);
} else if (b->type() == Block::kGap) {
gaps_to_extend.append(b);
}
break;
}
}
}
// Extend gaps that already exist
foreach (Block* gap, gaps_to_extend) {
new BlockResizeCommand(gap, gap->length() + insert_length, command);
}
// Split clips here
new BlockSplitPreservingLinksCommand(blocks_to_split, {earliest_point}, command);
// Insert gaps that don't exist yet
foreach (Block* b, blocks_to_append_gap_to) {
GapBlock* gap = new GapBlock();
gap->set_length_and_media_out(insert_length);
new NodeAddCommand(static_cast<NodeGraph*>(parent()->GetConnectedNode()->parent()), gap, command);
new TrackInsertBlockAfterCommand(TrackOutput::TrackFromBlock(b), gap, b, command);
}
}
void TimelineWidget::Tool::GetGhostData(const QVector<TimelineViewGhostItem *> &ghosts, rational *earliest_point, rational *latest_point)
{
rational ep = RATIONAL_MAX;
rational lp = RATIONAL_MIN;
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
ep = qMin(ep, ghost->GetAdjustedIn());
lp = qMax(lp, ghost->GetAdjustedOut());
}
if (earliest_point) {
*earliest_point = ep;
}
if (latest_point) {
*latest_point = lp;
}
}
void TimelineWidget::Tool::InsertGapsAtGhostDestination(const QVector<TimelineViewGhostItem *> &ghosts, QUndoCommand *command)
{
rational earliest_point, latest_point;
GetGhostData(ghosts, &earliest_point, &latest_point);
InsertGapsAt(earliest_point, latest_point - earliest_point, command);
}