labels scroll with the timeline views

This commit is contained in:
itsmattkc
2019-04-06 19:14:45 +11:00
parent 2674d284e2
commit 8199601048
7 changed files with 456 additions and 388 deletions
+118 -8
View File
@@ -1,5 +1,10 @@
#include "timelinearea.h"
#include <QScrollArea>
#include "panels/timeline.h"
#include "global/config.h"
int olive::timeline::kTimelineLabelFixedWidth = 200;
TimelineArea::TimelineArea(Timeline* timeline, olive::timeline::Alignment alignment) :
@@ -12,13 +17,22 @@ TimelineArea::TimelineArea(Timeline* timeline, olive::timeline::Alignment alignm
layout->setSpacing(0);
// LABELS
QWidget* label_container = new QWidget();
label_container->setFixedWidth(olive::timeline::kTimelineLabelFixedWidth);
label_container_layout_ = new QVBoxLayout(label_container);
label_container_ = new QWidget();
label_container_layout_ = new QVBoxLayout(label_container_);
label_container_layout_->setMargin(0);
label_container_layout_->setSpacing(0);
label_container_layout_->addStretch();
layout->addWidget(label_container);
// LABEL SCROLLAREA
QScrollArea* label_area = new QScrollArea();
label_area->setFrameShape(QFrame::NoFrame);
label_area->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
label_area->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
label_area->verticalScrollBar()->setMaximum(INT_MAX);
label_area->setWidgetResizable(true);
label_area->setFixedWidth(olive::timeline::kTimelineLabelFixedWidth);
label_area->setWidget(label_container_);
layout->addWidget(label_area);
// VIEW
view_ = new TimelineView(timeline_);
@@ -26,10 +40,13 @@ TimelineArea::TimelineArea(Timeline* timeline, olive::timeline::Alignment alignm
layout->addWidget(view_);
// SCROLLBAR
QScrollBar* scrollbar = new QScrollBar(Qt::Vertical);
layout->addWidget(scrollbar);
scrollbar_ = new QScrollBar(Qt::Vertical);
layout->addWidget(scrollbar_);
view_->scrollBar = scrollbar;
connect(scrollbar_, SIGNAL(valueChanged(int)), view_, SLOT(setScroll(int)));
connect(scrollbar_, SIGNAL(valueChanged(int)), label_area->verticalScrollBar(), SLOT(setValue(int)));
connect(view_, SIGNAL(setScrollMaximum(int)), this, SLOT(setScrollMaximum(int)));
connect(view_, SIGNAL(requestScrollChange(int)), scrollbar_, SLOT(setValue(int)));
}
void TimelineArea::SetTrackList(Sequence *sequence, Track::Type track_list)
@@ -55,6 +72,78 @@ void TimelineArea::SetTrackList(Sequence *sequence, Track::Type track_list)
}
void TimelineArea::SetAlignment(olive::timeline::Alignment alignment)
{
view_->SetAlignment(alignment);
alignment_ = alignment;
RefreshLabels();
}
void TimelineArea::wheelEvent(QWheelEvent *event)
{
// TODO: implement pixel scrolling
bool shift = (event->modifiers() & Qt::ShiftModifier);
bool ctrl = (event->modifiers() & Qt::ControlModifier);
bool alt = (event->modifiers() & Qt::AltModifier);
// "Scroll Zooms" false + Control up : not zooming
// "Scroll Zooms" false + Control down: zooming
// "Scroll Zooms" true + Control up : zooming
// "Scroll Zooms" true + Control down: not zooming
bool zooming = (olive::config.scroll_zooms != ctrl);
// Allow shift for axis swap, but don't swap on zoom... Unless
// we need to override Qt's axis swap via Alt
bool swap_hv = ((shift != olive::config.invert_timeline_scroll_axes) &
!zooming) | (alt & !shift & zooming);
int delta_h = swap_hv ? event->angleDelta().y() : event->angleDelta().x();
int delta_v = swap_hv ? event->angleDelta().x() : event->angleDelta().y();
if (zooming) {
// Zoom only uses vertical scrolling, to avoid glitches on touchpads.
// Don't do anything if not scrolling vertically.
if (delta_v != 0) {
// delta_v == 120 for one click of a mousewheel. Less or more for a
// touchpad gesture. Calculate speed to compensate.
// 120 = ratio of 4/3 (1.33), -120 = ratio of 3/4 (.75)
double zoom_ratio = 1.0 + (abs(delta_v) * 0.33 / 120);
if (delta_v < 0) {
zoom_ratio = 1.0 / zoom_ratio;
}
timeline_->multiply_zoom(zoom_ratio);
}
} else {
// Use the Timeline's main scrollbar for horizontal scrolling, and this
// widget's scrollbar for vertical scrolling.
QScrollBar* bar_v = scrollbar_;
QScrollBar* bar_h = timeline_->horizontalScrollBar;
// Match the wheel events to the size of a step as per
// https://doc.qt.io/qt-5/qwheelevent.html#angleDelta
int step_h = bar_h->singleStep() * delta_h / -120;
int step_v = bar_v->singleStep() * delta_v / -120;
// Apply to appropriate scrollbars
bar_h->setValue(bar_h->value() + step_h);
bar_v->setValue(bar_v->value() + step_v);
}
}
void TimelineArea::RefreshLabels()
{
if (track_list_ == nullptr) {
@@ -68,8 +157,29 @@ void TimelineArea::RefreshLabels()
labels_[i] = std::make_shared<TimelineLabel>();
labels_[i]->SetTrack(track_list_->TrackAt(i));
label_container_layout_->insertWidget(label_container_layout_->count()-1, labels_[i].get());
switch (alignment_) {
case olive::timeline::kAlignmentTop:
label_container_layout_->insertWidget(label_container_layout_->count()-1, labels_[i].get());
break;
case olive::timeline::kAlignmentBottom:
label_container_layout_->insertWidget(1, labels_[i].get());
break;
case olive::timeline::kAlignmentSingle:
break;
}
}
}
}
void TimelineArea::resizeEvent(QResizeEvent *)
{
scrollbar_->setPageStep(view_->height());
}
void TimelineArea::setScrollMaximum(int maximum)
{
scrollbar_->setMaximum(qMax(0, maximum - view_->height()));
label_container_->setMinimumHeight(maximum);
// label_container_->setFixedHeight(maximum);
}