use raw time values independent of timebase for scaling timeline ui
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
set(OLIVE_SOURCES
|
||||
${OLIVE_SOURCES}
|
||||
widget/timelineview/timelineplayhead.h
|
||||
widget/timelineview/timelineplayhead.cpp
|
||||
widget/timelineview/timelineview.h
|
||||
widget/timelineview/timelineview.cpp
|
||||
widget/timelineview/timelineviewrect.h
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#include "timelineplayhead.h"
|
||||
|
||||
TimelinePlayhead::TimelinePlayhead()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QColor TimelinePlayhead::PlayheadColor()
|
||||
{
|
||||
return playhead_color_;
|
||||
}
|
||||
|
||||
QColor TimelinePlayhead::PlayheadHighlightColor()
|
||||
{
|
||||
return playhead_highlight_color_;
|
||||
}
|
||||
|
||||
void TimelinePlayhead::SetPlayheadColor(QColor c)
|
||||
{
|
||||
playhead_color_ = c;
|
||||
}
|
||||
|
||||
void TimelinePlayhead::SetPlayheadHighlightColor(QColor c)
|
||||
{
|
||||
playhead_highlight_color_ = c;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef TIMELINEPLAYHEADSTYLE_H
|
||||
#define TIMELINEPLAYHEADSTYLE_H
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class TimelinePlayhead : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QColor playheadColor READ PlayheadColor WRITE SetPlayheadColor DESIGNABLE true)
|
||||
Q_PROPERTY(QColor playheadHighlightColor READ PlayheadHighlightColor WRITE SetPlayheadHighlightColor DESIGNABLE true)
|
||||
public:
|
||||
TimelinePlayhead();
|
||||
|
||||
QColor PlayheadColor();
|
||||
QColor PlayheadHighlightColor();
|
||||
|
||||
void SetPlayheadColor(QColor c);
|
||||
void SetPlayheadHighlightColor(QColor c);
|
||||
|
||||
private:
|
||||
QColor playhead_color_;
|
||||
QColor playhead_highlight_color_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEPLAYHEADSTYLE_H
|
||||
@@ -49,7 +49,6 @@ void TimelineView::AddClip(ClipBlock *clip)
|
||||
|
||||
// Set up clip with view parameters (clip item will automatically size its rect accordingly)
|
||||
clip_item->SetClip(clip);
|
||||
clip_item->SetTimebase(timebase_);
|
||||
clip_item->SetScale(scale_);
|
||||
|
||||
// Add to list of clip items that can be iterated through
|
||||
@@ -74,10 +73,6 @@ void TimelineView::SetTimebase(const rational &timebase)
|
||||
{
|
||||
timebase_ = timebase;
|
||||
|
||||
foreach (TimelineViewClipItem* item, clip_items_) {
|
||||
item->SetTimebase(timebase_);
|
||||
}
|
||||
|
||||
playhead_line_->SetTimebase(timebase_);
|
||||
}
|
||||
|
||||
@@ -113,7 +108,7 @@ void TimelineView::mousePressEvent(QMouseEvent *event)
|
||||
|
||||
ghost->SetIn(clip->in());
|
||||
ghost->SetOut(clip->out());
|
||||
ghost->SetTimebase(timebase_);
|
||||
ghost->SetScale(scale_);
|
||||
|
||||
ghost->setPos(clip_item->pos());
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ void TimelineViewClipItem::SetClip(ClipBlock *clip)
|
||||
|
||||
void TimelineViewClipItem::UpdateRect()
|
||||
{
|
||||
if (clip_ == nullptr || !TimebaseIsValid()) {
|
||||
if (clip_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "timelineviewplayheaditem.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QGraphicsScene>
|
||||
#include <QPainter>
|
||||
#include <QtMath>
|
||||
|
||||
TimelineViewPlayheadItem::TimelineViewPlayheadItem(QGraphicsItem *parent) :
|
||||
TimelineViewRect(parent)
|
||||
TimelineViewRect(parent),
|
||||
playhead_(0)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -17,6 +19,13 @@ void TimelineViewPlayheadItem::SetPlayhead(const int64_t &playhead)
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewPlayheadItem::SetTimebase(const rational &timebase)
|
||||
{
|
||||
timebase_ = timebase;
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewPlayheadItem::UpdateRect()
|
||||
{
|
||||
double x = TimeToScreenCoord(rational(playhead_ * timebase_.numerator(), timebase_.denominator()));
|
||||
@@ -33,10 +42,10 @@ void TimelineViewPlayheadItem::paint(QPainter *painter, const QStyleOptionGraphi
|
||||
|
||||
// FIXME: Make adjustable through CSS
|
||||
painter->setPen(Qt::NoPen);
|
||||
painter->setBrush(QColor(255, 255, 255, 128));
|
||||
painter->setBrush(style_.PlayheadHighlightColor());
|
||||
painter->drawRect(rect());
|
||||
|
||||
painter->setPen(Qt::red);
|
||||
painter->setPen(style_.PlayheadColor());
|
||||
painter->setBrush(Qt::NoBrush);
|
||||
painter->drawLine(QLineF(rect().topLeft(), rect().bottomLeft()));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef TIMELINEVIEWPLAYHEADITEM_H
|
||||
#define TIMELINEVIEWPLAYHEADITEM_H
|
||||
|
||||
#include "timelineplayhead.h"
|
||||
#include "timelineviewrect.h"
|
||||
|
||||
class TimelineViewPlayheadItem : public TimelineViewRect
|
||||
@@ -10,6 +11,8 @@ public:
|
||||
|
||||
void SetPlayhead(const int64_t& playhead);
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
protected:
|
||||
virtual void UpdateRect() override;
|
||||
|
||||
@@ -17,6 +20,10 @@ protected:
|
||||
|
||||
private:
|
||||
int64_t playhead_;
|
||||
|
||||
rational timebase_;
|
||||
|
||||
TimelinePlayhead style_;
|
||||
};
|
||||
|
||||
#endif // TIMELINEVIEWPLAYHEADITEM_H
|
||||
|
||||
@@ -7,26 +7,14 @@ TimelineViewRect::TimelineViewRect(QGraphicsItem* parent) :
|
||||
|
||||
}
|
||||
|
||||
void TimelineViewRect::SetTimebase(const rational &timebase)
|
||||
{
|
||||
timebase_ = timebase;
|
||||
timebase_dbl_ = timebase_.toDouble();
|
||||
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
void TimelineViewRect::SetScale(const double &scale)
|
||||
{
|
||||
scale_ = scale;
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
bool TimelineViewRect::TimebaseIsValid()
|
||||
{
|
||||
return timebase_.denominator() != 0;
|
||||
UpdateRect();
|
||||
}
|
||||
|
||||
double TimelineViewRect::TimeToScreenCoord(const rational &time)
|
||||
{
|
||||
return time.toDouble() / timebase_dbl_ * scale_;
|
||||
return time.toDouble() * scale_;
|
||||
}
|
||||
|
||||
@@ -10,21 +10,13 @@ class TimelineViewRect : public QGraphicsRectItem
|
||||
public:
|
||||
TimelineViewRect(QGraphicsItem* parent = nullptr);
|
||||
|
||||
void SetTimebase(const rational& timebase);
|
||||
|
||||
void SetScale(const double& scale);
|
||||
|
||||
protected:
|
||||
virtual void UpdateRect() = 0;
|
||||
|
||||
bool TimebaseIsValid();
|
||||
|
||||
double TimeToScreenCoord(const rational& time);
|
||||
|
||||
rational timebase_;
|
||||
|
||||
double timebase_dbl_;
|
||||
|
||||
double scale_;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user