diff --git a/app/widget/timelinewidget/view/timelineview.cpp b/app/widget/timelinewidget/view/timelineview.cpp index 101418112..1a87b608c 100644 --- a/app/widget/timelinewidget/view/timelineview.cpp +++ b/app/widget/timelinewidget/view/timelineview.cpp @@ -41,30 +41,10 @@ TimelineView::TimelineView(const TrackType &type, Qt::Alignment vertical_alignme Q_ASSERT(vertical_alignment == Qt::AlignTop || vertical_alignment == Qt::AlignBottom); setAlignment(Qt::AlignLeft | vertical_alignment); - setScene(&scene_); setDragMode(NoDrag); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setBackgroundRole(QPalette::Window); setContextMenuPolicy(Qt::CustomContextMenu); - - connect(&scene_, SIGNAL(changed(const QList&)), this, SLOT(UpdateSceneRect())); - - // Create end item - end_item_ = new TimelineViewEndItem(); - scene_.addItem(end_item_); - - // Set default scale - SetScale(1.0); -} - -void TimelineView::SetScale(const double &scale) -{ - scale_ = scale; - - // Force redraw for playhead - viewport()->update(); - - end_item_->SetScale(scale_); } void TimelineView::SelectAll() @@ -170,13 +150,6 @@ void TimelineView::dropEvent(QDropEvent *event) emit DragDropped(&timeline_event); } -void TimelineView::resizeEvent(QResizeEvent *event) -{ - QGraphicsView::resizeEvent(event); - - UpdateSceneRect(); -} - Stream::Type TimelineView::TrackTypeToStreamType(TrackType track_type) { switch (track_type) { @@ -270,43 +243,3 @@ void TimelineView::UserSetTime(const int64_t &time) SetTime(time); emit TimeChanged(time); } - -void TimelineView::UpdateSceneRect() -{ - QRectF bounding_rect = scene_.itemsBoundingRect(); - - // Ensure the scene height is always AT LEAST the height of the view - // The scrollbar appears to have a 1px margin on the top and bottom, hence the -2 - int minimum_height = height() - horizontalScrollBar()->height() - 2; - - if (alignment() & Qt::AlignBottom) { - // Ensure the scene left and bottom are always 0 - bounding_rect.setBottomLeft(QPointF(0, 0)); - - if (bounding_rect.top() > minimum_height) { - bounding_rect.setTop(-minimum_height); - } - } else { - // Ensure the scene left and top are always 0 - bounding_rect.setTopLeft(QPointF(0, 0)); - - if (bounding_rect.height() < minimum_height) { - bounding_rect.setHeight(minimum_height); - } - } - - // Ensure the scene is always the full length of the timeline with a gap at the end to work with - end_item_->SetEndPadding(width()/4); - - // If the scene is already this rect, do nothing - if (scene_.sceneRect() == bounding_rect) { - return; - } - - scene_.setSceneRect(bounding_rect); -} - -void TimelineView::SetEndTime(const rational &length) -{ - end_item_->SetEndTime(length); -} diff --git a/app/widget/timelinewidget/view/timelineview.h b/app/widget/timelinewidget/view/timelineview.h index 00578b6f4..0f48c1d44 100644 --- a/app/widget/timelinewidget/view/timelineview.h +++ b/app/widget/timelinewidget/view/timelineview.h @@ -32,7 +32,6 @@ #include "timelineviewbase.h" #include "timelineviewblockitem.h" #include "timelineviewmouseevent.h" -#include "timelineviewenditem.h" #include "timelineviewghostitem.h" #include "widget/timelinewidget/undo/undo.h" #include "undo/undostack.h" @@ -50,14 +49,10 @@ public: Qt::Alignment vertical_alignment = Qt::AlignTop, QWidget* parent = nullptr); - void SetScale(const double& scale); - void SelectAll(); void DeselectAll(); - void SetEndTime(const rational& length); - int GetTrackY(int track_index); int GetTrackHeight(int track_index); @@ -67,8 +62,6 @@ public: void ConnectTrackList(TrackList* list); signals: - void ScaleChanged(double scale); - void MousePressed(TimelineViewMouseEvent* event); void MouseMoved(TimelineViewMouseEvent* event); void MouseReleased(TimelineViewMouseEvent* event); @@ -90,8 +83,6 @@ protected: virtual void dragLeaveEvent(QDragLeaveEvent *event) override; virtual void dropEvent(QDropEvent *event) override; - virtual void resizeEvent(QResizeEvent *event) override; - private: TrackType ConnectedTrackType(); Stream::Type TrackTypeToStreamType(TrackType track_type); @@ -107,18 +98,8 @@ private: TrackList* connected_track_list_; - QGraphicsScene scene_; - - TimelineViewEndItem* end_item_; - TrackType type_; -private slots: - /** - * @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes - */ - void UpdateSceneRect(); - }; #endif // TIMELINEVIEW_H diff --git a/app/widget/timelinewidget/view/timelineviewbase.cpp b/app/widget/timelinewidget/view/timelineviewbase.cpp index 70916ff20..e7b6d4297 100644 --- a/app/widget/timelinewidget/view/timelineviewbase.cpp +++ b/app/widget/timelinewidget/view/timelineviewbase.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "common/timecodefunctions.h" @@ -11,6 +12,26 @@ TimelineViewBase::TimelineViewBase(QWidget *parent) : playhead_scene_left_(-1), playhead_scene_right_(-1) { + setScene(&scene_); + + // Create end item + end_item_ = new TimelineViewEndItem(); + scene_.addItem(end_item_); + + // Set default scale + SetScale(1.0); + + connect(&scene_, SIGNAL(changed(const QList&)), this, SLOT(UpdateSceneRect())); +} + +void TimelineViewBase::SetScale(const double &scale) +{ + scale_ = scale; + + // Force redraw for playhead + viewport()->update(); + + end_item_->SetScale(scale_); } void TimelineViewBase::SetTimebase(const rational &timebase) @@ -78,3 +99,50 @@ bool TimelineViewBase::PlayheadRelease(QMouseEvent *event) { return dragging_playhead_; } + +void TimelineViewBase::SetEndTime(const rational &length) +{ + end_item_->SetEndTime(length); +} + +void TimelineViewBase::UpdateSceneRect() +{ + QRectF bounding_rect = scene_.itemsBoundingRect(); + + // Ensure the scene height is always AT LEAST the height of the view + // The scrollbar appears to have a 1px margin on the top and bottom, hence the -2 + int minimum_height = height() - horizontalScrollBar()->height() - 2; + + if (alignment() & Qt::AlignBottom) { + // Ensure the scene left and bottom are always 0 + bounding_rect.setBottomLeft(QPointF(0, 0)); + + if (bounding_rect.top() > minimum_height) { + bounding_rect.setTop(-minimum_height); + } + } else { + // Ensure the scene left and top are always 0 + bounding_rect.setTopLeft(QPointF(0, 0)); + + if (bounding_rect.height() < minimum_height) { + bounding_rect.setHeight(minimum_height); + } + } + + // Ensure the scene is always the full length of the timeline with a gap at the end to work with + end_item_->SetEndPadding(width()/4); + + // If the scene is already this rect, do nothing + if (scene_.sceneRect() == bounding_rect) { + return; + } + + scene_.setSceneRect(bounding_rect); +} + +void TimelineViewBase::resizeEvent(QResizeEvent *event) +{ + QGraphicsView::resizeEvent(event); + + UpdateSceneRect(); +} diff --git a/app/widget/timelinewidget/view/timelineviewbase.h b/app/widget/timelinewidget/view/timelineviewbase.h index c29042a70..d3b9c2719 100644 --- a/app/widget/timelinewidget/view/timelineviewbase.h +++ b/app/widget/timelinewidget/view/timelineviewbase.h @@ -4,6 +4,7 @@ #include #include "timelineplayhead.h" +#include "timelineviewenditem.h" #include "widget/timelinewidget/timelinescaledobject.h" class TimelineViewBase : public QGraphicsView, public TimelineScaledObject @@ -12,7 +13,9 @@ class TimelineViewBase : public QGraphicsView, public TimelineScaledObject public: TimelineViewBase(QWidget* parent = nullptr); - virtual void drawForeground(QPainter *painter, const QRectF &rect) override; + void SetScale(const double& scale); + + void SetEndTime(const rational& length); public slots: void SetTimebase(const rational& timebase); @@ -22,7 +25,13 @@ public slots: signals: void TimeChanged(const int64_t& time); + void ScaleChanged(double scale); + protected: + virtual void drawForeground(QPainter *painter, const QRectF &rect) override; + + virtual void resizeEvent(QResizeEvent *event) override; + rational GetPlayheadTime(); bool PlayheadPress(QMouseEvent* event); @@ -39,6 +48,16 @@ private: bool dragging_playhead_; + TimelineViewEndItem* end_item_; + + QGraphicsScene scene_; + +private slots: + /** + * @brief Slot called whenever the view resizes or the scene contents change to enforce minimum scene sizes + */ + void UpdateSceneRect(); + }; #endif // TIMELINEVIEWBASE_H