Sélectionner une révision Git
TimingSeparator.cc 1,61 Kio
#include "TimingSeparator.hh"
#include <QPainter>
#include <QGraphicsScene>
#include "TimingUtils.hh"
using namespace Vivy;
TimingSeparator::TimingSeparator(int time, SeparatorStyle style_, QGraphicsItem* parent)
: QGraphicsObject(parent)
, style(style_)
{
setPos(TimingUtils::posFromMs(time), 0);
switch(style){
case SeparatorStyle::Start:
pen = QPen(QColor(0, 0, 255));
break;
case SeparatorStyle::Middle:
pen = QPen(QColor(180, 0, 180));
break;
case SeparatorStyle::End:
pen = QPen(QColor(255, 0, 0));
break;
}
// Putting even-size width seems to be undefined behaviour for pixel drawing : stick to odd
pen.setWidth(1);
}
QRectF
TimingSeparator::boundingRect() const
{
return QRectF(-widthPaw, 0, 2*widthPaw, TimingUtils::audioHeight());
}
void
TimingSeparator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setPen(pen);
int height = TimingUtils::audioHeight();
int top = 1 + pen.width()/2;
int bottom = height - 1 - pen.width()/2;
painter->drawLine(0, top, 0, bottom);
switch(style){
case SeparatorStyle::Start:
painter->drawLine(0, top, widthPaw, top);
painter->drawLine(0, bottom, widthPaw, bottom);
break;
case SeparatorStyle::Middle:
painter->drawLine(-widthPaw, top, widthPaw, top);
painter->drawLine(-widthPaw, bottom, widthPaw, bottom);
break;
case SeparatorStyle::End:
painter->drawLine(-widthPaw, top, 0, top);
painter->drawLine(-widthPaw, bottom, 0, bottom);
break;
}
}