implemented basic trimming

This commit is contained in:
itsmattkc
2019-08-22 13:06:21 +10:00
parent 0ede7bd319
commit 51a441bc29
7 changed files with 118 additions and 21 deletions
+2
View File
@@ -131,6 +131,8 @@ private:
virtual void DragMove(QDragMoveEvent *event) override;
virtual void DragLeave(QDragLeaveEvent *event) override;
virtual void DragDrop(QDropEvent *event) override;
private:
int import_pre_buffer_;
};
int GetTrackY(int track_index);
@@ -55,6 +55,7 @@ void TimelineViewClipItem::UpdateRect()
double item_left = TimeToScreenCoord(clip_->in());
double item_width = TimeToScreenCoord(clip_->length());
// -1 on width and height so we don't overlap any adjacent clips
setRect(0, y_, item_width - 1, height_ - 1);
setPos(item_left, 0.0);
}
@@ -42,6 +42,7 @@ protected:
private:
ClipBlock* clip_;
};
#endif // TIMELINEVIEWCLIPITEM_H
@@ -48,22 +48,22 @@ TimelineViewGhostItem *TimelineViewGhostItem::FromClip(TimelineViewClipItem *cli
return ghost;
}
const rational &TimelineViewGhostItem::In()
const rational &TimelineViewGhostItem::In() const
{
return in_;
}
const rational &TimelineViewGhostItem::Out()
const rational &TimelineViewGhostItem::Out() const
{
return out_;
}
rational TimelineViewGhostItem::Length()
rational TimelineViewGhostItem::Length() const
{
return out_ - in_;
}
rational TimelineViewGhostItem::AdjustedLength()
rational TimelineViewGhostItem::AdjustedLength() const
{
return GetAdjustedOut() - GetAdjustedIn();
}
@@ -101,22 +101,47 @@ void TimelineViewGhostItem::SetTrackAdjustment(const int &track_adj)
track_adj_ = track_adj;
}
rational TimelineViewGhostItem::GetAdjustedIn()
const rational &TimelineViewGhostItem::InAdjustment() const
{
return in_adj_;
}
const rational &TimelineViewGhostItem::OutAdjustment() const
{
return out_adj_;
}
const int &TimelineViewGhostItem::TrackAdjustment() const
{
return track_adj_;
}
rational TimelineViewGhostItem::GetAdjustedIn() const
{
return in_ + in_adj_;
}
rational TimelineViewGhostItem::GetAdjustedOut()
rational TimelineViewGhostItem::GetAdjustedOut() const
{
return out_ + out_adj_;
}
int TimelineViewGhostItem::GetAdjustedTrack()
int TimelineViewGhostItem::GetAdjustedTrack() const
{
return track_ + track_adj_;
}
const QVariant &TimelineViewGhostItem::data()
const TimelineViewGhostItem::Mode &TimelineViewGhostItem::mode() const
{
return mode_;
}
void TimelineViewGhostItem::SetMode(const TimelineViewGhostItem::Mode &mode)
{
mode_ = mode;
}
const QVariant &TimelineViewGhostItem::data() const
{
return data_;
}
@@ -33,15 +33,22 @@
class TimelineViewGhostItem : public TimelineViewRect
{
public:
enum Mode {
kNone,
kMove,
kTrimIn,
kTrimOut
};
TimelineViewGhostItem(QGraphicsItem* parent = nullptr);
static TimelineViewGhostItem* FromClip(TimelineViewClipItem* clip_item);
const rational& In();
const rational& Out();
const rational& In() const;
const rational& Out() const;
rational Length();
rational AdjustedLength();
rational Length() const;
rational AdjustedLength() const;
void SetIn(const rational& in);
void SetOut(const rational& out);
@@ -50,11 +57,18 @@ public:
void SetOutAdjustment(const rational& out_adj);
void SetTrackAdjustment(const int& track_adj);
rational GetAdjustedIn();
rational GetAdjustedOut();
int GetAdjustedTrack();
const rational& InAdjustment() const;
const rational& OutAdjustment() const;
const int& TrackAdjustment() const;
const QVariant& data();
rational GetAdjustedIn() const;
rational GetAdjustedOut() const;
int GetAdjustedTrack() const;
const Mode& mode() const;
void SetMode(const Mode& mode);
const QVariant& data() const;
void SetData(const QVariant& data);
virtual void UpdateRect() override;
@@ -73,6 +87,8 @@ private:
StreamPtr stream_;
QVariant data_;
Mode mode_;
};
#endif // TIMELINEVIEWGHOSTITEM_H
+5 -2
View File
@@ -22,11 +22,15 @@
#include <QMimeData>
#include "common/qtversionabstraction.h"
#include "node/input/media/media.h"
TimelineView::ImportTool::ImportTool(TimelineView *parent) :
Tool(parent)
{
// Calculate width used for importing to give ghosts a slight lead-in so the ghosts aren't right on the cursor
QFontMetrics fm = parent->fontMetrics();
import_pre_buffer_ = QFontMetricsWidth(&fm, "HHHHHHHH");
}
void TimelineView::ImportTool::DragEnter(QDragEnterEvent *event)
@@ -51,8 +55,7 @@ void TimelineView::ImportTool::DragEnter(QDragEnterEvent *event)
drag_start_ = GetScenePos(event->pos());
// Set ghosts to start where the cursor entered
// FIXME: 100 = magic number so that imported clips are not right on the cursor when dragged in
rational ghost_start = parent()->SceneToTime(drag_start_.x() - 100);
rational ghost_start = parent()->SceneToTime(drag_start_.x() - import_pre_buffer_);
while (!stream.atEnd()) {
stream >> r >> item_ptr;
+52 -3
View File
@@ -20,6 +20,8 @@
#include "widget/timelineview/timelineview.h"
#include <QDebug>
#include "node/block/gap/gap.h"
TimelineView::PointerTool::PointerTool(TimelineView *parent) :
@@ -57,8 +59,20 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
drag_start_ = GetScenePos(event->pos());
track_start_ = parent()->SceneToTrack(drag_start_.y());
TimelineViewRect* clicked_item = static_cast<TimelineViewRect*>(GetItemAtScenePos(drag_start_));
// Let's see if there's anything selected to drag
if (GetItemAtScenePos(drag_start_) != nullptr) {
if (clicked_item != nullptr) {
TimelineViewGhostItem::Mode trim_mode;
if (drag_start_.x() < clicked_item->x() + clicked_item->rect().left() + 20) {
trim_mode = TimelineViewGhostItem::kTrimIn;
} else if (drag_start_.x() > clicked_item->x() + clicked_item->rect().right() - 20) {
trim_mode = TimelineViewGhostItem::kTrimOut;
} else {
trim_mode = TimelineViewGhostItem::kMove;
}
QList<QGraphicsItem*> selected_items = parent()->scene_.selectedItems();
foreach (QGraphicsItem* item, selected_items) {
@@ -67,6 +81,18 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
ghost->SetScale(parent()->scale_);
/*
// Determine correct mode for ghost
if (trim_mode == TimelineViewGhostItem::kMove) {
// Movement is indiscriminate, all the ghosts can be set to this
ghost->SetMode(TimelineViewGhostItem::kMove);
} else {
}
*/
// FIXME: Determine correct modes
ghost->SetMode(trim_mode);
parent()->ghost_items_.append(ghost);
parent()->scene_.addItem(ghost);
}
@@ -90,8 +116,20 @@ void TimelineView::PointerTool::MouseMove(QMouseEvent *event)
// Perform movement
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
ghost->SetInAdjustment(time_movement);
ghost->SetOutAdjustment(time_movement);
switch (ghost->mode()) {
case TimelineViewGhostItem::kNone:
break;
case TimelineViewGhostItem::kTrimIn:
ghost->SetInAdjustment(time_movement);
break;
case TimelineViewGhostItem::kTrimOut:
ghost->SetOutAdjustment(time_movement);
break;
case TimelineViewGhostItem::kMove:
ghost->SetInAdjustment(time_movement);
ghost->SetOutAdjustment(time_movement);
break;
}
ghost->SetTrackAdjustment(track_movement);
int track = ghost->GetAdjustedTrack();
@@ -123,6 +161,17 @@ void TimelineView::PointerTool::MouseRelease(QMouseEvent *event)
foreach (TimelineViewGhostItem* ghost, parent()->ghost_items_) {
Block* b = Node::ValueToPtr<Block>(ghost->data());
if (ghost->mode() == TimelineViewGhostItem::kTrimIn || ghost->mode() == TimelineViewGhostItem::kTrimOut) {
// If we were trimming, we'll need to change the length
// If we were trimming the in point, we'll need to adjust the media in too
if (ghost->mode() == TimelineViewGhostItem::kTrimIn) {
b->set_media_in(b->media_in() + ghost->InAdjustment());
}
b->set_length(ghost->AdjustedLength());
}
emit parent()->RequestPlaceBlock(b, ghost->GetAdjustedIn(), ghost->GetAdjustedTrack());
}