Skip to content

Commit

Permalink
Timeline: fix drawing of duration rectangle
Browse files Browse the repository at this point in the history
Should fix issues reported in #94.
  • Loading branch information
rodlie committed Nov 12, 2023
1 parent 86da5e0 commit 0b1e0b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
12 changes: 8 additions & 4 deletions src/core/Timeline/animationrect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,19 @@ void AnimationRect::draw(QPainter * const p,
const QRect& drawRect,
const qreal fps,
const qreal pixelsPerFrame,
const FrameRange &absFrameRange) {
const FrameRange &absFrameRange)
{
const int clampedMin = qMax(absFrameRange.fMin, getMinAnimAbsFrame());
const int firstRelDrawFrame = clampedMin - absFrameRange.fMin;
const int clampedMax = qMin(absFrameRange.fMax, getMaxAnimAbsFrame());
const int lastRelDrawFrame = clampedMax - absFrameRange.fMin;
const int drawFrameSpan = lastRelDrawFrame - firstRelDrawFrame + 1;
if(drawFrameSpan > 0) {
QRect animDurRect(qFloor(firstRelDrawFrame*pixelsPerFrame), drawRect.y(),
qCeil(drawFrameSpan*pixelsPerFrame), drawRect.height());

if (drawFrameSpan > 0) {
QRect animDurRect(qFloor((firstRelDrawFrame + 0.5) * pixelsPerFrame),
drawRect.y(),
qCeil((drawFrameSpan - 1.0) * pixelsPerFrame),
drawRect.height());

const auto& sett = eSettings::instance();
p->fillRect(animDurRect.adjusted(0, 1, 0, -1), sett.fAnimationRangeColor);
Expand Down
49 changes: 28 additions & 21 deletions src/core/Timeline/durationrectangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,24 @@ void DurationRectangle::draw(QPainter * const p,
const QRect& drawRect,
const qreal fps,
const qreal pixelsPerFrame,
const FrameRange &absFrameRange) {
const FrameRange &absFrameRange)
{
const int clampedMin = qMax(absFrameRange.fMin, getMinAbsFrame());
const int firstRelDrawFrame = clampedMin - absFrameRange.fMin;
const int clampedMax = qMin(absFrameRange.fMax, getMaxAbsFrame());
const int lastRelDrawFrame = clampedMax - absFrameRange.fMin;
const int drawFrameSpan = lastRelDrawFrame - firstRelDrawFrame + 1;

if(drawFrameSpan < 1) return;
if (drawFrameSpan < 1) { return; }

const QRect durRect(qFloor(firstRelDrawFrame*pixelsPerFrame), drawRect.y(),
qCeil(drawFrameSpan*pixelsPerFrame), drawRect.height());
const QRect durRect(qFloor((firstRelDrawFrame + 0.5) * pixelsPerFrame),
drawRect.y(),
qCeil((drawFrameSpan - 1.0) * pixelsPerFrame),
drawRect.height());

const int rectStartFrame = absFrameRange.fMin - mValue;
// why are we drawing cache handlers here?
Q_UNUSED(fps)
/*const int rectStartFrame = absFrameRange.fMin - mValue;
const int rectEndFrame = absFrameRange.fMax - mValue;
if(mRasterCacheHandler && mSoundCacheHandler) {
const int soundHeight = drawRect.height()/3;
Expand Down Expand Up @@ -234,39 +239,41 @@ void DurationRectangle::draw(QPainter * const p,
rectStartFrame,
rectEndFrame, fps,
durRect.right());
}
}*/

QColor fillColor;
const auto& sett = eSettings::instance();
if(isSelected()) fillColor = sett.fSelectedVisibilityRangeColor;
else fillColor = sett.fVisibilityRangeColor;
if (isSelected()) { fillColor = sett.fSelectedVisibilityRangeColor; }
else { fillColor = sett.fVisibilityRangeColor; }

p->fillRect(durRect.adjusted(0, 1, 0, -1), fillColor);
if(mHovered) {
if (mHovered) {
p->setPen(QPen(Qt::white, .5));
p->drawRect(durRect);
}

if(mMinFrame.isHovered()) p->setPen(QPen(Qt::white));
else p->setPen(QPen(Qt::black));
if (mMinFrame.isHovered()) { p->setPen(QPen(Qt::white)); }
else { p->setPen(QPen(Qt::black)); }
p->drawLine(durRect.topLeft(), durRect.bottomLeft());
if(mMaxFrame.isHovered()) p->setPen(QPen(Qt::white));
else p->setPen(QPen(Qt::black));

if (mMaxFrame.isHovered()) { p->setPen(QPen(Qt::white)); }
else { p->setPen(QPen(Qt::black)); }
p->drawLine(durRect.topRight(), durRect.bottomRight());

// p->setPen(Qt::black);
// p->setBrush(Qt::NoBrush);
//p->drawRect(drawRect);
}

TimelineMovable *DurationRectangle::getMovableAt(
const int pressX, const qreal pixelsPerFrame,
const int minViewedFrame) {
const qreal startX = (getMinAbsFrame() - minViewedFrame)*pixelsPerFrame;
const qreal endX = (getMaxAbsFrame() - minViewedFrame + 1)*pixelsPerFrame;
if(qAbs(pressX - startX) < 5) return &mMinFrame;
else if(qAbs(pressX - endX) < 5) return &mMaxFrame;
else if(pressX > startX && pressX < endX) return this;
TimelineMovable *DurationRectangle::getMovableAt(const int pressX,
const qreal pixelsPerFrame,
const int minViewedFrame)
{
const qreal startX = ((getMinAbsFrame() - minViewedFrame) + 0.5) * pixelsPerFrame;
const qreal endX = ((getMaxAbsFrame() - minViewedFrame + 1) - 0.5) * pixelsPerFrame;
if (qAbs(pressX - startX) < 5) { return &mMinFrame; }
else if (qAbs(pressX - endX) < 5) { return &mMaxFrame; }
else if (pressX > startX && pressX < endX) { return this; }
return nullptr;
}

Expand Down

0 comments on commit 0b1e0b8

Please sign in to comment.