From dd3d11c7e0c29f69f4369d6eebfc2131ba99074d Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 2 Oct 2020 22:02:18 +1000 Subject: [PATCH] timeline: moved tools to separate files Code cleanup, TimelineWidget header was getting a little too bloated. --- app/config/config.cpp | 2 +- .../timelinewidget/timelinescaledobject.h | 2 +- app/widget/timelinewidget/timelinewidget.cpp | 88 +++- app/widget/timelinewidget/timelinewidget.h | 450 +++--------------- app/widget/timelinewidget/tool/CMakeLists.txt | 13 + app/widget/timelinewidget/tool/add.cpp | 19 +- app/widget/timelinewidget/tool/add.h | 47 ++ app/widget/timelinewidget/tool/beam.cpp | 9 +- app/widget/timelinewidget/tool/beam.h | 42 ++ app/widget/timelinewidget/tool/edit.cpp | 17 +- app/widget/timelinewidget/tool/edit.h | 48 ++ app/widget/timelinewidget/tool/import.cpp | 65 ++- app/widget/timelinewidget/tool/import.h | 91 ++++ app/widget/timelinewidget/tool/pointer.cpp | 95 ++-- app/widget/timelinewidget/tool/pointer.h | 127 +++++ app/widget/timelinewidget/tool/razor.cpp | 9 +- app/widget/timelinewidget/tool/razor.h | 43 ++ app/widget/timelinewidget/tool/ripple.cpp | 23 +- app/widget/timelinewidget/tool/ripple.h | 41 ++ app/widget/timelinewidget/tool/rolling.cpp | 5 +- app/widget/timelinewidget/tool/rolling.h | 40 ++ app/widget/timelinewidget/tool/slide.cpp | 5 +- app/widget/timelinewidget/tool/slide.h | 41 ++ app/widget/timelinewidget/tool/slip.cpp | 17 +- app/widget/timelinewidget/tool/slip.h | 40 ++ app/widget/timelinewidget/tool/tool.cpp | 50 +- app/widget/timelinewidget/tool/tool.h | 89 ++++ app/widget/timelinewidget/tool/transition.cpp | 25 +- app/widget/timelinewidget/tool/transition.h | 42 ++ app/widget/timelinewidget/tool/zoom.cpp | 25 +- app/widget/timelinewidget/tool/zoom.h | 41 ++ .../view/timelineviewghostitem.cpp | 30 +- .../view/timelineviewghostitem.h | 24 +- 33 files changed, 1103 insertions(+), 602 deletions(-) create mode 100644 app/widget/timelinewidget/tool/add.h create mode 100644 app/widget/timelinewidget/tool/beam.h create mode 100644 app/widget/timelinewidget/tool/edit.h create mode 100644 app/widget/timelinewidget/tool/import.h create mode 100644 app/widget/timelinewidget/tool/pointer.h create mode 100644 app/widget/timelinewidget/tool/razor.h create mode 100644 app/widget/timelinewidget/tool/ripple.h create mode 100644 app/widget/timelinewidget/tool/rolling.h create mode 100644 app/widget/timelinewidget/tool/slide.h create mode 100644 app/widget/timelinewidget/tool/slip.h create mode 100644 app/widget/timelinewidget/tool/tool.h create mode 100644 app/widget/timelinewidget/tool/transition.h create mode 100644 app/widget/timelinewidget/tool/zoom.h diff --git a/app/config/config.cpp b/app/config/config.cpp index f1dbe18fe..f2db463d7 100644 --- a/app/config/config.cpp +++ b/app/config/config.cpp @@ -87,7 +87,7 @@ void Config::SetDefaults() SetEntryInternal(QStringLiteral("AutoSelectDivider"), NodeParam::kBoolean, true); SetEntryInternal(QStringLiteral("SetNameWithMarker"), NodeParam::kBoolean, false); SetEntryInternal(QStringLiteral("RectifiedWaveforms"), NodeParam::kBoolean, false); - SetEntryInternal(QStringLiteral("DropWithoutSequenceBehavior"), NodeParam::kInt, TimelineWidget::kDWSAsk); + SetEntryInternal(QStringLiteral("DropWithoutSequenceBehavior"), NodeParam::kInt, ImportTool::kDWSAsk); SetEntryInternal(QStringLiteral("Loop"), NodeParam::kBoolean, false); SetEntryInternal(QStringLiteral("AutoCacheInterval"), NodeParam::kInt, 250); diff --git a/app/widget/timelinewidget/timelinescaledobject.h b/app/widget/timelinewidget/timelinescaledobject.h index c4aec301c..3b05f8e26 100644 --- a/app/widget/timelinewidget/timelinescaledobject.h +++ b/app/widget/timelinewidget/timelinescaledobject.h @@ -48,10 +48,10 @@ public: static double CalculateScaleFromDimensions(double viewport_sz, double content_sz); static double CalculatePaddingFromDimensionScale(double viewport_sz); -protected: double TimeToScene(const rational& time); rational SceneToTime(const double &x, bool round = false); +protected: virtual void TimebaseChangedEvent(const rational&){} virtual void ScaleChangedEvent(const double&){} diff --git a/app/widget/timelinewidget/timelinewidget.cpp b/app/widget/timelinewidget/timelinewidget.cpp index b21bf6092..a732e4c0d 100644 --- a/app/widget/timelinewidget/timelinewidget.cpp +++ b/app/widget/timelinewidget/timelinewidget.cpp @@ -30,6 +30,17 @@ #include "common/timecodefunctions.h" #include "dialog/sequence/sequence.h" #include "node/block/transition/transition.h" +#include "tool/add.h" +#include "tool/beam.h" +#include "tool/edit.h" +#include "tool/pointer.h" +#include "tool/razor.h" +#include "tool/ripple.h" +#include "tool/rolling.h" +#include "tool/slide.h" +#include "tool/slip.h" +#include "tool/transition.h" +#include "tool/zoom.h" #include "tool/tool.h" #include "trackview/trackview.h" #include "widget/menu/menu.h" @@ -354,22 +365,6 @@ void TimelineWidget::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, v } } -TimelineWidget::DraggedFootage TimelineWidget::FootageToDraggedFootage(Footage *f) -{ - return DraggedFootage(f, f->get_enabled_stream_flags()); -} - -QList TimelineWidget::FootageToDraggedFootage(QList footage) -{ - QList df; - - foreach (Footage* f, footage) { - df.append(FootageToDraggedFootage(f)); - } - - return df; -} - rational TimelineWidget::GetToolTipTimebase() const { if (GetConnectedNode() && use_audio_time_units_) { @@ -843,12 +838,7 @@ void TimelineWidget::ClearGhosts() HideSnaps(); } -bool TimelineWidget::HasGhosts() -{ - return !ghost_items_.isEmpty(); -} - -TimelineWidget::Tool *TimelineWidget::GetActiveTool() +TimelineTool *TimelineWidget::GetActiveTool() { return tools_.at(Core::instance()->tool()); } @@ -875,7 +865,7 @@ void TimelineWidget::ViewMouseMoved(TimelineViewMouseEvent *event) active_tool_->MouseMove(event); } else { // Mouse is not down, attempt a hover event - Tool* hover_tool = GetActiveTool(); + TimelineTool* hover_tool = GetActiveTool(); if (hover_tool) { hover_tool->HoverMove(event); @@ -1223,6 +1213,24 @@ void TimelineWidget::SetBlockLinksSelected(Block* block, bool selected) } } +void TimelineWidget::QueueScroll(int value) +{ + // (using a hacky singleShot so the scroll occurs after the scene and its scrollbars have updated) + deferred_scroll_value_ = value; + + QTimer::singleShot(0, this, &TimelineWidget::DeferredScrollAction); +} + +TimelineView *TimelineWidget::GetFirstTimelineView() +{ + return views_.first()->view(); +} + +const QRect& TimelineWidget::GetRubberBandGeometry() const +{ + return rubberband_.geometry(); +} + QVector TimelineWidget::GetEditToInfo(const rational& playhead_time, Timeline::MovementMode mode) { @@ -1519,6 +1527,40 @@ void TimelineWidget::RemoveSelection(TimelineViewBlockItem *item) RemoveSelection(item->block()->range(), item->Track()); } +void TimelineWidget::ShiftSelections(const rational &diff) +{ + for (auto it=selections_.begin(); it!=selections_.end(); it++) { + for (auto it2=it.value().begin(); it2!=it.value().end(); it2++) { + (*it2) += diff; + } + } +} + +void TimelineWidget::SetSelections(const TimelineWidget::Selections &s) +{ + selections_ = s; + + foreach (TimelineAndTrackView* tview, views_) { + tview->view()->viewport(),update(); + } +} + +TimelineViewBlockItem *TimelineWidget::GetItemAtScenePos(const TimelineCoordinate& coord) +{ + for (auto it=block_items_.cbegin(); it!=block_items_.cend(); it++) { + Block* b = it.key(); + TimelineViewBlockItem* item = it.value(); + + if (b->in() <= coord.GetFrame() + && b->out() > coord.GetFrame() + && item->Track() == coord.GetTrack()) { + return item; + } + } + + return nullptr; +} + bool TimelineWidget::IsItemSelected(TimelineViewBlockItem *item) const { return selections_[item->Track()].ContainsTimeRange(item->block()->range()); diff --git a/app/widget/timelinewidget/timelinewidget.h b/app/widget/timelinewidget/timelinewidget.h index f7121af03..89d91633e 100644 --- a/app/widget/timelinewidget/timelinewidget.h +++ b/app/widget/timelinewidget/timelinewidget.h @@ -34,6 +34,8 @@ #include "widget/nodecopypaste/nodecopypaste.h" #include "widget/slider/timeslider.h" #include "widget/timebased/timebased.h" +#include "widget/timelinewidget/tool/import.h" +#include "widget/timelinewidget/tool/tool.h" OLIVE_NAMESPACE_ENTER @@ -46,13 +48,6 @@ class TimelineWidget : public TimeBasedWidget, public NodeCopyPasteWidget, publi { Q_OBJECT public: - enum DropWithoutSequenceBehavior { - kDWSAsk, - kDWSAuto, - kDWSManual, - kDWSDisable - }; - TimelineWidget(QWidget* parent = nullptr); virtual ~TimelineWidget() override; @@ -105,6 +100,75 @@ public: static void ReplaceBlocksWithGaps(const QList& blocks, bool remove_from_graph, QUndoCommand* command); + /** + * @brief Retrieve the QGraphicsItem at a particular scene position + * + * Requires a float-based scene position. If you have a screen position, use GetScenePos() first to convert it to a + * scene position + */ + TimelineViewBlockItem* GetItemAtScenePos(const TimelineCoordinate &coord); + + const QMap& GetBlockItems() const + { + return block_items_; + } + + using Selections = QHash; + + void AddSelection(const TimeRange& time, const TrackReference& track); + void AddSelection(TimelineViewBlockItem* item); + + void RemoveSelection(const TimeRange& time, const TrackReference& track); + void RemoveSelection(TimelineViewBlockItem* item); + + void ShiftSelections(const rational& diff); + + const Selections& GetSelections() const + { + return selections_; + } + + void SetSelections(const Selections& s); + + TrackOutput* GetTrackFromReference(const TrackReference& ref); + + void SetViewBeamCursor(const TimelineCoordinate& coord); + + const QVector& GetGhostItems() const + { + return ghost_items_; + } + + void InsertGapsAt(const rational& time, const rational& length, QUndoCommand* command); + + void StartRubberBandSelect(bool enable_selecting, bool select_links); + void MoveRubberBandSelect(bool enable_selecting, bool select_links); + void EndRubberBandSelect(); + + int GetTrackY(const TrackReference& ref); + int GetTrackHeight(const TrackReference& ref); + + void AddGhost(TimelineViewGhostItem* ghost); + + void ClearGhosts(); + + bool HasGhosts() const + { + return !ghost_items_.isEmpty(); + } + + rational GetToolTipTimebase() const; + + bool IsItemSelected(TimelineViewBlockItem* item) const; + + void SetBlockLinksSelected(Block *block, bool selected); + + void QueueScroll(int value); + + TimelineView* GetFirstTimelineView(); + + const QRect &GetRubberBandGeometry() const; + signals: void BlocksSelected(const QList& selected_blocks); @@ -131,346 +195,6 @@ protected: }; private: - class DraggedFootage { - public: - DraggedFootage(Footage* f, quint64 streams) : - footage_(f), - streams_(streams) - { - } - - Footage* footage() const { - return footage_; - } - - const quint64& streams() const { - return streams_; - } - - private: - Footage* footage_; - - quint64 streams_; - - }; - - static DraggedFootage FootageToDraggedFootage(Footage* f); - static QList FootageToDraggedFootage(QList footage); - - class Tool - { - public: - Tool(TimelineWidget* parent); - virtual ~Tool(); - - virtual void MousePress(TimelineViewMouseEvent *){} - virtual void MouseMove(TimelineViewMouseEvent *){} - virtual void MouseRelease(TimelineViewMouseEvent *){} - virtual void MouseDoubleClick(TimelineViewMouseEvent *){} - - virtual void HoverMove(TimelineViewMouseEvent *){} - - virtual void DragEnter(TimelineViewMouseEvent *){} - virtual void DragMove(TimelineViewMouseEvent *){} - virtual void DragLeave(QDragLeaveEvent *){} - virtual void DragDrop(TimelineViewMouseEvent *){} - - TimelineWidget* parent(); - - static Timeline::MovementMode FlipTrimMode(const Timeline::MovementMode& trim_mode); - - protected: - /** - * @brief Retrieve the QGraphicsItem at a particular scene position - * - * Requires a float-based scene position. If you have a screen position, use GetScenePos() first to convert it to a - * scene position - */ - TimelineViewBlockItem* GetItemAtScenePos(const TimelineCoordinate &coord); - - /** - * @brief Validates Ghosts that are moving horizontally (time-based) - * - * Validation is the process of ensuring that whatever movements the user is making are "valid" and "legal". This - * function's validation ensures that no Ghost's in point ends up in a negative timecode. - */ - rational ValidateTimeMovement(rational movement); - - /** - * @brief Validates Ghosts that are moving vertically (track-based) - * - * This function's validation ensures that no Ghost's track ends up in a negative (non-existent) track. - */ - int ValidateTrackMovement(int movement, const QVector &ghosts); - - void GetGhostData(rational *earliest_point, rational *latest_point); - - void InsertGapsAtGhostDestination(QUndoCommand* command); - - QList snap_points_; - - bool dragging_; - - TimelineCoordinate drag_start_; - - private: - TimelineWidget* parent_; - - }; - - class BeamTool : public Tool - { - public: - BeamTool(TimelineWidget *parent); - - virtual void HoverMove(TimelineViewMouseEvent *event) override; - - protected: - TimelineCoordinate ValidatedCoordinate(TimelineCoordinate coord); - - }; - - class PointerTool : public Tool - { - public: - PointerTool(TimelineWidget* parent); - - virtual void MousePress(TimelineViewMouseEvent *event) override; - virtual void MouseMove(TimelineViewMouseEvent *event) override; - virtual void MouseRelease(TimelineViewMouseEvent *event) override; - - virtual void HoverMove(TimelineViewMouseEvent *event) override; - - protected: - virtual void FinishDrag(TimelineViewMouseEvent *event); - - virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, - Timeline::MovementMode trim_mode); - - TimelineViewGhostItem* AddGhostFromBlock(Block *block, const TrackReference& track, Timeline::MovementMode mode, bool check_if_exists = false); - - TimelineViewGhostItem* AddGhostFromNull(const rational& in, const rational& out, const TrackReference& track, Timeline::MovementMode mode); - - /** - * @brief Validates Ghosts that are getting their in points trimmed - * - * Assumes ghost->data() is a Block. Ensures no Ghost's in point becomes a negative timecode. Also ensures no - * Ghost's length becomes 0 or negative. - */ - rational ValidateInTrimming(rational movement); - - /** - * @brief Validates Ghosts that are getting their out points trimmed - * - * Assumes ghost->data() is a Block. Ensures no Ghost's in point becomes a negative timecode. Also ensures no - * Ghost's length becomes 0 or negative. - */ - rational ValidateOutTrimming(rational movement); - - virtual void ProcessDrag(const TimelineCoordinate &mouse_pos); - - void InitiateDragInternal(TimelineViewBlockItem* clicked_item, - Timeline::MovementMode trim_mode, - bool dont_roll_trims, - bool allow_nongap_rolling, bool slide_instead_of_moving); - - const Timeline::MovementMode& drag_movement_mode() const - { - return drag_movement_mode_; - } - - void SetMovementAllowed(bool e) - { - movement_allowed_ = e; - } - - void SetTrimmingAllowed(bool e) - { - trimming_allowed_ = e; - } - - void SetTrackMovementAllowed(bool e) - { - track_movement_allowed_ = e; - } - - void SetGapTrimmingAllowed(bool e) - { - gap_trimming_allowed_ = e; - } - - private: - Timeline::MovementMode IsCursorInTrimHandle(TimelineViewBlockItem* block, qreal cursor_x); - - void AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode); - - bool IsClipTrimmable(TimelineViewBlockItem* clip, - const QList& items, - const Timeline::MovementMode& mode); - - void ProcessGhostsForSliding(); - - void ProcessGhostsForRolling(); - - bool AddMovingTransitionsToClipGhost(Block *block, const TrackReference &track, Timeline::MovementMode movement, const QList &selected_items); - - bool movement_allowed_; - bool trimming_allowed_; - bool track_movement_allowed_; - bool gap_trimming_allowed_; - bool rubberband_selecting_; - - Timeline::TrackType drag_track_type_; - Timeline::MovementMode drag_movement_mode_; - - TimelineViewBlockItem* clicked_item_; - - }; - - class ImportTool : public Tool - { - public: - ImportTool(TimelineWidget* parent); - - virtual void DragEnter(TimelineViewMouseEvent *event) override; - virtual void DragMove(TimelineViewMouseEvent *event) override; - virtual void DragLeave(QDragLeaveEvent *event) override; - virtual void DragDrop(TimelineViewMouseEvent *event) override; - - void PlaceAt(const QList &footage, const rational& start, bool insert); - void PlaceAt(const QList &footage, const rational& start, bool insert); - - private: - void FootageToGhosts(rational ghost_start, const QList& footage, const rational &dest_tb, const int &track_start); - - void PrepGhosts(const rational &frame, const int &track_index); - - void DropGhosts(bool insert); - - QList dragged_footage_; - - int import_pre_buffer_; - - }; - - class EditTool : public BeamTool - { - public: - EditTool(TimelineWidget* parent); - - virtual void MousePress(TimelineViewMouseEvent *event) override; - virtual void MouseMove(TimelineViewMouseEvent *event) override; - virtual void MouseRelease(TimelineViewMouseEvent *event) override; - virtual void MouseDoubleClick(TimelineViewMouseEvent *event) override; - - private: - QHash start_selections_; - - TimelineCoordinate start_coord_; - - }; - - class RazorTool : public BeamTool - { - public: - RazorTool(TimelineWidget* parent); - - virtual void MousePress(TimelineViewMouseEvent *event) override; - virtual void MouseMove(TimelineViewMouseEvent *event) override; - virtual void MouseRelease(TimelineViewMouseEvent *event) override; - - private: - QVector split_tracks_; - }; - - class RippleTool : public PointerTool - { - public: - RippleTool(TimelineWidget* parent); - protected: - virtual void FinishDrag(TimelineViewMouseEvent *event) override; - - virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, - Timeline::MovementMode trim_mode) override; - }; - - class RollingTool : public PointerTool - { - public: - RollingTool(TimelineWidget* parent); - - protected: - virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, - Timeline::MovementMode trim_mode) override; - }; - - class SlideTool : public PointerTool - { - public: - SlideTool(TimelineWidget* parent); - - protected: - virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, - Timeline::MovementMode trim_mode) override; - - }; - - class SlipTool : public PointerTool - { - public: - SlipTool(TimelineWidget* parent); - - protected: - virtual void ProcessDrag(const TimelineCoordinate &mouse_pos) override; - virtual void FinishDrag(TimelineViewMouseEvent *event) override; - }; - - class ZoomTool : public Tool - { - public: - ZoomTool(TimelineWidget* parent); - - virtual void MousePress(TimelineViewMouseEvent *event) override; - virtual void MouseMove(TimelineViewMouseEvent *event) override; - virtual void MouseRelease(TimelineViewMouseEvent *event) override; - - }; - - class AddTool : public BeamTool - { - public: - AddTool(TimelineWidget* parent); - - virtual void MousePress(TimelineViewMouseEvent *event) override; - virtual void MouseMove(TimelineViewMouseEvent *event) override; - virtual void MouseRelease(TimelineViewMouseEvent *event) override; - - protected: - void MouseMoveInternal(const rational& cursor_frame, bool outwards); - - TimelineViewGhostItem* ghost_; - - rational drag_start_point_; - }; - - class TransitionTool : public AddTool - { - public: - TransitionTool(TimelineWidget* parent); - - virtual void MousePress(TimelineViewMouseEvent *event) override; - virtual void MouseMove(TimelineViewMouseEvent *event) override; - virtual void MouseRelease(TimelineViewMouseEvent *event) override; - private: - bool dual_transition_; - }; - - rational GetToolTipTimebase() const; - - void InsertGapsAt(const rational& time, const rational& length, QUndoCommand* command); - - void SetBlockLinksSelected(Block *block, bool selected); - QVector GetEditToInfo(const rational &playhead_time, Timeline::MovementMode mode); void RippleTo(Timeline::MovementMode mode); @@ -481,41 +205,24 @@ private: QPoint drag_origin_; - void StartRubberBandSelect(bool enable_selecting, bool select_links); - void MoveRubberBandSelect(bool enable_selecting, bool select_links); - void EndRubberBandSelect(); QRubberBand rubberband_; QList rubberband_already_selected_; QList rubberband_now_selected_; - QHash selections_; + Selections selections_; - void AddSelection(const TimeRange& time, const TrackReference& track); - void AddSelection(TimelineViewBlockItem* item); + TimelineTool* GetActiveTool(); - void RemoveSelection(const TimeRange& time, const TrackReference& track); - void RemoveSelection(TimelineViewBlockItem* item); - - bool IsItemSelected(TimelineViewBlockItem* item) const; - - Tool* GetActiveTool(); - - QVector tools_; + QVector tools_; ImportTool* import_tool_; - Tool* active_tool_; - - void ClearGhosts(); - - bool HasGhosts(); + TimelineTool* active_tool_; QVector ghost_items_; QMap block_items_; - TrackOutput* GetTrackFromReference(const TrackReference& ref); - QList views_; TimeSlider* timecode_label_; @@ -526,17 +233,10 @@ private: QSplitter* view_splitter_; - int GetTrackY(const TrackReference& ref); - int GetTrackHeight(const TrackReference& ref); - void CenterOn(qreal scene_pos); - void AddGhost(TimelineViewGhostItem* ghost); - void UpdateViewTimebases(); - void SetViewBeamCursor(const TimelineCoordinate& coord); - private slots: void ViewMousePressed(TimelineViewMouseEvent* event); void ViewMouseMoved(TimelineViewMouseEvent* event); diff --git a/app/widget/timelinewidget/tool/CMakeLists.txt b/app/widget/timelinewidget/tool/CMakeLists.txt index f14d4a8de..4e9850fc0 100644 --- a/app/widget/timelinewidget/tool/CMakeLists.txt +++ b/app/widget/timelinewidget/tool/CMakeLists.txt @@ -17,17 +17,30 @@ set(OLIVE_SOURCES ${OLIVE_SOURCES} widget/timelinewidget/tool/add.cpp + widget/timelinewidget/tool/add.h widget/timelinewidget/tool/beam.cpp + widget/timelinewidget/tool/beam.h widget/timelinewidget/tool/edit.cpp + widget/timelinewidget/tool/edit.h widget/timelinewidget/tool/import.cpp + widget/timelinewidget/tool/import.h widget/timelinewidget/tool/pointer.cpp + widget/timelinewidget/tool/pointer.h widget/timelinewidget/tool/razor.cpp + widget/timelinewidget/tool/razor.h widget/timelinewidget/tool/ripple.cpp + widget/timelinewidget/tool/ripple.h widget/timelinewidget/tool/rolling.cpp + widget/timelinewidget/tool/rolling.h widget/timelinewidget/tool/slide.cpp + widget/timelinewidget/tool/slide.h widget/timelinewidget/tool/slip.cpp + widget/timelinewidget/tool/slip.h widget/timelinewidget/tool/transition.cpp + widget/timelinewidget/tool/transition.h widget/timelinewidget/tool/tool.cpp + widget/timelinewidget/tool/tool.h widget/timelinewidget/tool/zoom.cpp + widget/timelinewidget/tool/zoom.h PARENT_SCOPE ) diff --git a/app/widget/timelinewidget/tool/add.cpp b/app/widget/timelinewidget/tool/add.cpp index f488bbfca..eefbf6e37 100644 --- a/app/widget/timelinewidget/tool/add.cpp +++ b/app/widget/timelinewidget/tool/add.cpp @@ -20,6 +20,7 @@ #include "widget/timelinewidget/timelinewidget.h" +#include "add.h" #include "core.h" #include "node/factory.h" #include "node/generator/solid/solid.h" @@ -28,13 +29,13 @@ OLIVE_NAMESPACE_ENTER -TimelineWidget::AddTool::AddTool(TimelineWidget *parent) : +AddTool::AddTool(TimelineWidget *parent) : BeamTool(parent), ghost_(nullptr) { } -void TimelineWidget::AddTool::MousePress(TimelineViewMouseEvent *event) +void AddTool::MousePress(TimelineViewMouseEvent *event) { const TrackReference& track = event->GetTrack(); @@ -78,7 +79,7 @@ void TimelineWidget::AddTool::MousePress(TimelineViewMouseEvent *event) } } -void TimelineWidget::AddTool::MouseMove(TimelineViewMouseEvent *event) +void AddTool::MouseMove(TimelineViewMouseEvent *event) { if (!ghost_) { return; @@ -87,16 +88,16 @@ void TimelineWidget::AddTool::MouseMove(TimelineViewMouseEvent *event) MouseMoveInternal(event->GetFrame(), event->GetModifiers() & Qt::AltModifier); } -void TimelineWidget::AddTool::MouseRelease(TimelineViewMouseEvent *event) +void AddTool::MouseRelease(TimelineViewMouseEvent *event) { const TrackReference& track = ghost_->Track(); if (ghost_) { - if (!ghost_->AdjustedLength().isNull()) { + if (!ghost_->GetAdjustedLength().isNull()) { QUndoCommand* command = new QUndoCommand(); ClipBlock* clip = new ClipBlock(); - clip->set_length_and_media_out(ghost_->AdjustedLength()); + clip->set_length_and_media_out(ghost_->GetAdjustedLength()); clip->SetLabel(OLIVE_NAMESPACE::Tool::GetAddableObjectName(Core::instance()->GetSelectedAddableObject())); NodeGraph* graph = static_cast(parent()->GetConnectedNode()->parent()); @@ -156,14 +157,14 @@ void TimelineWidget::AddTool::MouseRelease(TimelineViewMouseEvent *event) } } -void TimelineWidget::AddTool::MouseMoveInternal(const rational &cursor_frame, bool outwards) +void AddTool::MouseMoveInternal(const rational &cursor_frame, bool outwards) { // Calculate movement rational movement = cursor_frame - drag_start_point_; // Validation: Ensure in point never goes below 0 - if (movement < -ghost_->In() || (outwards && -movement < -ghost_->In())) { - movement = -ghost_->In(); + if (movement < -ghost_->GetIn() || (outwards && -movement < -ghost_->GetIn())) { + movement = -ghost_->GetIn(); } // Snap movement diff --git a/app/widget/timelinewidget/tool/add.h b/app/widget/timelinewidget/tool/add.h new file mode 100644 index 000000000..eabbdf3c9 --- /dev/null +++ b/app/widget/timelinewidget/tool/add.h @@ -0,0 +1,47 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef ADDTIMELINETOOL_H +#define ADDTIMELINETOOL_H + +#include "beam.h" + +OLIVE_NAMESPACE_ENTER + +class AddTool : public BeamTool +{ +public: + AddTool(TimelineWidget* parent); + + virtual void MousePress(TimelineViewMouseEvent *event) override; + virtual void MouseMove(TimelineViewMouseEvent *event) override; + virtual void MouseRelease(TimelineViewMouseEvent *event) override; + +protected: + void MouseMoveInternal(const rational& cursor_frame, bool outwards); + + TimelineViewGhostItem* ghost_; + + rational drag_start_point_; +}; + +OLIVE_NAMESPACE_EXIT + +#endif // ADDTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/beam.cpp b/app/widget/timelinewidget/tool/beam.cpp index e2fe1120e..574f2077e 100644 --- a/app/widget/timelinewidget/tool/beam.cpp +++ b/app/widget/timelinewidget/tool/beam.cpp @@ -18,21 +18,22 @@ ***/ +#include "beam.h" #include "widget/timelinewidget/timelinewidget.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::BeamTool::BeamTool(TimelineWidget *parent) : - Tool(parent) +BeamTool::BeamTool(TimelineWidget *parent) : + TimelineTool(parent) { } -void TimelineWidget::BeamTool::HoverMove(TimelineViewMouseEvent *event) +void BeamTool::HoverMove(TimelineViewMouseEvent *event) { parent()->SetViewBeamCursor(ValidatedCoordinate(event->GetCoordinates(true))); } -TimelineCoordinate TimelineWidget::BeamTool::ValidatedCoordinate(TimelineCoordinate coord) +TimelineCoordinate BeamTool::ValidatedCoordinate(TimelineCoordinate coord) { if (Core::instance()->snapping()) { rational movement; diff --git a/app/widget/timelinewidget/tool/beam.h b/app/widget/timelinewidget/tool/beam.h new file mode 100644 index 000000000..7949474c2 --- /dev/null +++ b/app/widget/timelinewidget/tool/beam.h @@ -0,0 +1,42 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef BEAMTIMELINETOOL_H +#define BEAMTIMELINETOOL_H + +#include "tool.h" + +OLIVE_NAMESPACE_ENTER + +class BeamTool : public TimelineTool +{ +public: + BeamTool(TimelineWidget *parent); + + virtual void HoverMove(TimelineViewMouseEvent *event) override; + +protected: + TimelineCoordinate ValidatedCoordinate(TimelineCoordinate coord); + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // BEAMTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/edit.cpp b/app/widget/timelinewidget/tool/edit.cpp index e8b79f312..ff8c9b9e4 100644 --- a/app/widget/timelinewidget/tool/edit.cpp +++ b/app/widget/timelinewidget/tool/edit.cpp @@ -18,30 +18,31 @@ ***/ +#include "edit.h" #include "widget/timelinewidget/timelinewidget.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::EditTool::EditTool(TimelineWidget* parent) : +EditTool::EditTool(TimelineWidget* parent) : BeamTool(parent) { } -void TimelineWidget::EditTool::MousePress(TimelineViewMouseEvent *event) +void EditTool::MousePress(TimelineViewMouseEvent *event) { if (!(event->GetModifiers() & Qt::ShiftModifier)) { parent()->DeselectAll(); } } -void TimelineWidget::EditTool::MouseMove(TimelineViewMouseEvent *event) +void EditTool::MouseMove(TimelineViewMouseEvent *event) { if (dragging_) { - parent()->selections_ = start_selections_; + parent()->SetSelections(start_selections_); parent()->AddSelection(TimeRange(start_coord_.GetFrame(), event->GetFrame()), start_coord_.GetTrack()); } else { - start_selections_ = parent()->selections_; + start_selections_ = parent()->GetSelections(); dragging_ = true; @@ -60,14 +61,14 @@ void TimelineWidget::EditTool::MouseMove(TimelineViewMouseEvent *event) } } -void TimelineWidget::EditTool::MouseRelease(TimelineViewMouseEvent *event) +void EditTool::MouseRelease(TimelineViewMouseEvent *event) { dragging_ = false; } -void TimelineWidget::EditTool::MouseDoubleClick(TimelineViewMouseEvent *event) +void EditTool::MouseDoubleClick(TimelineViewMouseEvent *event) { - TimelineViewBlockItem* item = GetItemAtScenePos(event->GetCoordinates()); + TimelineViewBlockItem* item = parent()->GetItemAtScenePos(event->GetCoordinates()); if (item && !parent()->GetTrackFromReference(item->Track())->IsLocked()) { parent()->AddSelection(item); diff --git a/app/widget/timelinewidget/tool/edit.h b/app/widget/timelinewidget/tool/edit.h new file mode 100644 index 000000000..8029014db --- /dev/null +++ b/app/widget/timelinewidget/tool/edit.h @@ -0,0 +1,48 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef EDITTIMELINETOOL_H +#define EDITTIMELINETOOL_H + +#include "beam.h" +#include "tool.h" + +OLIVE_NAMESPACE_ENTER + +class EditTool : public BeamTool +{ +public: + EditTool(TimelineWidget* parent); + + virtual void MousePress(TimelineViewMouseEvent *event) override; + virtual void MouseMove(TimelineViewMouseEvent *event) override; + virtual void MouseRelease(TimelineViewMouseEvent *event) override; + virtual void MouseDoubleClick(TimelineViewMouseEvent *event) override; + +private: + QHash start_selections_; + + TimelineCoordinate start_coord_; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // EDITTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/import.cpp b/app/widget/timelinewidget/tool/import.cpp index 9850a6eab..0d8376d09 100644 --- a/app/widget/timelinewidget/tool/import.cpp +++ b/app/widget/timelinewidget/tool/import.cpp @@ -60,14 +60,14 @@ Timeline::TrackType TrackTypeFromStreamType(Stream::Type stream_type) return Timeline::kTrackTypeNone; } -TimelineWidget::ImportTool::ImportTool(TimelineWidget *parent) : - Tool(parent) +ImportTool::ImportTool(TimelineWidget *parent) : + TimelineTool(parent) { // Calculate width used for importing to give ghosts a slight lead-in so the ghosts aren't right on the cursor import_pre_buffer_ = QFontMetricsWidth(parent->fontMetrics(), "HHHHHHHH"); } -void TimelineWidget::ImportTool::DragEnter(TimelineViewMouseEvent *event) +void ImportTool::DragEnter(TimelineViewMouseEvent *event) { QStringList mime_formats = event->GetMimeData()->formats(); @@ -115,7 +115,7 @@ void TimelineWidget::ImportTool::DragEnter(TimelineViewMouseEvent *event) } } -void TimelineWidget::ImportTool::DragMove(TimelineViewMouseEvent *event) +void ImportTool::DragMove(TimelineViewMouseEvent *event) { if (!dragged_footage_.isEmpty()) { @@ -124,20 +124,20 @@ void TimelineWidget::ImportTool::DragMove(TimelineViewMouseEvent *event) int track_movement = event->GetTrack().index() - drag_start_.GetTrack().index(); time_movement = ValidateTimeMovement(time_movement); - track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_); + track_movement = ValidateTrackMovement(track_movement, parent()->GetGhostItems()); // If snapping is enabled, check for snap points if (Core::instance()->snapping()) { parent()->SnapPoint(snap_points_, &time_movement); time_movement = ValidateTimeMovement(time_movement); - track_movement = ValidateTrackMovement(track_movement, parent()->ghost_items_); + track_movement = ValidateTrackMovement(track_movement, parent()->GetGhostItems()); } rational earliest_ghost = RATIONAL_MAX; // Move ghosts to the mouse cursor - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { ghost->SetInAdjustment(time_movement); ghost->SetOutAdjustment(time_movement); ghost->SetTrackAdjustment(track_movement); @@ -168,7 +168,7 @@ void TimelineWidget::ImportTool::DragMove(TimelineViewMouseEvent *event) } } -void TimelineWidget::ImportTool::DragLeave(QDragLeaveEvent* event) +void ImportTool::DragLeave(QDragLeaveEvent* event) { if (!dragged_footage_.isEmpty()) { parent()->ClearGhosts(); @@ -180,7 +180,7 @@ void TimelineWidget::ImportTool::DragLeave(QDragLeaveEvent* event) } } -void TimelineWidget::ImportTool::DragDrop(TimelineViewMouseEvent *event) +void ImportTool::DragDrop(TimelineViewMouseEvent *event) { if (!dragged_footage_.isEmpty()) { DropGhosts(event->GetModifiers() & Qt::ControlModifier); @@ -191,12 +191,12 @@ void TimelineWidget::ImportTool::DragDrop(TimelineViewMouseEvent *event) } } -void TimelineWidget::ImportTool::PlaceAt(const QList &footage, const rational &start, bool insert) +void ImportTool::PlaceAt(const QList &footage, const rational &start, bool insert) { PlaceAt(FootageToDraggedFootage(footage), start, insert); } -void TimelineWidget::ImportTool::PlaceAt(const QList &footage, const rational &start, bool insert) +void ImportTool::PlaceAt(const QList &footage, const rational &start, bool insert) { dragged_footage_ = footage; @@ -208,7 +208,7 @@ void TimelineWidget::ImportTool::PlaceAt(const QList &footage, c DropGhosts(insert); } -void TimelineWidget::ImportTool::FootageToGhosts(rational ghost_start, const QList &footage_list, const rational& dest_tb, const int& track_start) +void ImportTool::FootageToGhosts(rational ghost_start, const QList &footage_list, const rational& dest_tb, const int& track_start) { foreach (const DraggedFootage& footage, footage_list) { @@ -274,8 +274,8 @@ void TimelineWidget::ImportTool::FootageToGhosts(rational ghost_start, const QLi ghost->SetIn(ghost_start); ghost->SetOut(ghost_start + footage_duration); - snap_points_.append(ghost->In()); - snap_points_.append(ghost->Out()); + snap_points_.append(ghost->GetIn()); + snap_points_.append(ghost->GetOut()); parent()->AddGhost(ghost); } @@ -286,7 +286,7 @@ void TimelineWidget::ImportTool::FootageToGhosts(rational ghost_start, const QLi } } -void TimelineWidget::ImportTool::PrepGhosts(const rational& frame, const int& track_index) +void ImportTool::PrepGhosts(const rational& frame, const int& track_index) { if (parent()->GetConnectedNode()) { FootageToGhosts(frame, @@ -296,7 +296,7 @@ void TimelineWidget::ImportTool::PrepGhosts(const rational& frame, const int& tr } } -void TimelineWidget::ImportTool::DropGhosts(bool insert) +void ImportTool::DropGhosts(bool insert) { QUndoCommand* command = new QUndoCommand(); @@ -394,21 +394,21 @@ void TimelineWidget::ImportTool::DropGhosts(bool insert) if (dst_graph) { - QVector block_items(parent()->ghost_items_.size()); + QVector block_items(parent()->GetGhostItems().size()); // Check if we're inserting if (insert) { InsertGapsAtGhostDestination(command); } - for (int i=0;ighost_items_.size();i++) { - TimelineViewGhostItem* ghost = parent()->ghost_items_.at(i); + for (int i=0;iGetGhostItems().size();i++) { + TimelineViewGhostItem* ghost = parent()->GetGhostItems().at(i); StreamPtr footage_stream = ghost->data(TimelineViewGhostItem::kAttachedFootage).value(); ClipBlock* clip = new ClipBlock(); - clip->set_media_in(ghost->MediaIn()); - clip->set_length_and_media_out(ghost->Length()); + clip->set_media_in(ghost->GetMediaIn()); + clip->set_length_and_media_out(ghost->GetLength()); clip->SetLabel(footage_stream->footage()->name()); new NodeAddCommand(dst_graph, clip, command); @@ -463,7 +463,7 @@ void TimelineWidget::ImportTool::DropGhosts(bool insert) // Link any clips so far that share the same Footage with this one for (int j=0;jghost_items_.at(j)->data(TimelineViewGhostItem::kAttachedFootage).value(); + StreamPtr footage_compare = parent()->GetGhostItems().at(j)->data(TimelineViewGhostItem::kAttachedFootage).value(); if (footage_compare->footage() == footage_stream->footage()) { Block::Link(block_items.at(j), clip); @@ -482,4 +482,25 @@ void TimelineWidget::ImportTool::DropGhosts(bool insert) } } +ImportTool::DraggedFootage ImportTool::FootageToDraggedFootage(Footage *f) +{ + return DraggedFootage(f, f->get_enabled_stream_flags()); +} + +QList ImportTool::FootageToDraggedFootage(QList footage) +{ + QList df; + + foreach (Footage* f, footage) { + df.append(FootageToDraggedFootage(f)); + } + + return df; +} + +QString ImportTool::tr(const char *s) +{ + return QCoreApplication::translate("ImportTool", s); +} + OLIVE_NAMESPACE_EXIT diff --git a/app/widget/timelinewidget/tool/import.h b/app/widget/timelinewidget/tool/import.h new file mode 100644 index 000000000..a90c82c49 --- /dev/null +++ b/app/widget/timelinewidget/tool/import.h @@ -0,0 +1,91 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef IMPORTTIMELINETOOL_H +#define IMPORTTIMELINETOOL_H + +#include "tool.h" + +OLIVE_NAMESPACE_ENTER + +class ImportTool : public TimelineTool +{ +public: + ImportTool(TimelineWidget* parent); + + virtual void DragEnter(TimelineViewMouseEvent *event) override; + virtual void DragMove(TimelineViewMouseEvent *event) override; + virtual void DragLeave(QDragLeaveEvent *event) override; + virtual void DragDrop(TimelineViewMouseEvent *event) override; + + class DraggedFootage { + public: + DraggedFootage(Footage* f, quint64 streams) : + footage_(f), + streams_(streams) + { + } + + Footage* footage() const { + return footage_; + } + + const quint64& streams() const { + return streams_; + } + + private: + Footage* footage_; + + quint64 streams_; + + }; + + void PlaceAt(const QList &footage, const rational& start, bool insert); + void PlaceAt(const QList &footage, const rational& start, bool insert); + + enum DropWithoutSequenceBehavior { + kDWSAsk, + kDWSAuto, + kDWSManual, + kDWSDisable + }; + +private: + static DraggedFootage FootageToDraggedFootage(Footage* f); + static QList FootageToDraggedFootage(QList footage); + + QString tr(const char* s); + + void FootageToGhosts(rational ghost_start, const QList& footage, const rational &dest_tb, const int &track_start); + + void PrepGhosts(const rational &frame, const int &track_index); + + void DropGhosts(bool insert); + + QList dragged_footage_; + + int import_pre_buffer_; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // IMPORTTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/pointer.cpp b/app/widget/timelinewidget/tool/pointer.cpp index 186b8e93e..31314d133 100644 --- a/app/widget/timelinewidget/tool/pointer.cpp +++ b/app/widget/timelinewidget/tool/pointer.cpp @@ -32,12 +32,13 @@ #include "core.h" #include "node/block/gap/gap.h" #include "node/block/transition/transition.h" +#include "pointer.h" #include "widget/nodeview/nodeviewundo.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::PointerTool::PointerTool(TimelineWidget *parent) : - Tool(parent), +PointerTool::PointerTool(TimelineWidget *parent) : + TimelineTool(parent), movement_allowed_(true), trimming_allowed_(true), track_movement_allowed_(true), @@ -46,10 +47,10 @@ TimelineWidget::PointerTool::PointerTool(TimelineWidget *parent) : { } -void TimelineWidget::PointerTool::MousePress(TimelineViewMouseEvent *event) +void PointerTool::MousePress(TimelineViewMouseEvent *event) { // Determine if item clicked on is selectable - clicked_item_ = GetItemAtScenePos(event->GetCoordinates()); + clicked_item_ = parent()->GetItemAtScenePos(event->GetCoordinates()); bool selectable_item = (clicked_item_ && !parent()->GetTrackFromReference(clicked_item_->Track())->IsLocked()); @@ -130,7 +131,7 @@ void TimelineWidget::PointerTool::MousePress(TimelineViewMouseEvent *event) } } -void TimelineWidget::PointerTool::MouseMove(TimelineViewMouseEvent *event) +void PointerTool::MouseMove(TimelineViewMouseEvent *event) { if (rubberband_selecting_) { // Process rubberband select @@ -154,7 +155,7 @@ void TimelineWidget::PointerTool::MouseMove(TimelineViewMouseEvent *event) } - if (dragging_ && !parent()->ghost_items_.isEmpty()) { + if (dragging_ && !parent()->GetGhostItems().isEmpty()) { // We're already dragging AND we have ghosts to work with ProcessDrag(event->GetCoordinates()); @@ -163,7 +164,7 @@ void TimelineWidget::PointerTool::MouseMove(TimelineViewMouseEvent *event) } } -void TimelineWidget::PointerTool::MouseRelease(TimelineViewMouseEvent *event) +void PointerTool::MouseRelease(TimelineViewMouseEvent *event) { if (rubberband_selecting_) { // Finish rubberband select @@ -174,7 +175,7 @@ void TimelineWidget::PointerTool::MouseRelease(TimelineViewMouseEvent *event) if (dragging_) { // If we were dragging, process the end of the drag - if (!parent()->ghost_items_.isEmpty()) { + if (!parent()->GetGhostItems().isEmpty()) { FinishDrag(event); } @@ -186,11 +187,11 @@ void TimelineWidget::PointerTool::MouseRelease(TimelineViewMouseEvent *event) } } -void TimelineWidget::PointerTool::HoverMove(TimelineViewMouseEvent *event) +void PointerTool::HoverMove(TimelineViewMouseEvent *event) { if (trimming_allowed_) { // No dragging, but we still want to process cursors - TimelineViewBlockItem* block_at_cursor = GetItemAtScenePos(event->GetCoordinates()); + TimelineViewBlockItem* block_at_cursor = parent()->GetItemAtScenePos(event->GetCoordinates()); if (block_at_cursor) { switch (IsCursorInTrimHandle(block_at_cursor, event->GetSceneX())) { @@ -217,7 +218,7 @@ void SetGhostToSlideMode(TimelineViewGhostItem* g) g->setData(TimelineViewGhostItem::kGhostIsSliding, true); } -void TimelineWidget::PointerTool::InitiateDragInternal(TimelineViewBlockItem *clicked_item, +void PointerTool::InitiateDragInternal(TimelineViewBlockItem *clicked_item, Timeline::MovementMode trim_mode, bool dont_roll_trims, bool allow_nongap_rolling, @@ -443,7 +444,7 @@ void TimelineWidget::PointerTool::InitiateDragInternal(TimelineViewBlockItem *cl } } -void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos) +void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos) { // Calculate track movement int track_movement = track_movement_allowed_ @@ -469,7 +470,7 @@ void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_po // Validate ghosts that are being moved (clips from other track types do NOT get moved) { - QVector validate_track_ghosts = parent()->ghost_items_; + QVector validate_track_ghosts = parent()->GetGhostItems(); for (int i=0;iTrack().type() != drag_track_type_) { validate_track_ghosts.removeAt(i); @@ -480,8 +481,8 @@ void TimelineWidget::PointerTool::ProcessDrag(const TimelineCoordinate &mouse_po } // Perform movement - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { - switch (ghost->mode()) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { + switch (ghost->GetMode()) { case Timeline::kNone: break; case Timeline::kTrimIn: @@ -524,22 +525,22 @@ struct GhostBlockPair { Block* block; }; -void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event) +void PointerTool::FinishDrag(TimelineViewMouseEvent *event) { QList blocks_moving; QList blocks_sliding; QList blocks_trimming; // Sort ghosts depending on which ones are trimming, which are moving, and which are sliding - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { if (ghost->HasBeenAdjusted()) { Block* b = Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)); if (ghost->data(TimelineViewGhostItem::kGhostIsSliding).toBool()) { blocks_sliding.append({ghost, b}); - } else if (ghost->mode() == Timeline::kMove) { + } else if (ghost->GetMode() == Timeline::kMove) { blocks_moving.append({ghost, b}); - } else if (Timeline::IsATrimMode(ghost->mode())) { + } else if (Timeline::IsATrimMode(ghost->GetMode())) { blocks_trimming.append({ghost, b}); } } @@ -563,8 +564,8 @@ void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event) // Must be an ordinary trim/roll BlockTrimCommand* c = new BlockTrimCommand(parent()->GetTrackFromReference(ghost->GetAdjustedTrack()), p.block, - ghost->AdjustedLength(), - ghost->mode(), + ghost->GetAdjustedLength(), + ghost->GetMode(), command); c->SetTrimIsARollEdit(ghost->data(TimelineViewGhostItem::kTrimIsARollEdit).toBool()); @@ -631,13 +632,13 @@ void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event) foreach (const GhostBlockPair& p, blocks_sliding) { const TrackReference& track = p.ghost->Track(); - switch (p.ghost->mode()) { + switch (p.ghost->GetMode()) { case Timeline::kNone: break; case Timeline::kMove: { // These all should have moved uniformly, so as long as this is set, it should be fine - movement = p.ghost->InAdjustment(); + movement = p.ghost->GetInAdjustment(); QList& blocks_on_this_track = slide_info[track]; bool inserted = false; @@ -682,7 +683,7 @@ void TimelineWidget::PointerTool::FinishDrag(TimelineViewMouseEvent *event) Core::instance()->undo_stack()->pushIfHasChildren(command); } -Timeline::MovementMode TimelineWidget::PointerTool::IsCursorInTrimHandle(TimelineViewBlockItem *block, qreal cursor_x) +Timeline::MovementMode PointerTool::IsCursorInTrimHandle(TimelineViewBlockItem *block, qreal cursor_x) { double kTrimHandle = QFontMetricsWidth(parent()->fontMetrics(), "H"); @@ -700,7 +701,7 @@ Timeline::MovementMode TimelineWidget::PointerTool::IsCursorInTrimHandle(Timelin } } -void TimelineWidget::PointerTool::InitiateDrag(TimelineViewBlockItem* clicked_item, +void PointerTool::InitiateDrag(TimelineViewBlockItem* clicked_item, Timeline::MovementMode trim_mode) { InitiateDragInternal(clicked_item, trim_mode, false, false, false); @@ -708,10 +709,10 @@ void TimelineWidget::PointerTool::InitiateDrag(TimelineViewBlockItem* clicked_it //#define HIDE_GAP_GHOSTS -TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromBlock(Block* block, const TrackReference& track, Timeline::MovementMode mode, bool check_if_exists) +TimelineViewGhostItem* PointerTool::AddGhostFromBlock(Block* block, const TrackReference& track, Timeline::MovementMode mode, bool check_if_exists) { if (check_if_exists) { - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { if (Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)) == block) { return ghost; } @@ -734,7 +735,7 @@ TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromBlock(Block* blo return ghost; } -TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromNull(const rational &in, const rational &out, const TrackReference& track, Timeline::MovementMode mode) +TimelineViewGhostItem* PointerTool::AddGhostFromNull(const rational &in, const rational &out, const TrackReference& track, Timeline::MovementMode mode) { TimelineViewGhostItem* ghost = new TimelineViewGhostItem(); @@ -752,21 +753,21 @@ TimelineViewGhostItem* TimelineWidget::PointerTool::AddGhostFromNull(const ratio return ghost; } -void TimelineWidget::PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode) +void PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode) { ghost->SetMode(mode); // Prepare snap points (optimizes snapping for later) switch (mode) { case Timeline::kMove: - snap_points_.append(ghost->In()); - snap_points_.append(ghost->Out()); + snap_points_.append(ghost->GetIn()); + snap_points_.append(ghost->GetOut()); break; case Timeline::kTrimIn: - snap_points_.append(ghost->In()); + snap_points_.append(ghost->GetIn()); break; case Timeline::kTrimOut: - snap_points_.append(ghost->Out()); + snap_points_.append(ghost->GetOut()); break; default: break; @@ -775,7 +776,7 @@ void TimelineWidget::PointerTool::AddGhostInternal(TimelineViewGhostItem* ghost, parent()->AddGhost(ghost); } -bool TimelineWidget::PointerTool::IsClipTrimmable(TimelineViewBlockItem* clip, +bool PointerTool::IsClipTrimmable(TimelineViewBlockItem* clip, const QList& items, const Timeline::MovementMode& mode) { @@ -791,7 +792,7 @@ bool TimelineWidget::PointerTool::IsClipTrimmable(TimelineViewBlockItem* clip, return true; } -bool TimelineWidget::PointerTool::AddMovingTransitionsToClipGhost(Block* block, +bool PointerTool::AddMovingTransitionsToClipGhost(Block* block, const TrackReference& track, Timeline::MovementMode movement, const QList& selected_items) @@ -841,41 +842,41 @@ bool TimelineWidget::PointerTool::AddMovingTransitionsToClipGhost(Block* block, return ret; } -rational TimelineWidget::PointerTool::ValidateInTrimming(rational movement) +rational PointerTool::ValidateInTrimming(rational movement) { - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { - if (ghost->mode() != Timeline::kTrimIn) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { + if (ghost->GetMode() != Timeline::kTrimIn) { continue; } rational earliest_in = RATIONAL_MIN; - rational latest_in = ghost->Out(); + rational latest_in = ghost->GetOut(); if (!ghost->CanHaveZeroLength()) { latest_in -= parent()->timebase(); } // Clamp adjusted value between the earliest and latest values - rational adjusted = ghost->In() + movement; + rational adjusted = ghost->GetIn() + movement; rational clamped = clamp(adjusted, earliest_in, latest_in); if (clamped != adjusted) { - movement = clamped - ghost->In(); + movement = clamped - ghost->GetIn(); } } return movement; } -rational TimelineWidget::PointerTool::ValidateOutTrimming(rational movement) +rational PointerTool::ValidateOutTrimming(rational movement) { - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { - if (ghost->mode() != Timeline::kTrimOut) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { + if (ghost->GetMode() != Timeline::kTrimOut) { continue; } // Determine earliest and latest out points - rational earliest_out = ghost->In(); + rational earliest_out = ghost->GetIn(); if (!ghost->CanHaveZeroLength()) { earliest_out += parent()->timebase(); @@ -884,11 +885,11 @@ rational TimelineWidget::PointerTool::ValidateOutTrimming(rational movement) rational latest_out = RATIONAL_MAX; // Clamp adjusted value between the earliest and latest values - rational adjusted = ghost->Out() + movement; + rational adjusted = ghost->GetOut() + movement; rational clamped = clamp(adjusted, earliest_out, latest_out); if (clamped != adjusted) { - movement = clamped - ghost->Out(); + movement = clamped - ghost->GetOut(); } } diff --git a/app/widget/timelinewidget/tool/pointer.h b/app/widget/timelinewidget/tool/pointer.h new file mode 100644 index 000000000..31ec8b455 --- /dev/null +++ b/app/widget/timelinewidget/tool/pointer.h @@ -0,0 +1,127 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef POINTERTIMELINETOOL_H +#define POINTERTIMELINETOOL_H + +#include "tool.h" + +OLIVE_NAMESPACE_ENTER + +class PointerTool : public TimelineTool +{ +public: + PointerTool(TimelineWidget* parent); + + virtual void MousePress(TimelineViewMouseEvent *event) override; + virtual void MouseMove(TimelineViewMouseEvent *event) override; + virtual void MouseRelease(TimelineViewMouseEvent *event) override; + + virtual void HoverMove(TimelineViewMouseEvent *event) override; + +protected: + virtual void FinishDrag(TimelineViewMouseEvent *event); + + virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, + Timeline::MovementMode trim_mode); + + TimelineViewGhostItem* AddGhostFromBlock(Block *block, const TrackReference& track, Timeline::MovementMode mode, bool check_if_exists = false); + + TimelineViewGhostItem* AddGhostFromNull(const rational& in, const rational& out, const TrackReference& track, Timeline::MovementMode mode); + + /** + * @brief Validates Ghosts that are getting their in points trimmed + * + * Assumes ghost->data() is a Block. Ensures no Ghost's in point becomes a negative timecode. Also ensures no + * Ghost's length becomes 0 or negative. + */ + rational ValidateInTrimming(rational movement); + + /** + * @brief Validates Ghosts that are getting their out points trimmed + * + * Assumes ghost->data() is a Block. Ensures no Ghost's in point becomes a negative timecode. Also ensures no + * Ghost's length becomes 0 or negative. + */ + rational ValidateOutTrimming(rational movement); + + virtual void ProcessDrag(const TimelineCoordinate &mouse_pos); + + void InitiateDragInternal(TimelineViewBlockItem* clicked_item, + Timeline::MovementMode trim_mode, + bool dont_roll_trims, + bool allow_nongap_rolling, bool slide_instead_of_moving); + + const Timeline::MovementMode& drag_movement_mode() const + { + return drag_movement_mode_; + } + + void SetMovementAllowed(bool e) + { + movement_allowed_ = e; + } + + void SetTrimmingAllowed(bool e) + { + trimming_allowed_ = e; + } + + void SetTrackMovementAllowed(bool e) + { + track_movement_allowed_ = e; + } + + void SetGapTrimmingAllowed(bool e) + { + gap_trimming_allowed_ = e; + } + +private: + Timeline::MovementMode IsCursorInTrimHandle(TimelineViewBlockItem* block, qreal cursor_x); + + void AddGhostInternal(TimelineViewGhostItem* ghost, Timeline::MovementMode mode); + + bool IsClipTrimmable(TimelineViewBlockItem* clip, + const QList& items, + const Timeline::MovementMode& mode); + + void ProcessGhostsForSliding(); + + void ProcessGhostsForRolling(); + + bool AddMovingTransitionsToClipGhost(Block *block, const TrackReference &track, Timeline::MovementMode movement, const QList &selected_items); + + bool movement_allowed_; + bool trimming_allowed_; + bool track_movement_allowed_; + bool gap_trimming_allowed_; + bool rubberband_selecting_; + + Timeline::TrackType drag_track_type_; + Timeline::MovementMode drag_movement_mode_; + + TimelineViewBlockItem* clicked_item_; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // POINTERTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/razor.cpp b/app/widget/timelinewidget/tool/razor.cpp index 49177ce8a..fb6244ee8 100644 --- a/app/widget/timelinewidget/tool/razor.cpp +++ b/app/widget/timelinewidget/tool/razor.cpp @@ -18,23 +18,24 @@ ***/ +#include "razor.h" #include "widget/timelinewidget/timelinewidget.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::RazorTool::RazorTool(TimelineWidget* parent) : +RazorTool::RazorTool(TimelineWidget* parent) : BeamTool(parent) { } -void TimelineWidget::RazorTool::MousePress(TimelineViewMouseEvent *event) +void RazorTool::MousePress(TimelineViewMouseEvent *event) { split_tracks_.clear(); MouseMove(event); } -void TimelineWidget::RazorTool::MouseMove(TimelineViewMouseEvent *event) +void RazorTool::MouseMove(TimelineViewMouseEvent *event) { if (!dragging_) { drag_start_ = ValidatedCoordinate(event->GetCoordinates(true)); @@ -49,7 +50,7 @@ void TimelineWidget::RazorTool::MouseMove(TimelineViewMouseEvent *event) } } -void TimelineWidget::RazorTool::MouseRelease(TimelineViewMouseEvent *event) +void RazorTool::MouseRelease(TimelineViewMouseEvent *event) { Q_UNUSED(event) diff --git a/app/widget/timelinewidget/tool/razor.h b/app/widget/timelinewidget/tool/razor.h new file mode 100644 index 000000000..d2da08ac3 --- /dev/null +++ b/app/widget/timelinewidget/tool/razor.h @@ -0,0 +1,43 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef RAZORTIMELINETOOL_H +#define RAZORTIMELINETOOL_H + +#include "beam.h" + +OLIVE_NAMESPACE_ENTER + +class RazorTool : public BeamTool +{ +public: + RazorTool(TimelineWidget* parent); + + virtual void MousePress(TimelineViewMouseEvent *event) override; + virtual void MouseMove(TimelineViewMouseEvent *event) override; + virtual void MouseRelease(TimelineViewMouseEvent *event) override; + +private: + QVector split_tracks_; +}; + +OLIVE_NAMESPACE_EXIT + +#endif // RAZORTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/ripple.cpp b/app/widget/timelinewidget/tool/ripple.cpp index 919c0d908..3b8273327 100644 --- a/app/widget/timelinewidget/tool/ripple.cpp +++ b/app/widget/timelinewidget/tool/ripple.cpp @@ -21,36 +21,37 @@ #include "widget/timelinewidget/timelinewidget.h" #include "node/block/gap/gap.h" +#include "ripple.h" #include "widget/nodeview/nodeviewundo.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::RippleTool::RippleTool(TimelineWidget* parent) : +RippleTool::RippleTool(TimelineWidget* parent) : PointerTool(parent) { SetMovementAllowed(false); SetGapTrimmingAllowed(true); } -void TimelineWidget::RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_item, +void RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_item, Timeline::MovementMode trim_mode) { InitiateDragInternal(clicked_item, trim_mode, true, true, false); - if (parent()->ghost_items_.isEmpty()) { + if (!parent()->HasGhosts()) { return; } // Find the earliest ripple rational earliest_ripple = RATIONAL_MAX; - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { rational ghost_ripple_point; if (trim_mode == Timeline::kTrimIn) { - ghost_ripple_point = ghost->In(); + ghost_ripple_point = ghost->GetIn(); } else { - ghost_ripple_point = ghost->Out(); + ghost_ripple_point = ghost->GetOut(); } earliest_ripple = qMin(earliest_ripple, ghost_ripple_point); @@ -65,7 +66,7 @@ void TimelineWidget::RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_ite // Determine if we've already created a ghost on this track bool ghost_on_this_track_exists = false; - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { if (parent()->GetTrackFromReference(ghost->Track()) == track) { ghost_on_this_track_exists = true; break; @@ -103,20 +104,20 @@ void TimelineWidget::RippleTool::InitiateDrag(TimelineViewBlockItem *clicked_ite } } -void TimelineWidget::RippleTool::FinishDrag(TimelineViewMouseEvent *event) +void RippleTool::FinishDrag(TimelineViewMouseEvent *event) { Q_UNUSED(event) QVector< QList > info_list(Timeline::kTrackTypeCount); - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { TrackOutput* track = parent()->GetTrackFromReference(ghost->Track()); TrackListRippleToolCommand::RippleInfo i = {Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)), Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kReferenceBlock)), track, - ghost->AdjustedLength(), - ghost->Length()}; + ghost->GetAdjustedLength(), + ghost->GetLength()}; info_list[track->track_type()].append(i); } diff --git a/app/widget/timelinewidget/tool/ripple.h b/app/widget/timelinewidget/tool/ripple.h new file mode 100644 index 000000000..bb946eaa3 --- /dev/null +++ b/app/widget/timelinewidget/tool/ripple.h @@ -0,0 +1,41 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef RIPPLETIMELINETOOL_H +#define RIPPLETIMELINETOOL_H + +#include "pointer.h" + +OLIVE_NAMESPACE_ENTER + +class RippleTool : public PointerTool +{ +public: + RippleTool(TimelineWidget* parent); +protected: + virtual void FinishDrag(TimelineViewMouseEvent *event) override; + + virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, + Timeline::MovementMode trim_mode) override; +}; + +OLIVE_NAMESPACE_EXIT + +#endif // RIPPLETIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/rolling.cpp b/app/widget/timelinewidget/tool/rolling.cpp index 2aa55e43e..4f340991a 100644 --- a/app/widget/timelinewidget/tool/rolling.cpp +++ b/app/widget/timelinewidget/tool/rolling.cpp @@ -21,18 +21,19 @@ #include "widget/timelinewidget/timelinewidget.h" #include "node/block/gap/gap.h" +#include "rolling.h" #include "widget/nodeview/nodeviewundo.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::RollingTool::RollingTool(TimelineWidget* parent) : +RollingTool::RollingTool(TimelineWidget* parent) : PointerTool(parent) { SetMovementAllowed(false); SetGapTrimmingAllowed(true); } -void TimelineWidget::RollingTool::InitiateDrag(TimelineViewBlockItem *clicked_item, +void RollingTool::InitiateDrag(TimelineViewBlockItem *clicked_item, Timeline::MovementMode trim_mode) { InitiateDragInternal(clicked_item, trim_mode, false, true, false); diff --git a/app/widget/timelinewidget/tool/rolling.h b/app/widget/timelinewidget/tool/rolling.h new file mode 100644 index 000000000..f804b9118 --- /dev/null +++ b/app/widget/timelinewidget/tool/rolling.h @@ -0,0 +1,40 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef ROLLINGTIMELINETOOL_H +#define ROLLINGTIMELINETOOL_H + +#include "pointer.h" + +OLIVE_NAMESPACE_ENTER + +class RollingTool : public PointerTool +{ +public: + RollingTool(TimelineWidget* parent); + +protected: + virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, + Timeline::MovementMode trim_mode) override; +}; + +OLIVE_NAMESPACE_EXIT + +#endif // ROLLINGTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/slide.cpp b/app/widget/timelinewidget/tool/slide.cpp index c64d9ec43..0dc7d1482 100644 --- a/app/widget/timelinewidget/tool/slide.cpp +++ b/app/widget/timelinewidget/tool/slide.cpp @@ -21,11 +21,12 @@ #include "widget/timelinewidget/timelinewidget.h" #include "node/block/gap/gap.h" +#include "slide.h" #include "widget/nodeview/nodeviewundo.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::SlideTool::SlideTool(TimelineWidget* parent) : +SlideTool::SlideTool(TimelineWidget* parent) : PointerTool(parent) { SetTrimmingAllowed(false); @@ -33,7 +34,7 @@ TimelineWidget::SlideTool::SlideTool(TimelineWidget* parent) : SetGapTrimmingAllowed(true); } -void TimelineWidget::SlideTool::InitiateDrag(TimelineViewBlockItem *clicked_item, +void SlideTool::InitiateDrag(TimelineViewBlockItem *clicked_item, Timeline::MovementMode trim_mode) { InitiateDragInternal(clicked_item, trim_mode, false, true, true); diff --git a/app/widget/timelinewidget/tool/slide.h b/app/widget/timelinewidget/tool/slide.h new file mode 100644 index 000000000..326f78d8b --- /dev/null +++ b/app/widget/timelinewidget/tool/slide.h @@ -0,0 +1,41 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef SLIDETIMELINETOOL_H +#define SLIDETIMELINETOOL_H + +#include "pointer.h" + +OLIVE_NAMESPACE_ENTER + +class SlideTool : public PointerTool +{ +public: + SlideTool(TimelineWidget* parent); + +protected: + virtual void InitiateDrag(TimelineViewBlockItem* clicked_item, + Timeline::MovementMode trim_mode) override; + +}; + +OLIVE_NAMESPACE_EXIT + +#endif // SLIDETIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/slip.cpp b/app/widget/timelinewidget/tool/slip.cpp index 0208743be..caea2014d 100644 --- a/app/widget/timelinewidget/tool/slip.cpp +++ b/app/widget/timelinewidget/tool/slip.cpp @@ -24,30 +24,31 @@ #include "common/timecodefunctions.h" #include "config/config.h" +#include "slip.h" OLIVE_NAMESPACE_ENTER -TimelineWidget::SlipTool::SlipTool(TimelineWidget *parent) : +SlipTool::SlipTool(TimelineWidget *parent) : PointerTool(parent) { SetTrimmingAllowed(false); SetTrackMovementAllowed(false); } -void TimelineWidget::SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos) +void SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos) { // Determine frame movement rational time_movement = drag_start_.GetFrame() - mouse_pos.GetFrame(); // Validate slip (enforce all ghosts moving in legal ways) - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { - if (ghost->MediaIn() + time_movement < 0) { - time_movement = -ghost->MediaIn(); + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { + if (ghost->GetMediaIn() + time_movement < 0) { + time_movement = -ghost->GetMediaIn(); } } // Perform slip - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { ghost->SetMediaInAdjustment(time_movement); } @@ -62,14 +63,14 @@ void TimelineWidget::SlipTool::ProcessDrag(const TimelineCoordinate &mouse_pos) parent()); } -void TimelineWidget::SlipTool::FinishDrag(TimelineViewMouseEvent *event) +void SlipTool::FinishDrag(TimelineViewMouseEvent *event) { Q_UNUSED(event) QUndoCommand* command = new QUndoCommand(); // Find earliest point to ripple around - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { Block* b = Node::ValueToPtr(ghost->data(TimelineViewGhostItem::kAttachedBlock)); new BlockSetMediaInCommand(b, ghost->GetAdjustedMediaIn(), command); diff --git a/app/widget/timelinewidget/tool/slip.h b/app/widget/timelinewidget/tool/slip.h new file mode 100644 index 000000000..bf358e5fc --- /dev/null +++ b/app/widget/timelinewidget/tool/slip.h @@ -0,0 +1,40 @@ +/*** + + Olive - Non-Linear Video Editor + Copyright (C) 2019 Olive Team + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +***/ + +#ifndef SLIPTIMELINETOOL_H +#define SLIPTIMELINETOOL_H + +#include "pointer.h" + +OLIVE_NAMESPACE_ENTER + +class SlipTool : public PointerTool +{ +public: + SlipTool(TimelineWidget* parent); + +protected: + virtual void ProcessDrag(const TimelineCoordinate &mouse_pos) override; + virtual void FinishDrag(TimelineViewMouseEvent *event) override; +}; + +OLIVE_NAMESPACE_EXIT + +#endif // SLIPTIMELINETOOL_H diff --git a/app/widget/timelinewidget/tool/tool.cpp b/app/widget/timelinewidget/tool/tool.cpp index 04ce25b32..060c82da1 100644 --- a/app/widget/timelinewidget/tool/tool.cpp +++ b/app/widget/timelinewidget/tool/tool.cpp @@ -25,22 +25,22 @@ OLIVE_NAMESPACE_ENTER -TimelineWidget::Tool::Tool(TimelineWidget *parent) : +TimelineTool::TimelineTool(TimelineWidget *parent) : dragging_(false), parent_(parent) { } -TimelineWidget::Tool::~Tool() +TimelineTool::~TimelineTool() { } -TimelineWidget *TimelineWidget::Tool::parent() +TimelineWidget *TimelineTool::parent() { return parent_; } -Timeline::MovementMode TimelineWidget::Tool::FlipTrimMode(const Timeline::MovementMode &trim_mode) +Timeline::MovementMode TimelineTool::FlipTrimMode(const Timeline::MovementMode &trim_mode) { if (trim_mode == Timeline::kTrimIn) { return Timeline::kTrimOut; @@ -53,50 +53,30 @@ Timeline::MovementMode TimelineWidget::Tool::FlipTrimMode(const Timeline::Moveme return trim_mode; } -TimelineViewBlockItem *TimelineWidget::Tool::GetItemAtScenePos(const TimelineCoordinate& coord) +rational TimelineTool::ValidateTimeMovement(rational movement) { - QMapIterator iterator(parent()->block_items_); - - while (iterator.hasNext()) { - iterator.next(); - - Block* b = iterator.key(); - TimelineViewBlockItem* item = iterator.value(); - - if (b->in() <= coord.GetFrame() - && b->out() > coord.GetFrame() - && item->Track() == coord.GetTrack()) { - return item; - } - } - - return nullptr; -} - -rational TimelineWidget::Tool::ValidateTimeMovement(rational movement) -{ - foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) { - if (ghost->mode() != Timeline::kMove) { + foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) { + if (ghost->GetMode() != Timeline::kMove) { continue; } // Prevents any ghosts from going below 0:00:00 time - if (ghost->In() + movement < 0) { - movement = -ghost->In(); + if (ghost->GetIn() + movement < 0) { + movement = -ghost->GetIn(); } } return movement; } -int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector& ghosts) +int TimelineTool::ValidateTrackMovement(int movement, const QVector& ghosts) { foreach (TimelineViewGhostItem* ghost, ghosts) { - if (ghost->mode() != Timeline::kMove) { + if (ghost->GetMode() != Timeline::kMove) { continue; } - if (!ghost->CanMoveTracks()) { + if (!ghost->GetCanMoveTracks()) { return 0; @@ -111,12 +91,12 @@ int TimelineWidget::Tool::ValidateTrackMovement(int movement, const QVector