timeline: reimplemented linking/unlinking functionality

This commit is contained in:
itsmattkc
2020-03-15 13:41:46 +11:00
parent b57b091ca4
commit 02e7c68104
11 changed files with 102 additions and 19 deletions
+20 -6
View File
@@ -202,20 +202,25 @@ void Block::LengthInputChanged()
emit LengthChanged(length());
}
void Block::Link(Block *a, Block *b)
bool Block::Link(Block *a, Block *b)
{
if (a == b || !a || !b) {
return;
return false;
}
// Prevent duplicate link entries (assume that we only need to check one clip since this should be the only function
// that adds to the linked array)
if (a->linked_clips_.contains(b)) {
return;
if (Block::AreLinked(a, b)) {
return false;
}
a->linked_clips_.append(b);
b->linked_clips_.append(a);
emit a->LinksChanged();
emit b->LinksChanged();
return true;
}
void Block::Link(const QList<Block*>& blocks)
@@ -227,14 +232,23 @@ void Block::Link(const QList<Block*>& blocks)
}
}
void Block::Unlink(Block *a, Block *b)
bool Block::Unlink(Block *a, Block *b)
{
if (a == b || !a || !b) {
return;
return false;
}
if (!Block::AreLinked(a, b)) {
return false;
}
a->linked_clips_.removeOne(b);
b->linked_clips_.removeOne(a);
emit a->LinksChanged();
emit b->LinksChanged();
return true;
}
void Block::Unlink(const QList<Block *> &blocks)
+4 -2
View File
@@ -76,9 +76,9 @@ public:
QString block_name() const;
void set_block_name(const QString& name);
static void Link(Block* a, Block* b);
static bool Link(Block* a, Block* b);
static void Link(const QList<Block*>& blocks);
static void Unlink(Block* a, Block* b);
static bool Unlink(Block* a, Block* b);
static void Unlink(const QList<Block*>& blocks);
static bool AreLinked(Block* a, Block* b);
const QVector<Block*>& linked_clips();
@@ -104,6 +104,8 @@ signals:
void LengthChanged(const rational& length);
void LinksChanged();
protected:
rational SequenceToMediaTime(const rational& sequence_time) const;
+5
View File
@@ -115,6 +115,11 @@ void TimelinePanel::Overwrite()
}
}
void TimelinePanel::ToggleLinks()
{
static_cast<TimelineWidget*>(GetTimeBasedWidget())->ToggleLinksOnSelected();
}
void TimelinePanel::InsertFootageAtPlayhead(const QList<Footage *> &footage)
{
static_cast<TimelineWidget*>(GetTimeBasedWidget())->InsertFootageAtPlayhead(footage);
+2
View File
@@ -61,6 +61,8 @@ public:
virtual void Overwrite() override;
virtual void ToggleLinks() override;
void InsertFootageAtPlayhead(const QList<Footage *> &footage);
void OverwriteFootageAtPlayhead(const QList<Footage *> &footage);
+6 -1
View File
@@ -52,7 +52,7 @@ MenuShared::MenuShared()
// "Clip Edit" menu shared items
clip_add_default_transition_item_ = Menu::CreateItem(this, "deftransition", nullptr, nullptr, "Ctrl+Shift+D");
clip_link_unlink_item_ = Menu::CreateItem(this, "linkunlink", nullptr, nullptr, "Ctrl+L");
clip_link_unlink_item_ = Menu::CreateItem(this, "linkunlink", this, SLOT(ToggleLinksTriggered()), "Ctrl+L");
clip_enable_disable_item_ = Menu::CreateItem(this, "enabledisable", nullptr, nullptr, "Shift+E");
clip_nest_item_ = Menu::CreateItem(this, "nest", nullptr, nullptr);
@@ -156,6 +156,11 @@ void MenuShared::ClearInOutTriggered()
PanelManager::instance()->CurrentlyFocused()->ClearInOut();
}
void MenuShared::ToggleLinksTriggered()
{
PanelManager::instance()->CurrentlyFocused()->ToggleLinks();
}
void MenuShared::Retranslate()
{
// "New" menu shared items
+2
View File
@@ -91,6 +91,8 @@ private slots:
void ClearInOutTriggered();
void ToggleLinksTriggered();
};
#endif // MENUSHARED_H
+2
View File
@@ -130,6 +130,8 @@ public:
virtual void SetMarker(){}
virtual void ToggleLinks(){}
protected:
/**
* @brief paintEvent
@@ -472,6 +472,30 @@ void TimelineWidget::OverwriteFootageAtPlayhead(const QList<Footage *> &footage)
import_tool_->PlaceAt(footage, GetTime(), false);
}
void TimelineWidget::ToggleLinksOnSelected()
{
QList<TimelineViewBlockItem*> sel = GetSelectedBlocks();
// Prioritize unlinking
QList<Block*> blocks;
bool link = true;
foreach (TimelineViewBlockItem* item, sel) {
if (link && item->block()->HasLinks()) {
link = false;
}
blocks.append(item->block());
}
if (link) {
Core::instance()->undo_stack()->push(new BlockLinkManyCommand(blocks, true));
} else {
Core::instance()->undo_stack()->push(new BlockLinkManyCommand(blocks, false));
}
}
QList<TimelineViewBlockItem *> TimelineWidget::GetSelectedBlocks()
{
QList<TimelineViewBlockItem *> list;
@@ -687,6 +711,7 @@ void TimelineWidget::AddBlock(Block *block, TrackReference track)
views_.at(track.type())->view()->scene()->addItem(item);
connect(block, &Block::Refreshed, this, &TimelineWidget::BlockChanged);
connect(block, &Block::LinksChanged, this, &TimelineWidget::PreviewUpdated);
if (block->type() == Block::kClip) {
connect(static_cast<ClipBlock*>(block), &ClipBlock::PreviewUpdated, this, &TimelineWidget::PreviewUpdated);
@@ -57,6 +57,8 @@ public:
void OverwriteFootageAtPlayhead(const QList<Footage *> &footage);
void ToggleLinksOnSelected();
QList<TimelineViewBlockItem*> GetSelectedBlocks();
signals:
+23 -8
View File
@@ -716,9 +716,10 @@ void WorkareaSetRangeCommand::undo_internal()
points_->workarea()->set_range(old_range_);
}
BlockLinkCommand::BlockLinkCommand(const QList<Block *> &blocks, bool link, QUndoCommand *parent) :
BlockLinkCommand::BlockLinkCommand(Block *a, Block *b, bool link, QUndoCommand *parent) :
UndoCommand(parent),
blocks_(blocks),
a_(a),
b_(b),
link_(link)
{
}
@@ -726,18 +727,20 @@ BlockLinkCommand::BlockLinkCommand(const QList<Block *> &blocks, bool link, QUnd
void BlockLinkCommand::redo_internal()
{
if (link_) {
Block::Link(blocks_);
done_ = Block::Link(a_, b_);
} else {
Block::Unlink(blocks_);
done_ = Block::Unlink(a_, b_);
}
}
void BlockLinkCommand::undo_internal()
{
if (link_) {
Block::Unlink(blocks_);
} else {
Block::Link(blocks_);
if (done_) {
if (link_) {
Block::Unlink(a_, b_);
} else {
Block::Link(a_, b_);
}
}
}
@@ -764,3 +767,15 @@ void BlockUnlinkAllCommand::undo_internal()
unlinked_.clear();
}
BlockLinkManyCommand::BlockLinkManyCommand(const QList<Block *> blocks, bool link, QUndoCommand *parent) :
UndoCommand(parent)
{
foreach (Block* a, blocks) {
foreach (Block* b, blocks) {
if (a != b) {
new BlockLinkCommand(a, b, link, this);
}
}
}
}
+11 -2
View File
@@ -331,19 +331,28 @@ private:
};
class BlockLinkManyCommand : public UndoCommand {
public:
BlockLinkManyCommand(const QList<Block*> blocks, bool link, QUndoCommand* parent = nullptr);
};
class BlockLinkCommand : public UndoCommand {
public:
BlockLinkCommand(const QList<Block*>& blocks, bool link, QUndoCommand* parent = nullptr);
BlockLinkCommand(Block* a, Block* b, bool link, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
QList<Block*> blocks_;
Block* a_;
Block* b_;
bool link_;
bool done_;
};
class BlockUnlinkAllCommand : public UndoCommand {