Skip to content

Commit

Permalink
move intro/outro duration text outside of range on overviews
Browse files Browse the repository at this point in the history
This avoids the text overlapping the borders of the range, which
looks ugly.
  • Loading branch information
Be-ing committed May 5, 2019
1 parent 5161968 commit 0ab6a46
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
2 changes: 2 additions & 0 deletions res/skins/Deere/deck_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>after</DurationTextLocation>
</MarkRange>
<MarkRange>
<StartControl>outro_start_position</StartControl>
<EndControl>outro_end_position</EndControl>
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>before</DurationTextLocation>
</MarkRange>
<Mark>
<Control>intro_start_position</Control>
Expand Down
2 changes: 2 additions & 0 deletions res/skins/LateNight/deck_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>after</DurationTextLocation>
</MarkRange>
<MarkRange>
<StartControl>outro_start_position</StartControl>
<EndControl>outro_end_position</EndControl>
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>before</DurationTextLocation>
</MarkRange>
<Mark>
<Control>intro_start_position</Control>
Expand Down
2 changes: 2 additions & 0 deletions res/skins/Shade/deck_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>after</DurationTextLocation>
</MarkRange>
<MarkRange>
<StartControl>outro_start_position</StartControl>
<EndControl>outro_end_position</EndControl>
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>before</DurationTextLocation>
</MarkRange>
<Mark>
<Control>intro_start_position</Control>
Expand Down
2 changes: 2 additions & 0 deletions res/skins/Tango/deck_overview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ Variables:
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>after</DurationTextLocation>
</MarkRange>
<MarkRange>
<StartControl>outro_start_position</StartControl>
<EndControl>outro_end_position</EndControl>
<Color>#0000FF</Color>
<VisibilityControl>[Skin],show_intro_outro_cues</VisibilityControl>
<DurationTextColor>#ffffff</DurationTextColor>
<DurationTextLocation>before</DurationTextLocation>
</MarkRange>
<Mark>
<Control>intro_start_position</Control>
Expand Down
7 changes: 7 additions & 0 deletions src/waveform/renderers/waveformmarkrange.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ WaveformMarkRange::WaveformMarkRange(
ConfigKey key = ConfigKey::parseCommaSeparated(visibilityControl);
m_markVisibleControl = std::make_unique<ControlProxy>(key);
}

QString durationTextLocation = context.selectString(node, "DurationTextLocation");
if (durationTextLocation == "before") {
m_durationTextLocation = DurationTextLocation::Before;
} else {
m_durationTextLocation = DurationTextLocation::After;
}
}

bool WaveformMarkRange::active() const {
Expand Down
11 changes: 11 additions & 0 deletions src/waveform/renderers/waveformmarkrange.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ class WaveformMarkRange {

bool showDuration() const;

enum class DurationTextLocation {
Before = 0,
After = 1
};

DurationTextLocation durationTextLocation() const {
return m_durationTextLocation;
}

private:
void generateImage(int weidth, int height);

Expand All @@ -53,6 +62,8 @@ class WaveformMarkRange {
QImage m_activeImage;
QImage m_disabledImage;

DurationTextLocation m_durationTextLocation;

friend class WaveformRenderMarkRange;
friend class WOverview;
};
19 changes: 14 additions & 5 deletions src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,18 +577,27 @@ void WOverview::paintEvent(QPaintEvent * /*unused*/) {
QString duration = mixxx::Duration::formatTime((endValue - startValue)
/ m_trackSampleRateControl->get() / 2 / rateRatio);

// Ensure the right end of the text does not get cut off by
// the end of the track
QFontMetrics fm(painter.font());
int textWidth = fm.width(duration);
float x = startPosition;
if (startPosition + textWidth > width()) {
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, height() - 2.0), duration);
painter.drawText(QPointF(x, fm.ascent()), duration);
}
}

Expand Down

0 comments on commit 0ab6a46

Please sign in to comment.