timeline: implemented in/out points

This commit is contained in:
itsmattkc
2020-03-08 01:06:45 +11:00
parent 52fc4f064b
commit dc37389d02
23 changed files with 609 additions and 25 deletions
+36 -11
View File
@@ -39,16 +39,16 @@ MenuShared::MenuShared()
edit_paste_item_ = Menu::CreateItem(this, "paste", nullptr, nullptr, "Ctrl+V");
edit_paste_insert_item_ = Menu::CreateItem(this, "pasteinsert", nullptr, nullptr, "Ctrl+Shift+V");
edit_duplicate_item_ = Menu::CreateItem(this, "duplicate", nullptr, nullptr, "Ctrl+D");
edit_delete_item_ = Menu::CreateItem(this, "delete", this, SLOT(DeleteSelected()), "Del");
edit_ripple_delete_item_ = Menu::CreateItem(this, "rippledelete", this, SLOT(RippleDelete()), "Shift+Del");
edit_split_item_ = Menu::CreateItem(this, "split", this, SLOT(SplitAtPlayhead()), "Ctrl+K");
edit_delete_item_ = Menu::CreateItem(this, "delete", this, SLOT(DeleteSelectedTriggered()), "Del");
edit_ripple_delete_item_ = Menu::CreateItem(this, "rippledelete", this, SLOT(RippleDeleteTriggered()), "Shift+Del");
edit_split_item_ = Menu::CreateItem(this, "split", this, SLOT(SplitAtPlayheadTriggered()), "Ctrl+K");
// "In/Out" menu shared items
inout_set_in_item_ = Menu::CreateItem(this, "setinpoint", nullptr, nullptr, "I");
inout_set_out_item_ = Menu::CreateItem(this, "setoutpoint", nullptr, nullptr, "O");
inout_reset_in_item_ = Menu::CreateItem(this, "resetin", nullptr, nullptr);
inout_reset_out_item_ = Menu::CreateItem(this, "resetout", nullptr, nullptr);
inout_clear_inout_item_ = Menu::CreateItem(this, "clearinout", nullptr, nullptr, "G");
inout_set_in_item_ = Menu::CreateItem(this, "setinpoint", this, SLOT(SetInTriggered()), "I");
inout_set_out_item_ = Menu::CreateItem(this, "setoutpoint", this, SLOT(SetOutTriggered()), "O");
inout_reset_in_item_ = Menu::CreateItem(this, "resetin", this, SLOT(ResetInTriggered()));
inout_reset_out_item_ = Menu::CreateItem(this, "resetout", this, SLOT(ResetOutTriggered()));
inout_clear_inout_item_ = Menu::CreateItem(this, "clearinout", this, SLOT(ClearInOutTriggered()), "G");
// "Clip Edit" menu shared items
clip_add_default_transition_item_ = Menu::CreateItem(this, "deftransition", nullptr, nullptr, "Ctrl+Shift+D");
@@ -112,7 +112,7 @@ MenuShared *MenuShared::instance()
return instance_;
}
void MenuShared::SplitAtPlayhead()
void MenuShared::SplitAtPlayheadTriggered()
{
TimelinePanel* timeline = PanelManager::instance()->MostRecentlyFocused<TimelinePanel>();
@@ -121,16 +121,41 @@ void MenuShared::SplitAtPlayhead()
}
}
void MenuShared::DeleteSelected()
void MenuShared::DeleteSelectedTriggered()
{
PanelManager::instance()->CurrentlyFocused()->DeleteSelected();
}
void MenuShared::RippleDelete()
void MenuShared::RippleDeleteTriggered()
{
PanelManager::instance()->CurrentlyFocused()->RippleDelete();
}
void MenuShared::SetInTriggered()
{
PanelManager::instance()->CurrentlyFocused()->SetIn();
}
void MenuShared::SetOutTriggered()
{
PanelManager::instance()->CurrentlyFocused()->SetOut();
}
void MenuShared::ResetInTriggered()
{
PanelManager::instance()->CurrentlyFocused()->ResetIn();
}
void MenuShared::ResetOutTriggered()
{
PanelManager::instance()->CurrentlyFocused()->ResetOut();
}
void MenuShared::ClearInOutTriggered()
{
PanelManager::instance()->CurrentlyFocused()->ClearInOut();
}
void MenuShared::Retranslate()
{
// "New" menu shared items
+13 -3
View File
@@ -75,11 +75,21 @@ private:
static MenuShared* instance_;
private slots:
void SplitAtPlayhead();
void SplitAtPlayheadTriggered();
void DeleteSelected();
void DeleteSelectedTriggered();
void RippleDelete();
void RippleDeleteTriggered();
void SetInTriggered();
void SetOutTriggered();
void ResetInTriggered();
void ResetOutTriggered();
void ClearInOutTriggered();
};
+10
View File
@@ -118,6 +118,16 @@ public:
virtual void DecreaseTrackHeight(){}
virtual void SetIn(){}
virtual void SetOut(){}
virtual void ResetIn(){}
virtual void ResetOut(){}
virtual void ClearInOut(){}
protected:
/**
* @brief paintEvent
+105
View File
@@ -1,6 +1,11 @@
#include "timebased.h"
#include <QUndoCommand>
#include "common/timecodefunctions.h"
#include "core.h"
#include "project/item/sequence/sequence.h"
#include "widget/timelinewidget/undo/undo.h"
TimeBasedWidget::TimeBasedWidget(bool ruler_text_visible, bool ruler_cache_status_visible, QWidget *parent) :
QWidget(parent),
@@ -44,6 +49,8 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
DisconnectNodeInternal(viewer_node_);
disconnect(viewer_node_, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
ruler()->ConnectTimelinePoints(nullptr);
}
viewer_node_ = node;
@@ -54,6 +61,8 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
ConnectNodeInternal(viewer_node_);
connect(viewer_node_, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
ruler()->ConnectTimelinePoints(static_cast<Sequence*>(viewer_node_->parent()));
}
}
@@ -242,3 +251,99 @@ void TimeBasedWidget::CenterScrollOnPlayhead()
{
scrollbar_->setValue(qRound(TimeToScene(Timecode::timestamp_to_time(ruler_->GetTime(), timebase()))) - scrollbar_->width()/2);
}
void TimeBasedWidget::SetPoint(Timeline::MovementMode m, const rational& time)
{
if (!GetConnectedNode()) {
return;
}
QUndoCommand* command = new QUndoCommand();
Sequence* s = static_cast<Sequence*>(GetConnectedNode()->parent());
// Enable workarea if it isn't already enabled
if (!s->workarea()->enabled()) {
new WorkareaSetEnabledCommand(s, true, command);
}
// Determine our new range
rational in_point, out_point;
if (m == Timeline::kTrimIn) {
in_point = time;
if (!s->workarea()->enabled() || s->workarea()->out() < in_point) {
out_point = TimelineWorkArea::kResetOut;
} else {
out_point = s->workarea()->out();
}
} else {
out_point = time;
if (!s->workarea()->enabled() || s->workarea()->in() > out_point) {
in_point = TimelineWorkArea::kResetIn;
} else {
in_point = s->workarea()->in();
}
}
// Set workarea
new WorkareaSetRangeCommand(s, TimeRange(in_point, out_point), command);
Core::instance()->undo_stack()->push(command);
}
void TimeBasedWidget::ResetPoint(Timeline::MovementMode m)
{
if (!GetConnectedNode()) {
return;
}
Sequence* s = static_cast<Sequence*>(GetConnectedNode()->parent());
if (!s->workarea()->enabled()) {
return;
}
TimeRange r = s->workarea()->range();
if (m == Timeline::kTrimIn) {
r.set_in(TimelineWorkArea::kResetIn);
} else {
r.set_out(TimelineWorkArea::kResetOut);
}
Core::instance()->undo_stack()->push(new WorkareaSetRangeCommand(s, r));
}
void TimeBasedWidget::SetInAtPlayhead()
{
SetPoint(Timeline::kTrimIn, GetTime());
}
void TimeBasedWidget::SetOutAtPlayhead()
{
SetPoint(Timeline::kTrimOut, GetTime());
}
void TimeBasedWidget::ResetIn()
{
ResetPoint(Timeline::kTrimIn);
}
void TimeBasedWidget::ResetOut()
{
ResetPoint(Timeline::kTrimOut);
}
void TimeBasedWidget::ClearInOutPoints()
{
if (!GetConnectedNode()) {
return;
}
Sequence* s = static_cast<Sequence*>(GetConnectedNode()->parent());
Core::instance()->undo_stack()->push(new WorkareaSetEnabledCommand(s, false));
}
+31
View File
@@ -3,6 +3,7 @@
#include <QWidget>
#include "common/timelinecommon.h"
#include "node/output/viewer/viewer.h"
#include "widget/resizablescrollbar/resizablescrollbar.h"
#include "widget/timelinewidget/timelinescaledobject.h"
@@ -48,6 +49,16 @@ public slots:
void GoToNextCut();
void SetInAtPlayhead();
void SetOutAtPlayhead();
void ResetIn();
void ResetOut();
void ClearInOutPoints();
TimeRuler* ruler() const;
protected slots:
@@ -84,6 +95,26 @@ signals:
void TimebaseChanged(const rational&);
private:
/**
* @brief Set either in or out point to the current playhead
*
* @param m
*
* Set to kTrimIn or kTrimOut for setting the in point or out point respectively.
*/
void SetPoint(Timeline::MovementMode m, const rational &time);
/**
* @brief Reset either the in or out point
*
* Sets either the in point to 0 or the out point to `RATIONAL_MAX`.
*
* @param m
*
* Set to kTrimIn or kTrimOut for setting the in point or out point respectively.
*/
void ResetPoint(Timeline::MovementMode m);
ViewerOutput* viewer_node_;
TimeRuler* ruler_;
+2 -2
View File
@@ -335,7 +335,7 @@ void TimelineWidget::SplitAtPlayhead()
}
}
void TimelineWidget::DeleteSelectedInternal(QList<Block *> blocks,
void TimelineWidget::DeleteSelectedInternal(const QList<Block *> &blocks,
bool transition_aware,
bool remove_from_graph,
QUndoCommand *command)
@@ -426,7 +426,7 @@ void TimelineWidget::DeleteSelected(bool ripple)
range_list.InsertTimeRange(TimeRange(b->in(), b->out()));
}
new TimelineRippleDeleteGapsAtRegions(GetConnectedNode(), range_list, command);
new TimelineRippleDeleteGapsAtRegionsCommand(GetConnectedNode(), range_list, command);
}
Core::instance()->undo_stack()->pushIfHasChildren(command);
+1 -1
View File
@@ -349,7 +349,7 @@ private:
bool dual_transition_;
};
void DeleteSelectedInternal(QList<Block *> blocks, bool transition_aware, bool remove_from_graph, QUndoCommand* command);
void DeleteSelectedInternal(const QList<Block *>& blocks, bool transition_aware, bool remove_from_graph, QUndoCommand* command);
void SetBlockLinksSelected(Block *block, bool selected);
+39 -3
View File
@@ -623,14 +623,14 @@ void BlockSetSpeedCommand::undo_internal()
block_->set_speed(old_speed_);
}
TimelineRippleDeleteGapsAtRegions::TimelineRippleDeleteGapsAtRegions(ViewerOutput *vo, const TimeRangeList &regions, QUndoCommand *parent) :
TimelineRippleDeleteGapsAtRegionsCommand::TimelineRippleDeleteGapsAtRegionsCommand(ViewerOutput *vo, const TimeRangeList &regions, QUndoCommand *parent) :
UndoCommand(parent),
timeline_(vo),
regions_(regions)
{
}
void TimelineRippleDeleteGapsAtRegions::redo_internal()
void TimelineRippleDeleteGapsAtRegionsCommand::redo_internal()
{
foreach (const TimeRange& range, regions_) {
rational max_ripple_length = range.length();
@@ -671,7 +671,7 @@ void TimelineRippleDeleteGapsAtRegions::redo_internal()
}
}
void TimelineRippleDeleteGapsAtRegions::undo_internal()
void TimelineRippleDeleteGapsAtRegionsCommand::undo_internal()
{
for (int i=commands_.size()-1;i>=0;i--) {
commands_.at(i)->undo();
@@ -679,3 +679,39 @@ void TimelineRippleDeleteGapsAtRegions::undo_internal()
}
commands_.empty();
}
WorkareaSetEnabledCommand::WorkareaSetEnabledCommand(TimelinePoints *points, bool enabled, QUndoCommand *parent) :
UndoCommand(parent),
points_(points),
old_enabled_(points_->workarea()->enabled()),
new_enabled_(enabled)
{
}
void WorkareaSetEnabledCommand::redo_internal()
{
points_->workarea()->set_enabled(new_enabled_);
}
void WorkareaSetEnabledCommand::undo_internal()
{
points_->workarea()->set_enabled(old_enabled_);
}
WorkareaSetRangeCommand::WorkareaSetRangeCommand(TimelinePoints *points, const TimeRange &range, QUndoCommand *parent) :
UndoCommand(parent),
points_(points),
old_range_(points_->workarea()->range()),
new_range_(range)
{
}
void WorkareaSetRangeCommand::redo_internal()
{
points_->workarea()->set_range(new_range_);
}
void WorkareaSetRangeCommand::undo_internal()
{
points_->workarea()->set_range(old_range_);
}
+37 -2
View File
@@ -27,6 +27,7 @@
#include "node/block/gap/gap.h"
#include "node/output/track/track.h"
#include "node/output/track/tracklist.h"
#include "timeline/timelinepoints.h"
#include "undo/undocommand.h"
class BlockResizeCommand : public UndoCommand {
@@ -280,9 +281,9 @@ private:
};
class TimelineRippleDeleteGapsAtRegions : public UndoCommand {
class TimelineRippleDeleteGapsAtRegionsCommand : public UndoCommand {
public:
TimelineRippleDeleteGapsAtRegions(ViewerOutput* vo, const TimeRangeList& regions, QUndoCommand* parent = nullptr);
TimelineRippleDeleteGapsAtRegionsCommand(ViewerOutput* vo, const TimeRangeList& regions, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
@@ -296,4 +297,38 @@ private:
};
class WorkareaSetEnabledCommand : public UndoCommand {
public:
WorkareaSetEnabledCommand(TimelinePoints* points, bool enabled, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
TimelinePoints* points_;
bool old_enabled_;
bool new_enabled_;
};
class WorkareaSetRangeCommand : public UndoCommand {
public:
WorkareaSetRangeCommand(TimelinePoints* points, const TimeRange& range, QUndoCommand* parent = nullptr);
protected:
virtual void redo_internal() override;
virtual void undo_internal() override;
private:
TimelinePoints* points_;
TimeRange old_range_;
TimeRange new_range_;
};
#endif // TIMELINEUNDOABLE_H
+40 -1
View File
@@ -37,7 +37,8 @@ TimeRuler::TimeRuler(bool text_visible, bool cache_status_visible, QWidget* pare
centered_text_(true),
scale_(1.0),
time_(0),
show_cache_status_(cache_status_visible)
show_cache_status_(cache_status_visible),
timeline_points_(nullptr)
{
QFontMetrics fm = fontMetrics();
@@ -81,6 +82,23 @@ void TimeRuler::SetTimebase(const rational &r)
update();
}
void TimeRuler::ConnectTimelinePoints(TimelinePoints *points)
{
if (timeline_points_) {
disconnect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, &TimeRuler::TimelineWorkareaChanged);
disconnect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, &TimeRuler::TimelineWorkareaChanged);
}
timeline_points_ = points;
if (timeline_points_) {
connect(timeline_points_->workarea(), &TimelineWorkArea::RangeChanged, this, &TimeRuler::TimelineWorkareaChanged);
connect(timeline_points_->workarea(), &TimelineWorkArea::EnabledChanged, this, &TimeRuler::TimelineWorkareaChanged);
}
update();
}
const int64_t &TimeRuler::GetTime()
{
return time_;
@@ -138,6 +156,22 @@ void TimeRuler::paintEvent(QPaintEvent *)
QPainter p(this);
// Draw timeline points if connected
if (timeline_points_) {
if (timeline_points_->workarea()->enabled()) {
int workarea_left = qMax(0, TimeToScreen(timeline_points_->workarea()->in()));
int workarea_right;
if (timeline_points_->workarea()->out() == TimelineWorkArea::kResetOut) {
workarea_right = width();
} else {
workarea_right = qMin(width(), TimeToScreen(timeline_points_->workarea()->out()));
}
p.fillRect(workarea_left, 0, workarea_right - workarea_left, height(), palette().highlight());
}
}
double width_of_frame = timebase_dbl_ * scale_;
double width_of_second = 0;
do {
@@ -381,6 +415,11 @@ void TimeRuler::SeekToScreenPoint(int screen)
emit TimeChanged(timestamp);
}
void TimeRuler::TimelineWorkareaChanged()
{
update();
}
void TimeRuler::UpdateHeight()
{
int height = text_height_;
+8
View File
@@ -26,6 +26,7 @@
#include "common/rational.h"
#include "common/timerange.h"
#include "timeline/timelinepoints.h"
#include "widget/timelinewidget/view/timelineplayhead.h"
class TimeRuler : public QWidget
@@ -41,6 +42,8 @@ public:
void SetCenteredText(bool c);
void ConnectTimelinePoints(TimelinePoints* points);
const int64_t& GetTime();
public slots:
@@ -115,6 +118,11 @@ private:
TimeRangeList dirty_cache_ranges_;
TimelinePoints* timeline_points_;
private slots:
void TimelineWorkareaChanged();
};
#endif // TIMERULER_H