Sélectionner une révision Git
-
Loïc DUBARD a rédigéLoïc DUBARD a rédigé
TimingSeparator.cc 2,96 Kio
#include "TimingSeparator.hh"
#include <QPainter>
#include <QGraphicsScene>
#include <QDrag>
#include "TimingUtils.hh"
#include "TimingLine.hh"
using namespace Vivy;
TimingSeparator::TimingSeparator(int time, int index, SeparatorStyle style_, TimingLine *parent)
: QGraphicsObject(parent)
, style(style_)
, sepIndex(index)
, parentTimingLine(parent)
{
setPos(TimingUtils::posFromMs(time), 0);
setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsGeometryChanges);
setAcceptHoverEvents(true);
setCursor(Qt::PointingHandCursor);
switch (style) {
case SeparatorStyle::Start:
pen = QPen(QColor(0, 0, 255));
setZValue(Z_SEPARATOR_START_END);
break;
case SeparatorStyle::Middle:
pen = QPen(QColor(180, 0, 180));
setZValue(Z_SEPARATOR_MIDDLE);
break;
case SeparatorStyle::End:
pen = QPen(QColor(255, 0, 0));
setZValue(Z_SEPARATOR_START_END);
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;
}
}
void
TimingSeparator::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
emit enterPress(sepIndex);
QGraphicsObject::mousePressEvent(event);
}
void
TimingSeparator::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
emit exitPress(sepIndex);
QGraphicsObject::mouseReleaseEvent(event);
}
void
TimingSeparator::silentlySetPos(int x, int y)
{
inhibMove = true;
setPos(x, y);
inhibMove = false;
}
void
TimingSeparator::silentlyMoveBy(int x, int y)
{
inhibMove = true;
moveBy(x, y);
inhibMove = false;
}
QVariant
TimingSeparator::itemChange(GraphicsItemChange change, const QVariant &value) noexcept
{
if (change == ItemPositionChange && !inhibMove) {
qreal destination = value.toPointF().x();
destination = parentTimingLine->requestMove(sepIndex, destination);
emit positionChanged(sepIndex, destination);
return QPointF(destination, 0);
}
return QGraphicsObject::itemChange(change, value);
}