From 03a0c64e155b2b313ac14c7cb5b3b5374ec3a877 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 13 Aug 2019 18:14:36 +1000 Subject: [PATCH] some timeline work --- app/node/graph.h | 5 +++++ app/node/output/timeline/timeline.h | 25 +++++++++++++++++++++++++ app/panel/timeline/timeline.cpp | 5 +++++ app/panel/timeline/timeline.h | 5 ++--- app/widget/timelineview/timelineview.h | 2 ++ app/widget/timelineview/tool/import.cpp | 18 +++++++++++++++--- 6 files changed, 54 insertions(+), 6 deletions(-) diff --git a/app/node/graph.h b/app/node/graph.h index 539e5a395..b32fec5d6 100644 --- a/app/node/graph.h +++ b/app/node/graph.h @@ -53,6 +53,11 @@ public: */ void AddNodeWithDependencies(Node* node); + /** + * @brief Removes a Node from the graph and destroys it + */ + void RemoveNode(Node* node); + /** * @brief Retrieve a complete list of the nodes belonging to this graph */ diff --git a/app/node/output/timeline/timeline.h b/app/node/output/timeline/timeline.h index 409e65805..54c652878 100644 --- a/app/node/output/timeline/timeline.h +++ b/app/node/output/timeline/timeline.h @@ -55,6 +55,11 @@ private: */ void ConnectBlockInternal(Block* block); + /** + * @brief Disconnects t + */ + void RemoveBlockInternal(); + /** * @brief Adds a Block to the parent graph so it can be connected to other Nodes * @@ -107,6 +112,26 @@ private slots: * the Sequence, a GapBlock is inserted to compensate. */ void PlaceBlock(Block* block, rational start); + + /** + * @brief Removes a Block and places a Gap in its place + */ + void RemoveBlock(Block* block); + + /** + * @brief Removes a Block pushing all subsequent Blocks earlier to take up the space + */ + void RippleRemoveBlock(Block* block); + + /** + * @brief Removes the Block at the given index pushing all subsequent Blocks earlier to take up the space + */ + void RippleRemoveBlockAtIndex(int index); + + /** + * @brief Removes the last Block of the Sequence at the given index + */ + void RippleRemoveLast(); }; #endif // TIMELINEOUTPUT_H diff --git a/app/panel/timeline/timeline.cpp b/app/panel/timeline/timeline.cpp index bdf180c7f..e40b12c16 100644 --- a/app/panel/timeline/timeline.cpp +++ b/app/panel/timeline/timeline.cpp @@ -75,6 +75,11 @@ void TimelinePanel::SetTimebase(const rational &timebase) view_->SetTimebase(timebase); } +TimelineView *TimelinePanel::view() +{ + return view_; +} + void TimelinePanel::changeEvent(QEvent *e) { if (e->type() == QEvent::LanguageChange) { diff --git a/app/panel/timeline/timeline.h b/app/panel/timeline/timeline.h index 1e968a3b4..9358570a9 100644 --- a/app/panel/timeline/timeline.h +++ b/app/panel/timeline/timeline.h @@ -39,13 +39,12 @@ public: void SetTimebase(const rational& timebase); + TimelineView* view(); + protected: virtual void changeEvent(QEvent* e) override; signals: - void RequestInsertBlockAtIndex(Block*, int); - - void RequestPlaceBlock(Block* block, rational start); private: void Retranslate(); diff --git a/app/widget/timelineview/timelineview.h b/app/widget/timelineview/timelineview.h index e5b5acdd0..3ad8ec9df 100644 --- a/app/widget/timelineview/timelineview.h +++ b/app/widget/timelineview/timelineview.h @@ -61,6 +61,8 @@ signals: void RequestPlaceBlock(Block* block, rational start); + void RequestInsertBlockAtTime(Block* block, rational time); + protected: virtual void mousePressEvent(QMouseEvent *event) override; virtual void mouseMoveEvent(QMouseEvent *event) override; diff --git a/app/widget/timelineview/tool/import.cpp b/app/widget/timelineview/tool/import.cpp index d1fe70abc..be2708930 100644 --- a/app/widget/timelineview/tool/import.cpp +++ b/app/widget/timelineview/tool/import.cpp @@ -111,18 +111,30 @@ void TimelineView::ImportTool::DragLeave(QDragLeaveEvent *event) void TimelineView::ImportTool::DragDrop(QDropEvent *event) { if (parent()->HasGhosts()) { + // We use QObject as the parent for the nodes we create. If there is no TimelineOutput node, this object going out + // of scope will delete the nodes. If there is, they'll become parents of the NodeGraph instead + QObject node_memory_manager; + foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { ClipBlock* clip = new ClipBlock(); MediaInput* media = new MediaInput(); + // Set parents to node_memory_manager in case no TimelineOutput receives this signal + // FIXME: Moving nodes to shared_ptrs might be a better idea, except they all use the QObject system for hierarchy + // already... + clip->setParent(&node_memory_manager); + media->setParent(&node_memory_manager); + clip->set_length(ghost->Out() - ghost->In()); media->SetFootage(ghost->stream()->footage()); NodeParam::ConnectEdge(media->texture_output(), clip->texture_input()); - // FIXME: If this doesn't have a TimelineOutput node attached, this is a memory leak. Maybe switching nodes to - // shared ptrs would be a better idea. - emit parent()->RequestPlaceBlock(clip, ghost->In()); + if (event->keyboardModifiers() & Qt::ControlModifier) { + emit parent()->RequestPlaceBlock(clip, ghost->In()); + } else { + emit parent()->RequestInsertBlockAtTime(clip, ghost->In()); + } } parent()->ClearGhosts();