diff --git a/app/widget/timelinewidget/view/timelineview.cpp b/app/widget/timelinewidget/view/timelineview.cpp index 2f1d5c6e0..63ae9c643 100644 --- a/app/widget/timelinewidget/view/timelineview.cpp +++ b/app/widget/timelinewidget/view/timelineview.cpp @@ -38,6 +38,7 @@ OLIVE_NAMESPACE_ENTER TimelineView::TimelineView(Qt::Alignment vertical_alignment, QWidget *parent) : TimelineViewBase(parent), selections_(nullptr), + ghosts_(nullptr), show_beam_cursor_(false), connected_track_list_(nullptr) { @@ -229,21 +230,7 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect) { TimelineViewBase::drawForeground(painter, rect); - if (show_beam_cursor_ - && connected_track_list_ - && cursor_coord_.GetTrack().type() == connected_track_list_->type()) { - painter->setPen(Qt::gray); - - double cursor_x = TimeToScene(cursor_coord_.GetFrame()); - int track_index = cursor_coord_.GetTrack().index(); - int track_y = GetTrackY(track_index); - - painter->drawLine(cursor_x, - track_y, - cursor_x, - track_y + GetTrackHeight(track_index)); - } - + // Draw selections if (selections_ && !selections_->isEmpty()) { painter->setPen(Qt::NoPen); painter->setBrush(QColor(0, 0, 0, 64)); @@ -261,6 +248,39 @@ void TimelineView::drawForeground(QPainter *painter, const QRectF &rect) } } } + + // Draw ghosts + if (ghosts_ && !ghosts_->isEmpty()) { + painter->setPen(QPen(Qt::yellow, 2)); + painter->setBrush(Qt::NoBrush); + + foreach (TimelineViewGhostItem* ghost, (*ghosts_)) { + if (ghost->GetTrack().type() == connected_track_list_->type()) { + int track_index = ghost->GetAdjustedTrack().index(); + + painter->drawRect(TimeToScene(ghost->GetAdjustedIn()), + GetTrackY(track_index), + TimeToScene(ghost->GetAdjustedLength()), + GetTrackHeight(track_index)); + } + } + } + + // Draw beam cursor + if (show_beam_cursor_ + && connected_track_list_ + && cursor_coord_.GetTrack().type() == connected_track_list_->type()) { + painter->setPen(Qt::gray); + + double cursor_x = TimeToScene(cursor_coord_.GetFrame()); + int track_index = cursor_coord_.GetTrack().index(); + int track_y = GetTrackY(track_index); + + painter->drawLine(cursor_x, + track_y, + cursor_x, + track_y + GetTrackHeight(track_index)); + } } void TimelineView::ToolChangedEvent(Tool::Item tool) diff --git a/app/widget/timelinewidget/view/timelineview.h b/app/widget/timelinewidget/view/timelineview.h index 67606dcea..88740a93e 100644 --- a/app/widget/timelinewidget/view/timelineview.h +++ b/app/widget/timelinewidget/view/timelineview.h @@ -64,6 +64,11 @@ public: selections_ = s; } + void SetGhostList(QVector* ghosts) + { + ghosts_ = ghosts; + } + signals: void MousePressed(TimelineViewMouseEvent* event); void MouseMoved(TimelineViewMouseEvent* event); @@ -115,6 +120,8 @@ private: QHash* selections_; + QVector* ghosts_; + bool show_beam_cursor_; TimelineCoordinate cursor_coord_; diff --git a/app/widget/timelinewidget/view/timelineviewghostitem.cpp b/app/widget/timelinewidget/view/timelineviewghostitem.cpp index eb9990a7b..b2a0c86e8 100644 --- a/app/widget/timelinewidget/view/timelineviewghostitem.cpp +++ b/app/widget/timelinewidget/view/timelineviewghostitem.cpp @@ -24,18 +24,17 @@ OLIVE_NAMESPACE_ENTER -TimelineViewGhostItem::TimelineViewGhostItem(QGraphicsItem *parent) : - TimelineViewRect(parent), +TimelineViewGhostItem::TimelineViewGhostItem() : track_adj_(0), stream_(nullptr), mode_(Timeline::kNone), can_have_zero_length_(true), - can_move_tracks_(true) + can_move_tracks_(true), + invisible_(false) { - SetInvisible(false); } -TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const TrackReference& track, int y, int height) +TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const TrackReference& track) { TimelineViewGhostItem* ghost = new TimelineViewGhostItem(); @@ -43,8 +42,7 @@ TimelineViewGhostItem *TimelineViewGhostItem::FromBlock(Block *block, const Trac ghost->SetOut(block->out()); ghost->SetMediaIn(block->media_in()); ghost->SetTrack(track); - ghost->SetYCoords(y, height); - ghost->setData(kAttachedBlock, Node::PtrToValue(block)); + ghost->SetData(kAttachedBlock, Node::PtrToValue(block)); switch (block->type()) { case Block::kClip: @@ -76,7 +74,7 @@ void TimelineViewGhostItem::SetCanMoveTracks(bool e) can_move_tracks_ = e; } -void TimelineViewGhostItem::SetInvisible(bool invisible) +/*void TimelineViewGhostItem::SetInvisible(bool invisible) { setBrush(Qt::NoBrush); @@ -85,7 +83,7 @@ void TimelineViewGhostItem::SetInvisible(bool invisible) } else { setPen(QPen(Qt::yellow, 2)); // FIXME: Make customizable via CSS } -} +}*/ const rational &TimelineViewGhostItem::GetIn() const { @@ -115,15 +113,11 @@ rational TimelineViewGhostItem::GetAdjustedLength() const void TimelineViewGhostItem::SetIn(const rational &in) { in_ = in; - - UpdateRect(); } void TimelineViewGhostItem::SetOut(const rational &out) { out_ = out; - - UpdateRect(); } void TimelineViewGhostItem::SetMediaIn(const rational &media_in) @@ -134,15 +128,11 @@ void TimelineViewGhostItem::SetMediaIn(const rational &media_in) void TimelineViewGhostItem::SetInAdjustment(const rational &in_adj) { in_adj_ = in_adj; - - UpdateRect(); } void TimelineViewGhostItem::SetOutAdjustment(const rational &out_adj) { out_adj_ = out_adj; - - UpdateRect(); } void TimelineViewGhostItem::SetTrackAdjustment(const int &track_adj) @@ -213,13 +203,4 @@ bool TimelineViewGhostItem::HasBeenAdjusted() const || GetTrackAdjustment() != 0; } -void TimelineViewGhostItem::UpdateRect() -{ - rational length = GetAdjustedOut() - GetAdjustedIn(); - - setRect(0, y_, TimeToScene(length), height_ - 1); - - setPos(TimeToScene(GetAdjustedIn()), 0); -} - OLIVE_NAMESPACE_EXIT diff --git a/app/widget/timelinewidget/view/timelineviewghostitem.h b/app/widget/timelinewidget/view/timelineviewghostitem.h index b96955fdb..d13ad7d7c 100644 --- a/app/widget/timelinewidget/view/timelineviewghostitem.h +++ b/app/widget/timelinewidget/view/timelineviewghostitem.h @@ -32,7 +32,7 @@ OLIVE_NAMESPACE_ENTER /** * @brief A graphical representation of changes the user is making before they apply it */ -class TimelineViewGhostItem : public TimelineViewRect +class TimelineViewGhostItem { public: enum DataType { @@ -44,17 +44,15 @@ public: kTrimShouldBeIgnored }; - TimelineViewGhostItem(QGraphicsItem* parent = nullptr); + TimelineViewGhostItem(); - static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track, int y, int height); + static TimelineViewGhostItem* FromBlock(Block *block, const TrackReference &track); bool CanHaveZeroLength() const; bool GetCanMoveTracks() const; void SetCanMoveTracks(bool e); - void SetInvisible(bool invisible); - const rational& GetIn() const; const rational& GetOut() const; const rational& GetMediaIn() const; @@ -86,7 +84,35 @@ public: bool HasBeenAdjusted() const; - virtual void UpdateRect() override; + QVariant GetData(int key) const + { + return data_.value(key); + } + + void SetData(int key, const QVariant& value) + { + data_.insert(key, value); + } + + const TrackReference& GetTrack() const + { + return track_; + } + + void SetTrack(const TrackReference& track) + { + track_ = track; + } + + bool IsInvisible() const + { + return invisible_; + } + + void SetInvisible(bool e) + { + invisible_ = e; + } protected: @@ -107,6 +133,13 @@ private: bool can_have_zero_length_; bool can_move_tracks_; + + TrackReference track_; + + QHash data_; + + bool invisible_; + }; OLIVE_NAMESPACE_EXIT