timeline: separate markers and workarea

This commit is contained in:
itsmattkc
2022-06-27 23:39:31 -07:00
parent 63f74691a5
commit 079d6beff2
34 changed files with 324 additions and 338 deletions
@@ -31,36 +31,51 @@ namespace olive {
ResizableTimelineScrollBar::ResizableTimelineScrollBar(QWidget* parent) :
ResizableScrollBar(parent),
points_(nullptr),
markers_(nullptr),
workarea_(nullptr),
scale_(1.0)
{
}
ResizableTimelineScrollBar::ResizableTimelineScrollBar(Qt::Orientation orientation, QWidget* parent) :
ResizableScrollBar(orientation, parent),
points_(nullptr),
markers_(nullptr),
workarea_(nullptr),
scale_(1.0)
{
}
void ResizableTimelineScrollBar::ConnectTimelinePoints(TimelinePoints *points)
void ResizableTimelineScrollBar::ConnectMarkers(TimelineMarkerList *markers)
{
if (points_) {
disconnect(points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(points_->markers(), &TimelineMarkerList::MarkerModified, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
if (markers_) {
disconnect(markers_, &TimelineMarkerList::MarkerAdded, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(markers_, &TimelineMarkerList::MarkerRemoved, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(markers_, &TimelineMarkerList::MarkerModified, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
}
points_ = points;
markers_ = markers;
if (points_) {
connect(points_->workarea(), &TimelineWorkArea::RangeChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(points_->workarea(), &TimelineWorkArea::EnabledChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(points_->markers(), &TimelineMarkerList::MarkerAdded, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(points_->markers(), &TimelineMarkerList::MarkerRemoved, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(points_->markers(), &TimelineMarkerList::MarkerModified, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
if (markers_) {
connect(markers_, &TimelineMarkerList::MarkerAdded, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(markers_, &TimelineMarkerList::MarkerRemoved, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(markers_, &TimelineMarkerList::MarkerModified, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
}
update();
}
void ResizableTimelineScrollBar::ConnectWorkArea(TimelineWorkArea *workarea)
{
if (workarea_) {
disconnect(workarea_, &TimelineWorkArea::RangeChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
disconnect(workarea_, &TimelineWorkArea::EnabledChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
}
workarea_ = workarea;
if (workarea_) {
connect(workarea_, &TimelineWorkArea::RangeChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
connect(workarea_, &TimelineWorkArea::EnabledChanged, this, static_cast<void (ResizableTimelineScrollBar::*)()>(&ResizableTimelineScrollBar::update));
}
update();
@@ -77,9 +92,8 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event)
{
ResizableScrollBar::paintEvent(event);
if (points_
&& !timebase().isNull()
&& (points_->workarea()->enabled() || !points_->markers()->empty())) {
if (!timebase().isNull() && ((workarea_ && workarea_->enabled()) || (markers_ && !markers_->empty()))) {
// Draw workarea
QStyleOptionSlider opt;
initStyleOption(&opt);
@@ -87,20 +101,20 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event)
QStyle::SC_ScrollBarGroove, this);
double ratio = scale_ * double(gr.width()) / double(this->maximum() + gr.width());
QPainter p(this);
if (points_->workarea()->enabled()) {
if (workarea_ && workarea_->enabled()) {
QColor workarea_color(this->palette().highlight().color());
workarea_color.setAlpha(128);
qint64 in = qMax(qint64(0), qRound64(ratio * TimeToScene(points_->workarea()->in())));
qint64 in = qMax(qint64(0), qRound64(ratio * TimeToScene(workarea_->in())));
qint64 out;
if (points_->workarea()->out() == RATIONAL_MAX) {
if (workarea_->out() == RATIONAL_MAX) {
out = gr.width();
} else {
out = qMin(qint64(gr.width()), qRound64(ratio * TimeToScene(points_->workarea()->out())));
out = qMin(qint64(gr.width()), qRound64(ratio * TimeToScene(workarea_->out())));
}
qint64 length = qMax(qint64(1), out-in);
@@ -112,8 +126,9 @@ void ResizableTimelineScrollBar::paintEvent(QPaintEvent *event)
workarea_color);
}
if (!points_->markers()->empty()) {
for (auto it=points_->markers()->cbegin(); it!=points_->markers()->cend(); it++) {
// Draw markers
if (markers_ && !markers_->empty()) {
for (auto it=markers_->cbegin(); it!=markers_->cend(); it++) {
TimelineMarker* marker = *it;
QColor marker_color = ColorCoding::GetColor(marker->color()).toQColor();