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
+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 {