Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render duration of intro & outro ranges on overview waveforms #2089

Merged
merged 8 commits into from
May 5, 2019
Prev Previous commit
Next Next commit
draw cue markers on top of ranges on overview
This was changed in 5161968 so the cue markers did not get drawn
over range duration text, but that concern was obviated by
0ab6a46
Be-ing committed May 5, 2019
commit 9f183c82f565485ee87b0643a346ff0d0f6922b4
136 changes: 68 additions & 68 deletions src/widget/woverview.cpp
Original file line number Diff line number Diff line change
@@ -456,6 +456,74 @@ void WOverview::paintEvent(QPaintEvent * /*unused*/) {

painter.setOpacity(0.9);

// Draw range (loop)
for (auto&& markRange: m_markRanges) {
if (!markRange.active() || !markRange.visible()) {
continue;
}

// Active mark ranges by definition have starts/ends that are not
// disabled.
const double startValue = markRange.start();
const double endValue = markRange.end();

const float startPosition = offset + startValue * gain;
const float endPosition = offset + endValue * gain;

if (startPosition < 0.0 && endPosition < 0.0) {
continue;
}

if (markRange.enabled()) {
painter.setOpacity(0.4);
painter.setPen(markRange.m_activeColor);
painter.setBrush(markRange.m_activeColor);
} else {
painter.setOpacity(0.2);
painter.setPen(markRange.m_disabledColor);
painter.setBrush(markRange.m_disabledColor);
}

// let top and bottom of the rect out of the widget
if (m_orientation == Qt::Horizontal) {
painter.drawRect(QRectF(QPointF(startPosition, -2.0),
QPointF(endPosition, height() + 1.0)));
} else {
painter.drawRect(QRectF(QPointF(-2.0, startPosition),
QPointF(width() + 1.0, endPosition)));
}

// draw duration of range
if (markRange.showDuration()) {
// TODO: replace with rate_ratio in PR #1765
double rateRatio = 1.0 + m_pRateDirControl->get() * m_pRateRangeControl->get() * m_pRateSliderControl->get();
QString duration = mixxx::Duration::formatTime((endValue - startValue)
/ m_trackSampleRateControl->get() / 2 / rateRatio);

QFontMetrics fm(painter.font());
int textWidth = fm.width(duration);
float padding = 3.0;
float x;

WaveformMarkRange::DurationTextLocation textLocation = markRange.durationTextLocation();
if (textLocation == WaveformMarkRange::DurationTextLocation::Before) {
x = startPosition - textWidth - padding;
} else {
x = endPosition + padding;
}

// Ensure the right end of the text does not get cut off by
// the end of the track
if (x + textWidth > width()) {
x = width() - textWidth;
}

painter.setOpacity(1.0);
painter.setPen(markRange.m_durationTextColor);
painter.drawText(QPointF(x, fm.ascent()), duration);
}
}

for (const auto& currentMark: m_marks) {
const WaveformMarkProperties& markProperties = currentMark->getProperties();
if (currentMark->isValid() && currentMark->getSamplePosition() >= 0.0) {
@@ -533,74 +601,6 @@ void WOverview::paintEvent(QPaintEvent * /*unused*/) {
}
}

// Draw range (loop)
for (auto&& markRange: m_markRanges) {
if (!markRange.active() || !markRange.visible()) {
continue;
}

// Active mark ranges by definition have starts/ends that are not
// disabled.
const double startValue = markRange.start();
const double endValue = markRange.end();

const float startPosition = offset + startValue * gain;
const float endPosition = offset + endValue * gain;

if (startPosition < 0.0 && endPosition < 0.0) {
continue;
}

if (markRange.enabled()) {
painter.setOpacity(0.4);
painter.setPen(markRange.m_activeColor);
painter.setBrush(markRange.m_activeColor);
} else {
painter.setOpacity(0.2);
painter.setPen(markRange.m_disabledColor);
painter.setBrush(markRange.m_disabledColor);
}

// let top and bottom of the rect out of the widget
if (m_orientation == Qt::Horizontal) {
painter.drawRect(QRectF(QPointF(startPosition, -2.0),
QPointF(endPosition, height() + 1.0)));
} else {
painter.drawRect(QRectF(QPointF(-2.0, startPosition),
QPointF(width() + 1.0, endPosition)));
}

// draw duration of range
if (markRange.showDuration()) {
// TODO: replace with rate_ratio in PR #1765
double rateRatio = 1.0 + m_pRateDirControl->get() * m_pRateRangeControl->get() * m_pRateSliderControl->get();
QString duration = mixxx::Duration::formatTime((endValue - startValue)
/ m_trackSampleRateControl->get() / 2 / rateRatio);

QFontMetrics fm(painter.font());
int textWidth = fm.width(duration);
float padding = 3.0;
float x;

WaveformMarkRange::DurationTextLocation textLocation = markRange.durationTextLocation();
if (textLocation == WaveformMarkRange::DurationTextLocation::Before) {
x = startPosition - textWidth - padding;
} else {
x = endPosition + padding;
}

// Ensure the right end of the text does not get cut off by
// the end of the track
if (x + textWidth > width()) {
x = width() - textWidth;
}

painter.setOpacity(1.0);
painter.setPen(markRange.m_durationTextColor);
painter.drawText(QPointF(x, fm.ascent()), duration);
}
}

if (m_orientation == Qt::Vertical) {
painter.setTransform(QTransform(0, 1, 1, 0, 0, 0));
}