Files
oak-editor/app/widget/timelineview/timelineviewplayheaditem.cpp
T

52 lines
1.2 KiB
C++

#include "timelineviewplayheaditem.h"
#include <QDebug>
#include <QGraphicsScene>
#include <QPainter>
#include <QtMath>
TimelineViewPlayheadItem::TimelineViewPlayheadItem(QGraphicsItem *parent) :
TimelineViewRect(parent),
playhead_(0)
{
}
void TimelineViewPlayheadItem::SetPlayhead(const int64_t &playhead)
{
playhead_ = playhead;
UpdateRect();
}
void TimelineViewPlayheadItem::SetTimebase(const rational &timebase)
{
timebase_ = timebase;
UpdateRect();
}
void TimelineViewPlayheadItem::UpdateRect()
{
double x = TimeToScreenCoord(rational(playhead_ * timebase_.numerator(), timebase_.denominator()));
double width = TimeToScreenCoord(timebase_);
setRect(0, 0, width, scene()->height());
setPos(x, 0);
}
void TimelineViewPlayheadItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
Q_UNUSED(option)
Q_UNUSED(widget)
// FIXME: Make adjustable through CSS
painter->setPen(Qt::NoPen);
painter->setBrush(style_.PlayheadHighlightColor());
painter->drawRect(rect());
painter->setPen(style_.PlayheadColor());
painter->setBrush(Qt::NoBrush);
painter->drawLine(QLineF(rect().topLeft(), rect().bottomLeft()));
}