reimplemented split at playhead functionality
Reimplemented an older but very useful timeline function for splitting blocks at the current playhead.
This commit is contained in:
@@ -59,6 +59,11 @@ void TimelinePanel::DisconnectTimelineNode()
|
||||
timeline_widget_->DisconnectTimelineNode();
|
||||
}
|
||||
|
||||
void TimelinePanel::SplitAtPlayhead()
|
||||
{
|
||||
timeline_widget_->SplitAtPlayhead();
|
||||
}
|
||||
|
||||
void TimelinePanel::ZoomIn()
|
||||
{
|
||||
timeline_widget_->ZoomIn();
|
||||
|
||||
@@ -40,6 +40,8 @@ public:
|
||||
|
||||
void DisconnectTimelineNode();
|
||||
|
||||
void SplitAtPlayhead();
|
||||
|
||||
virtual void ZoomIn() override;
|
||||
|
||||
virtual void ZoomOut() override;
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#include "menushared.h"
|
||||
|
||||
#include "core.h"
|
||||
#include "panel/panelmanager.h"
|
||||
#include "panel/timeline/timeline.h"
|
||||
|
||||
MenuShared olive::menu_shared;
|
||||
|
||||
@@ -43,7 +45,7 @@ void MenuShared::Initialize()
|
||||
edit_duplicate_item_ = Menu::CreateItem(this, "duplicate", nullptr, nullptr, "Ctrl+D");
|
||||
edit_delete_item_ = Menu::CreateItem(this, "delete", nullptr, nullptr, "Del");
|
||||
edit_ripple_delete_item_ = Menu::CreateItem(this, "rippledelete", nullptr, nullptr, "Shift+Del");
|
||||
edit_split_item_ = Menu::CreateItem(this, "split", nullptr, nullptr, "Ctrl+K");
|
||||
edit_split_item_ = Menu::CreateItem(this, "split", this, SLOT(SplitAtPlayhead()), "Ctrl+K");
|
||||
|
||||
// "In/Out" menu shared items
|
||||
inout_set_in_item_ = Menu::CreateItem(this, "setinpoint", nullptr, nullptr, "I");
|
||||
@@ -99,6 +101,15 @@ void MenuShared::AddItemsForClipEditMenu(Menu *m)
|
||||
m->addAction(clip_nest_item_);
|
||||
}
|
||||
|
||||
void MenuShared::SplitAtPlayhead()
|
||||
{
|
||||
TimelinePanel* timeline = olive::panel_manager->MostRecentlyFocused<TimelinePanel>();
|
||||
|
||||
if (timeline != nullptr) {
|
||||
timeline->SplitAtPlayhead();
|
||||
}
|
||||
}
|
||||
|
||||
void MenuShared::Retranslate()
|
||||
{
|
||||
// "New" menu shared items
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
* @brief A static object that provides various "stock" menus for use throughout the application
|
||||
*/
|
||||
class MenuShared : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
MenuShared();
|
||||
|
||||
@@ -66,6 +67,10 @@ private:
|
||||
QAction* clip_link_unlink_item_;
|
||||
QAction* clip_enable_disable_item_;
|
||||
QAction* clip_nest_item_;
|
||||
|
||||
private slots:
|
||||
void SplitAtPlayhead();
|
||||
|
||||
};
|
||||
|
||||
namespace olive {
|
||||
|
||||
@@ -300,6 +300,55 @@ void TimelineWidget::GoToNextCut()
|
||||
}
|
||||
}
|
||||
|
||||
void TimelineWidget::SplitAtPlayhead()
|
||||
{
|
||||
rational playhead_time = olive::timestamp_to_time(playhead_, timebase());
|
||||
|
||||
QList<TimelineViewBlockItem *> selected_blocks = GetSelectedBlocks();
|
||||
|
||||
// Prioritize blocks that are selected and overlap the playhead
|
||||
QVector<Block*> blocks_to_split;
|
||||
QVector<bool> block_is_selected;
|
||||
|
||||
bool some_blocks_are_selected = false;
|
||||
|
||||
// Get all blocks at the playhead
|
||||
foreach (TrackOutput* track, timeline_node_->Tracks()) {
|
||||
Block* b = track->BlockContainingTime(playhead_time);
|
||||
|
||||
if (b != nullptr) {
|
||||
bool selected = false;
|
||||
|
||||
// See if this block is selected
|
||||
foreach (TimelineViewBlockItem* item, selected_blocks) {
|
||||
if (item->block() == b) {
|
||||
some_blocks_are_selected = true;
|
||||
selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
blocks_to_split.append(b);
|
||||
block_is_selected.append(selected);
|
||||
}
|
||||
}
|
||||
|
||||
// If some blocks are selected, we prioritize those and don't split the blocks that aren't
|
||||
if (some_blocks_are_selected) {
|
||||
for (int i=0;i<block_is_selected.size();i++) {
|
||||
if (!block_is_selected.at(i)) {
|
||||
blocks_to_split.removeAt(i);
|
||||
block_is_selected.removeAt(i);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!blocks_to_split.isEmpty()) {
|
||||
olive::undo_stack.push(new BlockSplitPreservingLinksCommand(blocks_to_split, {playhead_time}));
|
||||
}
|
||||
}
|
||||
|
||||
QList<TimelineViewBlockItem *> TimelineWidget::GetSelectedBlocks()
|
||||
{
|
||||
QList<TimelineViewBlockItem *> list;
|
||||
|
||||
@@ -48,6 +48,8 @@ public:
|
||||
|
||||
void GoToNextCut();
|
||||
|
||||
void SplitAtPlayhead();
|
||||
|
||||
QList<TimelineViewBlockItem*> GetSelectedBlocks();
|
||||
|
||||
public slots:
|
||||
@@ -318,8 +320,6 @@ private:
|
||||
|
||||
void RippleEditTo(olive::timeline::MovementMode mode, bool insert_gaps);
|
||||
|
||||
void SplitBlocksPreservingLinks(const QVector<Block*>& blocks, const QList<rational> ×);
|
||||
|
||||
void SetTimeAndSignal(const int64_t& t);
|
||||
|
||||
TrackOutput* GetTrackFromReference(const TrackReference& ref);
|
||||
|
||||
Reference in New Issue
Block a user