timeline: moved tools to separate files

Code cleanup, TimelineWidget header was getting a little too bloated.
This commit is contained in:
itsmattkc
2020-10-02 22:02:18 +10:00
parent 0508acc613
commit dd3d11c7e0
33 changed files with 1103 additions and 602 deletions
+1 -1
View File
@@ -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);
@@ -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&){}
+65 -23
View File
@@ -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::DraggedFootage> TimelineWidget::FootageToDraggedFootage(QList<Footage *> footage)
{
QList<DraggedFootage> 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<Timeline::EditToInfo> 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());
+75 -375
View File
@@ -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<Block *>& 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<Block*, TimelineViewBlockItem*>& GetBlockItems() const
{
return block_items_;
}
using Selections = QHash<TrackReference, TimeRangeList>;
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<TimelineViewGhostItem*>& 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<Block*>& 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<DraggedFootage> FootageToDraggedFootage(QList<Footage*> 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<TimelineViewGhostItem *> &ghosts);
void GetGhostData(rational *earliest_point, rational *latest_point);
void InsertGapsAtGhostDestination(QUndoCommand* command);
QList<rational> 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<TimelineViewBlockItem*>& items,
const Timeline::MovementMode& mode);
void ProcessGhostsForSliding();
void ProcessGhostsForRolling();
bool AddMovingTransitionsToClipGhost(Block *block, const TrackReference &track, Timeline::MovementMode movement, const QList<TimelineViewBlockItem *> &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*> &footage, const rational& start, bool insert);
void PlaceAt(const QList<DraggedFootage> &footage, const rational& start, bool insert);
private:
void FootageToGhosts(rational ghost_start, const QList<DraggedFootage>& footage, const rational &dest_tb, const int &track_start);
void PrepGhosts(const rational &frame, const int &track_index);
void DropGhosts(bool insert);
QList<DraggedFootage> 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<TrackReference, TimeRangeList> 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<TrackReference> 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<Timeline::EditToInfo> 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<QGraphicsItem*> rubberband_already_selected_;
QList<QGraphicsItem*> rubberband_now_selected_;
QHash<TrackReference, TimeRangeList> 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<Tool*> tools_;
QVector<TimelineTool*> tools_;
ImportTool* import_tool_;
Tool* active_tool_;
void ClearGhosts();
bool HasGhosts();
TimelineTool* active_tool_;
QVector<TimelineViewGhostItem*> ghost_items_;
QMap<Block*, TimelineViewBlockItem*> block_items_;
TrackOutput* GetTrackFromReference(const TrackReference& ref);
QList<TimelineAndTrackView*> 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);
@@ -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
)
+10 -9
View File
@@ -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<NodeGraph*>(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
+47
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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
+5 -4
View File
@@ -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;
+42
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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
+9 -8
View File
@@ -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);
+48
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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<TrackReference, TimeRangeList> start_selections_;
TimelineCoordinate start_coord_;
};
OLIVE_NAMESPACE_EXIT
#endif // EDITTIMELINETOOL_H
+43 -22
View File
@@ -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 *> &footage, const rational &start, bool insert)
void ImportTool::PlaceAt(const QList<Footage *> &footage, const rational &start, bool insert)
{
PlaceAt(FootageToDraggedFootage(footage), start, insert);
}
void TimelineWidget::ImportTool::PlaceAt(const QList<DraggedFootage> &footage, const rational &start, bool insert)
void ImportTool::PlaceAt(const QList<DraggedFootage> &footage, const rational &start, bool insert)
{
dragged_footage_ = footage;
@@ -208,7 +208,7 @@ void TimelineWidget::ImportTool::PlaceAt(const QList<DraggedFootage> &footage, c
DropGhosts(insert);
}
void TimelineWidget::ImportTool::FootageToGhosts(rational ghost_start, const QList<DraggedFootage> &footage_list, const rational& dest_tb, const int& track_start)
void ImportTool::FootageToGhosts(rational ghost_start, const QList<DraggedFootage> &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*> block_items(parent()->ghost_items_.size());
QVector<Block*> block_items(parent()->GetGhostItems().size());
// Check if we're inserting
if (insert) {
InsertGapsAtGhostDestination(command);
}
for (int i=0;i<parent()->ghost_items_.size();i++) {
TimelineViewGhostItem* ghost = parent()->ghost_items_.at(i);
for (int i=0;i<parent()->GetGhostItems().size();i++) {
TimelineViewGhostItem* ghost = parent()->GetGhostItems().at(i);
StreamPtr footage_stream = ghost->data(TimelineViewGhostItem::kAttachedFootage).value<StreamPtr>();
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;j<i;j++) {
StreamPtr footage_compare = parent()->ghost_items_.at(j)->data(TimelineViewGhostItem::kAttachedFootage).value<StreamPtr>();
StreamPtr footage_compare = parent()->GetGhostItems().at(j)->data(TimelineViewGhostItem::kAttachedFootage).value<StreamPtr>();
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::DraggedFootage> ImportTool::FootageToDraggedFootage(QList<Footage *> footage)
{
QList<DraggedFootage> 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
+91
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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*> &footage, const rational& start, bool insert);
void PlaceAt(const QList<DraggedFootage> &footage, const rational& start, bool insert);
enum DropWithoutSequenceBehavior {
kDWSAsk,
kDWSAuto,
kDWSManual,
kDWSDisable
};
private:
static DraggedFootage FootageToDraggedFootage(Footage* f);
static QList<DraggedFootage> FootageToDraggedFootage(QList<Footage*> footage);
QString tr(const char* s);
void FootageToGhosts(rational ghost_start, const QList<DraggedFootage>& footage, const rational &dest_tb, const int &track_start);
void PrepGhosts(const rational &frame, const int &track_index);
void DropGhosts(bool insert);
QList<DraggedFootage> dragged_footage_;
int import_pre_buffer_;
};
OLIVE_NAMESPACE_EXIT
#endif // IMPORTTIMELINETOOL_H
+48 -47
View File
@@ -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<TimelineViewGhostItem*> validate_track_ghosts = parent()->ghost_items_;
QVector<TimelineViewGhostItem*> validate_track_ghosts = parent()->GetGhostItems();
for (int i=0;i<validate_track_ghosts.size();i++) {
if (validate_track_ghosts.at(i)->Track().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<GhostBlockPair> blocks_moving;
QList<GhostBlockPair> blocks_sliding;
QList<GhostBlockPair> 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<Block>(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<Block*>& 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<Block>(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<TimelineViewBlockItem*>& 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<TimelineViewBlockItem*>& 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();
}
}
+127
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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<TimelineViewBlockItem*>& items,
const Timeline::MovementMode& mode);
void ProcessGhostsForSliding();
void ProcessGhostsForRolling();
bool AddMovingTransitionsToClipGhost(Block *block, const TrackReference &track, Timeline::MovementMode movement, const QList<TimelineViewBlockItem *> &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
+5 -4
View File
@@ -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)
+43
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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<TrackReference> split_tracks_;
};
OLIVE_NAMESPACE_EXIT
#endif // RAZORTIMELINETOOL_H
+12 -11
View File
@@ -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<TrackListRippleToolCommand::RippleInfo> > 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<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock)),
Node::ValueToPtr<Block>(ghost->data(TimelineViewGhostItem::kReferenceBlock)),
track,
ghost->AdjustedLength(),
ghost->Length()};
ghost->GetAdjustedLength(),
ghost->GetLength()};
info_list[track->track_type()].append(i);
}
+41
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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
+3 -2
View File
@@ -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);
+40
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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
+3 -2
View File
@@ -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);
+41
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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
+9 -8
View File
@@ -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<Block>(ghost->data(TimelineViewGhostItem::kAttachedBlock));
new BlockSetMediaInCommand(b, ghost->GetAdjustedMediaIn(), command);
+40
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#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
+15 -35
View File
@@ -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<Block*, TimelineViewBlockItem*> 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<TimelineViewGhostItem*>& ghosts)
int TimelineTool::ValidateTrackMovement(int movement, const QVector<TimelineViewGhostItem*>& 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<Time
return movement;
}
void TimelineWidget::Tool::GetGhostData(rational *earliest_point, rational *latest_point)
void TimelineTool::GetGhostData(rational *earliest_point, rational *latest_point)
{
rational ep = RATIONAL_MAX;
rational lp = RATIONAL_MIN;
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) {
ep = qMin(ep, ghost->GetAdjustedIn());
lp = qMax(lp, ghost->GetAdjustedOut());
}
@@ -130,7 +110,7 @@ void TimelineWidget::Tool::GetGhostData(rational *earliest_point, rational *late
}
}
void TimelineWidget::Tool::InsertGapsAtGhostDestination(QUndoCommand *command)
void TimelineTool::InsertGapsAtGhostDestination(QUndoCommand *command)
{
rational earliest_point, latest_point;
+89
View File
@@ -0,0 +1,89 @@
/***
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 <http://www.gnu.org/licenses/>.
***/
#ifndef TIMELINETOOL_H
#define TIMELINETOOL_H
#include <QDragLeaveEvent>
#include "common/rational.h"
#include "widget/timelinewidget/view/timelineviewghostitem.h"
#include "widget/timelinewidget/view/timelineviewmouseevent.h"
OLIVE_NAMESPACE_ENTER
class TimelineWidget;
class TimelineTool
{
public:
TimelineTool(TimelineWidget* parent);
virtual ~TimelineTool();
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 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<TimelineViewGhostItem *> &ghosts);
void GetGhostData(rational *earliest_point, rational *latest_point);
void InsertGapsAtGhostDestination(QUndoCommand* command);
QList<rational> snap_points_;
bool dragging_;
TimelineCoordinate drag_start_;
private:
TimelineWidget* parent_;
};
OLIVE_NAMESPACE_EXIT
#endif // TIMELINETOOL_H
+13 -12
View File
@@ -23,16 +23,17 @@
#include "node/block/transition/crossdissolve/crossdissolvetransition.h"
#include "node/block/transition/transition.h"
#include "node/factory.h"
#include "transition.h"
#include "widget/nodeview/nodeviewundo.h"
OLIVE_NAMESPACE_ENTER
TimelineWidget::TransitionTool::TransitionTool(TimelineWidget *parent) :
TransitionTool::TransitionTool(TimelineWidget *parent) :
AddTool(parent)
{
}
void TimelineWidget::TransitionTool::MousePress(TimelineViewMouseEvent *event)
void TransitionTool::MousePress(TimelineViewMouseEvent *event)
{
const TrackReference& track = event->GetTrack();
TrackOutput* t = parent()->GetTrackFromReference(track);
@@ -95,7 +96,7 @@ void TimelineWidget::TransitionTool::MousePress(TimelineViewMouseEvent *event)
drag_start_point_ = cursor_frame;
}
void TimelineWidget::TransitionTool::MouseMove(TimelineViewMouseEvent *event)
void TransitionTool::MouseMove(TimelineViewMouseEvent *event)
{
if (!ghost_) {
return;
@@ -104,12 +105,12 @@ void TimelineWidget::TransitionTool::MouseMove(TimelineViewMouseEvent *event)
MouseMoveInternal(event->GetFrame(), dual_transition_);
}
void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
void TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
{
const TrackReference& track = ghost_->Track();
if (ghost_) {
if (!ghost_->AdjustedLength().isNull()) {
if (!ghost_->GetAdjustedLength().isNull()) {
TransitionBlock* transition;
if (Core::instance()->GetSelectedTransition().isEmpty()) {
@@ -133,8 +134,8 @@ void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
command);
if (dual_transition_) {
transition->set_length_and_media_out(ghost_->AdjustedLength());
transition->set_media_in(-ghost_->AdjustedLength()/2);
transition->set_length_and_media_out(ghost_->GetAdjustedLength());
transition->set_media_in(-ghost_->GetAdjustedLength()/2);
// Block mouse is hovering over
Block* active_block = Node::ValueToPtr<Block>(ghost_->data(TimelineViewGhostItem::kAttachedBlock));
@@ -143,8 +144,8 @@ void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
Block* friend_block = Node::ValueToPtr<Block>(ghost_->data(TimelineViewGhostItem::kReferenceBlock));
// Use ghost mode to determine which block is which
Block* out_block = (ghost_->mode() == Timeline::kTrimIn) ? friend_block : active_block;
Block* in_block = (ghost_->mode() == Timeline::kTrimIn) ? active_block : friend_block;
Block* out_block = (ghost_->GetMode() == Timeline::kTrimIn) ? friend_block : active_block;
Block* in_block = (ghost_->GetMode() == Timeline::kTrimIn) ? active_block : friend_block;
// Connect block to transition
new NodeEdgeAddCommand(out_block->output(),
@@ -158,11 +159,11 @@ void TimelineWidget::TransitionTool::MouseRelease(TimelineViewMouseEvent *event)
Block* block_to_transition = Node::ValueToPtr<Block>(ghost_->data(TimelineViewGhostItem::kAttachedBlock));
NodeInput* transition_input_to_connect;
if (ghost_->mode() == Timeline::kTrimIn) {
transition->set_length_and_media_out(ghost_->AdjustedLength());
if (ghost_->GetMode() == Timeline::kTrimIn) {
transition->set_length_and_media_out(ghost_->GetAdjustedLength());
transition_input_to_connect = transition->in_block_input();
} else {
transition->set_length_and_media_out(ghost_->AdjustedLength());
transition->set_length_and_media_out(ghost_->GetAdjustedLength());
transition_input_to_connect = transition->out_block_input();
}
@@ -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 <http://www.gnu.org/licenses/>.
***/
#ifndef TRANSITIONTIMELINETOOL_H
#define TRANSITIONTIMELINETOOL_H
#include "add.h"
OLIVE_NAMESPACE_ENTER
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_;
};
OLIVE_NAMESPACE_EXIT
#endif // TRANSITIONTIMELINETOOL_H
+14 -11
View File
@@ -19,20 +19,21 @@
***/
#include "widget/timelinewidget/timelinewidget.h"
#include "zoom.h"
OLIVE_NAMESPACE_ENTER
TimelineWidget::ZoomTool::ZoomTool(TimelineWidget *parent) :
Tool(parent)
ZoomTool::ZoomTool(TimelineWidget *parent) :
TimelineTool(parent)
{
}
void TimelineWidget::ZoomTool::MousePress(TimelineViewMouseEvent *event)
void ZoomTool::MousePress(TimelineViewMouseEvent *event)
{
Q_UNUSED(event)
}
void TimelineWidget::ZoomTool::MouseMove(TimelineViewMouseEvent *event)
void ZoomTool::MouseMove(TimelineViewMouseEvent *event)
{
Q_UNUSED(event)
@@ -45,15 +46,17 @@ void TimelineWidget::ZoomTool::MouseMove(TimelineViewMouseEvent *event)
}
}
void TimelineWidget::ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
void ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
{
int scroll_value;
if (dragging_) {
// Zoom into the rubberband selection
QRect screen_coords = parent()->rubberband_.geometry();
QRect screen_coords = parent()->GetRubberBandGeometry();
parent()->EndRubberBandSelect();
TimelineView* reference_view = parent()->views_.first()->view();
TimelineView* reference_view = parent()->GetFirstTimelineView();
QPointF scene_topleft = reference_view->mapToScene(reference_view->mapFrom(parent(), screen_coords.topLeft()));
QPointF scene_bottomright = reference_view->mapToScene(reference_view->mapFrom(parent(), screen_coords.bottomRight()));
@@ -64,10 +67,11 @@ void TimelineWidget::ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
double scene_width = (scene_right - scene_left) / parent()->GetScale();
double new_scale = qMin(TimelineViewBase::kMaximumScale, static_cast<double>(reference_view->viewport()->width()) / scene_width);
parent()->deferred_scroll_value_ = qMax(0, qRound(scene_left / parent()->GetScale() * new_scale));
parent()->SetScale(new_scale);
scroll_value = qMax(0, qRound(scene_left / parent()->GetScale() * new_scale));
dragging_ = false;
} else {
// Simple zoom in/out at the cursor position
@@ -86,11 +90,10 @@ void TimelineWidget::ZoomTool::MouseRelease(TimelineViewMouseEvent *event)
// Adjust scroll location for new scale
double frame_x = event->GetFrame().toDouble() * scale;
parent()->deferred_scroll_value_ = qMax(0, qRound(frame_x - parent()->views_.first()->view()->viewport()->width()/2));
scroll_value = qMax(0, qRound(frame_x - parent()->GetFirstTimelineView()->viewport()->width()/2));
}
// (using a hacky singleShot so the scroll occurs after the scene and its scrollbars have updated)
QTimer::singleShot(0, parent(), &TimelineWidget::DeferredScrollAction);
parent()->QueueScroll(scroll_value);
}
OLIVE_NAMESPACE_EXIT
+41
View File
@@ -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 <http://www.gnu.org/licenses/>.
***/
#ifndef ZOOMTIMELINETOOL_H
#define ZOOMTIMELINETOOL_H
#include "tool.h"
OLIVE_NAMESPACE_ENTER
class ZoomTool : public TimelineTool
{
public:
ZoomTool(TimelineWidget* parent);
virtual void MousePress(TimelineViewMouseEvent *event) override;
virtual void MouseMove(TimelineViewMouseEvent *event) override;
virtual void MouseRelease(TimelineViewMouseEvent *event) override;
};
OLIVE_NAMESPACE_EXIT
#endif // ZOOMTIMELINETOOL_H
@@ -66,7 +66,7 @@ bool TimelineViewGhostItem::CanHaveZeroLength() const
return can_have_zero_length_;
}
bool TimelineViewGhostItem::CanMoveTracks() const
bool TimelineViewGhostItem::GetCanMoveTracks() const
{
return can_move_tracks_;
}
@@ -87,27 +87,27 @@ void TimelineViewGhostItem::SetInvisible(bool invisible)
}
}
const rational &TimelineViewGhostItem::In() const
const rational &TimelineViewGhostItem::GetIn() const
{
return in_;
}
const rational &TimelineViewGhostItem::Out() const
const rational &TimelineViewGhostItem::GetOut() const
{
return out_;
}
const rational &TimelineViewGhostItem::MediaIn() const
const rational &TimelineViewGhostItem::GetMediaIn() const
{
return media_in_;
}
rational TimelineViewGhostItem::Length() const
rational TimelineViewGhostItem::GetLength() const
{
return out_ - in_;
}
rational TimelineViewGhostItem::AdjustedLength() const
rational TimelineViewGhostItem::GetAdjustedLength() const
{
return GetAdjustedOut() - GetAdjustedIn();
}
@@ -155,22 +155,22 @@ void TimelineViewGhostItem::SetMediaInAdjustment(const rational &media_in_adj)
media_in_adj_ = media_in_adj;
}
const rational &TimelineViewGhostItem::InAdjustment() const
const rational &TimelineViewGhostItem::GetInAdjustment() const
{
return in_adj_;
}
const rational &TimelineViewGhostItem::OutAdjustment() const
const rational &TimelineViewGhostItem::GetOutAdjustment() const
{
return out_adj_;
}
const rational &TimelineViewGhostItem::MediaInAdjustment() const
const rational &TimelineViewGhostItem::GetMediaInAdjustment() const
{
return media_in_adj_;
}
const int &TimelineViewGhostItem::TrackAdjustment() const
const int &TimelineViewGhostItem::GetTrackAdjustment() const
{
return track_adj_;
}
@@ -195,7 +195,7 @@ TrackReference TimelineViewGhostItem::GetAdjustedTrack() const
return TrackReference(track_.type(), track_.index() + track_adj_);
}
const Timeline::MovementMode &TimelineViewGhostItem::mode() const
const Timeline::MovementMode &TimelineViewGhostItem::GetMode() const
{
return mode_;
}
@@ -207,10 +207,10 @@ void TimelineViewGhostItem::SetMode(const Timeline::MovementMode &mode)
bool TimelineViewGhostItem::HasBeenAdjusted() const
{
return InAdjustment() != 0
|| OutAdjustment() != 0
|| MediaInAdjustment() != 0
|| TrackAdjustment() != 0;
return GetInAdjustment() != 0
|| GetOutAdjustment() != 0
|| GetMediaInAdjustment() != 0
|| GetTrackAdjustment() != 0;
}
void TimelineViewGhostItem::UpdateRect()
@@ -50,17 +50,17 @@ public:
bool CanHaveZeroLength() const;
bool CanMoveTracks() const;
bool GetCanMoveTracks() const;
void SetCanMoveTracks(bool e);
void SetInvisible(bool invisible);
const rational& In() const;
const rational& Out() const;
const rational& MediaIn() const;
const rational& GetIn() const;
const rational& GetOut() const;
const rational& GetMediaIn() const;
rational Length() const;
rational AdjustedLength() const;
rational GetLength() const;
rational GetAdjustedLength() const;
void SetIn(const rational& in);
void SetOut(const rational& out);
@@ -71,18 +71,18 @@ public:
void SetTrackAdjustment(const int& track_adj);
void SetMediaInAdjustment(const rational& media_in_adj);
const rational& InAdjustment() const;
const rational& OutAdjustment() const;
const rational& MediaInAdjustment() const;
const int& TrackAdjustment() const;
const rational& GetInAdjustment() const;
const rational& GetOutAdjustment() const;
const rational& GetMediaInAdjustment() const;
const int& GetTrackAdjustment() const;
rational GetAdjustedIn() const;
rational GetAdjustedOut() const;
rational GetAdjustedMediaIn() const;
TrackReference GetAdjustedTrack() const;
const Timeline::MovementMode& mode() const;
void SetMode(const Timeline::MovementMode& mode);
const Timeline::MovementMode& GetMode() const;
void SetMode(const Timeline::MovementMode& GetMode);
bool HasBeenAdjusted() const;