diff --git a/panels/timeline.cpp b/panels/timeline.cpp index 70efae94f..c0b3f7a0a 100644 --- a/panels/timeline.cpp +++ b/panels/timeline.cpp @@ -90,7 +90,7 @@ Timeline::Timeline(QWidget *parent) : headers->viewer = panel_sequence_viewer; -// video_area->SetAlignment(olive::timeline::kAlignmentBottom); + video_area->SetAlignment(olive::timeline::kAlignmentBottom); tool_buttons.append(toolArrowButton); tool_buttons.append(toolEditButton); diff --git a/ui/timelinearea.cpp b/ui/timelinearea.cpp index 86d12a205..5fe9d29ff 100644 --- a/ui/timelinearea.cpp +++ b/ui/timelinearea.cpp @@ -166,6 +166,7 @@ void TimelineArea::RefreshLabels() for (int i=0;i(); labels_[i]->SetTrack(track_list_->TrackAt(i)); + labels_[i]->SetAlignment(alignment_); switch (alignment_) { case olive::timeline::kAlignmentTop: diff --git a/ui/timelinelabel.cpp b/ui/timelinelabel.cpp index 7f7cf583e..37d7fd0b8 100644 --- a/ui/timelinelabel.cpp +++ b/ui/timelinelabel.cpp @@ -5,7 +5,8 @@ #include TimelineLabel::TimelineLabel() : - track_(nullptr) + track_(nullptr), + alignment_(olive::timeline::kAlignmentTop) { QHBoxLayout* layout = new QHBoxLayout(this); layout->setMargin(0); @@ -68,12 +69,25 @@ void TimelineLabel::UpdateState() lock_button_->setChecked(track_->IsLocked()); } +void TimelineLabel::SetAlignment(olive::timeline::Alignment alignment) +{ + alignment_ = alignment; + update(); +} + void TimelineLabel::paintEvent(QPaintEvent *) { + if (alignment_ != olive::timeline::kAlignmentTop && alignment_ != olive::timeline::kAlignmentBottom) { + return; + } + QPainter p(this); p.setPen(QColor(0, 0, 0, 96)); - p.drawLine(0, height() - 1, width(), height() - 1); + + int line_y = (alignment_ == olive::timeline::kAlignmentTop) ? height() - 1 : 0; + + p.drawLine(0, line_y, width(), line_y); } void TimelineLabel::RenameTrack() diff --git a/ui/timelinelabel.h b/ui/timelinelabel.h index 56368e62c..348c59ceb 100644 --- a/ui/timelinelabel.h +++ b/ui/timelinelabel.h @@ -6,6 +6,7 @@ #include "ui/clickablelabel.h" #include "timeline/track.h" +#include "timeline/timelinefunctions.h" class TimelineLabel : public QWidget { @@ -15,6 +16,7 @@ public: void SetTrack(Track* track); void UpdateState(); + void SetAlignment(olive::timeline::Alignment alignment); protected: virtual void paintEvent(QPaintEvent *event) override; private: @@ -25,6 +27,8 @@ private: ClickableLabel* label_; Track* track_; + + olive::timeline::Alignment alignment_; private slots: void RenameTrack(); void UpdateHeight(int h); diff --git a/ui/timelineview.cpp b/ui/timelineview.cpp index 956a57b67..47b1a1d87 100644 --- a/ui/timelineview.cpp +++ b/ui/timelineview.cpp @@ -929,6 +929,18 @@ void TimelineView::VerifyTransitionsAfterCreating(ComboAction* ca, Clip* open, C } } +int TimelineView::GetTotalAreaHeight() +{ + // start by adding a track height worth of padding + int panel_height = olive::timeline::kTrackDefaultHeight; + + for (int i=0;iTrackCount();i++) { + panel_height += track_list_->TrackAt(i)->height(); + } + + return panel_height; +} + void TimelineView::mouseReleaseEvent(QMouseEvent *event) { QToolTip::hideText(); if (sequence() != nullptr) { @@ -2865,15 +2877,7 @@ void TimelineView::paintEvent(QPaintEvent*) { QPainter p(this); // get widget width and height - - // start by adding a track height worth of padding - int panel_height = olive::timeline::kTrackDefaultHeight; - - for (int i=0;iTrackCount();i++) { - panel_height += track_list_->TrackAt(i)->height(); - } - - emit setScrollMaximum(panel_height); + emit setScrollMaximum(GetTotalAreaHeight()); for (int i=0;iTrackCount();i++) { @@ -2890,7 +2894,14 @@ void TimelineView::paintEvent(QPaintEvent*) { QRect clip_rect(ParentTimeline()->getTimelineScreenPointFromFrame(clip->timeline_in()), track_top, getScreenPointFromFrame(ParentTimeline()->zoom, clip->length()), - track->height() - 1); + track->height()); + + if (alignment_ == olive::timeline::kAlignmentTop) { + clip_rect.setHeight(track->height() - 1); + } else if (alignment_ == olive::timeline::kAlignmentBottom) { + clip_rect.setTop(track_top + 1); + } + QRect text_rect(clip_rect.left() + olive::timeline::kClipTextPadding, clip_rect.top() + olive::timeline::kClipTextPadding, clip_rect.width() - olive::timeline::kClipTextPadding - 1, @@ -3206,7 +3217,11 @@ void TimelineView::paintEvent(QPaintEvent*) { // Draw track line p.setPen(QColor(0, 0, 0, 96)); - p.drawLine(0, track_bottom, rect().width(), track_bottom); + if (alignment_ == olive::timeline::kAlignmentTop) { + p.drawLine(0, track_bottom, rect().width(), track_bottom); + } else if (alignment_ == olive::timeline::kAlignmentBottom) { + p.drawLine(0, track_top, rect().width(), track_top); + } } } @@ -3315,18 +3330,16 @@ int TimelineView::getTrackIndexFromScreenPoint(int y) return 0; } + if (alignment_ == olive::timeline::kAlignmentBottom) { + y = -(y + 1 + scroll - qMax(height(), GetTotalAreaHeight())); + } else { + y += scroll; + } + if (y < 0) { return 0; } - y += scroll; - - /* - if (alignment_ == olive::timeline::kAlignmentBottom) { - y = height() - y; - } - */ - int heights = 0; int i = 0; @@ -3363,14 +3376,11 @@ int TimelineView::getScreenPointFromTrackIndex(int track) point += getTrackHeightFromTrackIndex(i) + 1; } - int screen_point = point - scroll; - - /* if (alignment_ == olive::timeline::kAlignmentBottom) { - return height() - screen_point - track_list_->First()->height(); + return qMax(height(), GetTotalAreaHeight()) - point - scroll - track_list_->First()->height() - 1; } - */ - return screen_point; + + return point - scroll; } int TimelineView::getTrackHeightFromTrackIndex(int track) diff --git a/ui/timelineview.h b/ui/timelineview.h index 364ea42ee..0cd5ca22c 100644 --- a/ui/timelineview.h +++ b/ui/timelineview.h @@ -86,6 +86,8 @@ private: void VerifyTransitionsAfterCreating(ComboAction* ca, Clip* open, Clip* close, long transition_start, long transition_end); void VerifyTransitionHelper(); + int GetTotalAreaHeight(); + Timeline* timeline_; olive::timeline::Alignment alignment_;