Skip to content

Commit

Permalink
WOverView/WVisual: allow custom dim/bright treshold for marks
Browse files Browse the repository at this point in the history
  • Loading branch information
ronso0 committed Sep 23, 2020
1 parent 8f0962e commit 53c2bc6
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 13 deletions.
7 changes: 5 additions & 2 deletions src/util/color/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ int brightness(int red, int green, int blue) {

// If the baseColor is darker than the global threshold,
// returns a lighter color, otherwise returns a darker color.
QColor chooseContrastColor(QColor baseColor) {
QColor chooseContrastColor(QColor baseColor, int dimBrightThreshold) {
// Will produce a color that is 60% brighter.
static const int iLighterFactor = 160;
// We consider a hsv color dark if its value is <= 20% of max value
Expand All @@ -44,7 +44,10 @@ QColor chooseContrastColor(QColor baseColor) {
// not a good indicator of a color brightness (saturation comes into play too).
// That's why we call chooseColorByBrightness so the proper brightness of the color is used
// to choose between the light and the dark colors.
QColor contrastColor = chooseColorByBrightness(baseColor, lightColor.toRgb(), darkColor.toRgb());
QColor contrastColor = chooseColorByBrightness(baseColor,
lightColor.toRgb(),
darkColor.toRgb(),
dimBrightThreshold);
return contrastColor;
}

Expand Down
12 changes: 8 additions & 4 deletions src/waveform/renderers/waveformmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ WaveformMark::WaveformMark(const QString& group,
} else {
color = WSkinColor::getCorrectColor(color);
}
setBaseColor(color);
int dimBrightThreshold = signalColors.getDimBrightThreshold();
setBaseColor(color, dimBrightThreshold);

m_textColor = context.selectString(node, "TextColor");
if (!m_textColor.isValid()) {
Expand All @@ -103,11 +104,14 @@ WaveformMark::WaveformMark(const QString& group,
}
}

void WaveformMark::setBaseColor(QColor baseColor) {
void WaveformMark::setBaseColor(QColor baseColor, int dimBrightThreshold) {
m_image = QImage();
m_fillColor = baseColor;
m_borderColor = Color::chooseContrastColor(baseColor);
m_labelColor = Color::chooseColorByBrightness(baseColor, QColor(255,255,255,255), QColor(0,0,0,255));
m_borderColor = Color::chooseContrastColor(baseColor, dimBrightThreshold);
m_labelColor = Color::chooseColorByBrightness(baseColor,
QColor(255, 255, 255, 255),
QColor(0, 0, 0, 255),
dimBrightThreshold);
};

bool WaveformMark::contains(QPoint point, Qt::Orientation orientation) const {
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/renderers/waveformmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class WaveformMark {
}

// Sets the appropriate mark colors based on the base color
void setBaseColor(QColor baseColor);
void setBaseColor(QColor baseColor, int dimBrightThreshold);
QColor fillColor() const {
return m_fillColor;
}
Expand Down
3 changes: 2 additions & 1 deletion src/waveform/renderers/waveformrendermark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ void WaveformRenderMark::slotCuesUpdated() {
!pMark->fillColor().isValid() ||
newColor != pMark->fillColor()) {
pMark->m_text = newLabel;
pMark->setBaseColor(newColor);
int dimBrightThreshold = m_waveformRenderer->getDimBrightThreshold();
pMark->setBaseColor(newColor, dimBrightThreshold);
generateMarkImage(pMark);
}
}
Expand Down
13 changes: 12 additions & 1 deletion src/waveform/renderers/waveformsignalcolors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
#include "widget/wskincolor.h"
#include "widget/wwidget.h"

WaveformSignalColors::WaveformSignalColors() {
namespace {
constexpr int kDefaultDimBrightThreshold = 127;
}

WaveformSignalColors::WaveformSignalColors()
: m_dimBrightThreshold(kDefaultDimBrightThreshold) {
}

bool WaveformSignalColors::setup(const QDomNode &node, const SkinContext& context) {
Expand Down Expand Up @@ -76,6 +81,12 @@ bool WaveformSignalColors::setup(const QDomNode &node, const SkinContext& contex
}
m_bgColor = WSkinColor::getCorrectColor(m_bgColor).toRgb();

bool okay;
m_dimBrightThreshold = context.selectInt(node, QStringLiteral("DimBrightThreshold"), &okay);
if (!okay) {
m_dimBrightThreshold = kDefaultDimBrightThreshold;
}

bool filteredColorValid = m_lowColor.isValid() && m_midColor.isValid() && m_highColor.isValid();

if (m_signalColor.isValid() && filteredColorValid) {
Expand Down
2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformsignalcolors.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class WaveformSignalColors {
inline const QColor& getPlayedOverlayColor() const { return m_playedOverlayColor; }
inline const QColor& getPassthroughOverlayColor() const { return m_passthroughOverlayColor; }
inline const QColor& getBgColor() const { return m_bgColor; }
inline int getDimBrightThreshold() const { return m_dimBrightThreshold; }

protected:
void fallBackFromSignalColor();
Expand All @@ -45,6 +46,7 @@ class WaveformSignalColors {
QColor m_playedOverlayColor;
QColor m_passthroughOverlayColor;
QColor m_bgColor;
int m_dimBrightThreshold;
};

#endif // WAVEFORMSIGNALCOLORS_H
11 changes: 11 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ const double WaveformWidgetRenderer::s_waveformMaxZoom = 10.0;
const double WaveformWidgetRenderer::s_waveformDefaultZoom = 3.0;
const double WaveformWidgetRenderer::s_defaultPlayMarkerPosition = 0.5;

namespace {
constexpr int kDefaultDimBrightThreshold = 127;
}

WaveformWidgetRenderer::WaveformWidgetRenderer(const QString& group)
: m_group(group),
m_orientation(Qt::Horizontal),
m_dimBrightThreshold(kDefaultDimBrightThreshold),
m_height(-1),
m_width(-1),
m_devicePixelRatio(1.0f),
Expand Down Expand Up @@ -315,6 +320,12 @@ void WaveformWidgetRenderer::setup(
m_orientation = Qt::Horizontal;
}

bool okay;
m_dimBrightThreshold = context.selectInt(node, QStringLiteral("DimBrightThreshold"), &okay);
if (!okay) {
m_dimBrightThreshold = kDefaultDimBrightThreshold;
}

m_colors.setup(node, context);
for (int i = 0; i < m_rendererStack.size(); ++i) {
m_rendererStack[i]->setScaleFactor(m_scaleFactor);
Expand Down
2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformwidgetrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class WaveformWidgetRenderer {
int getBreadth() const { return m_orientation == Qt::Horizontal ? m_height : m_width;}
Qt::Orientation getOrientation() const { return m_orientation;}
const WaveformSignalColors* getWaveformSignalColors() const { return &m_colors; };
int getDimBrightThreshold() { return m_dimBrightThreshold; }

template< class T_Renderer>
inline T_Renderer* addRenderer() {
Expand Down Expand Up @@ -120,6 +121,7 @@ class WaveformWidgetRenderer {
TrackPointer m_pTrack;
QList<WaveformRendererAbstract*> m_rendererStack;
Qt::Orientation m_orientation;
int m_dimBrightThreshold;
int m_height;
int m_width;
float m_devicePixelRatio;
Expand Down
3 changes: 2 additions & 1 deletion src/widget/woverview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ void WOverview::setup(const QDomNode& node, const SkinContext& context) {
m_passthroughOverlayColor = m_signalColors.getPassthroughOverlayColor();
m_playedOverlayColor = m_signalColors.getPlayedOverlayColor();
m_lowColor = m_signalColors.getLowColor();
m_dimBrightThreshold = m_signalColors.getDimBrightThreshold();

m_labelBackgroundColor = context.selectColor(node, "LabelBackgroundColor");
if (!m_labelBackgroundColor.isValid()) {
Expand Down Expand Up @@ -390,7 +391,7 @@ void WOverview::updateCues(const QList<CuePointer> &loadedCues) {
&& pMark->getSamplePosition() != Cue::kNoPosition) {
QColor newColor = mixxx::RgbColor::toQColor(currentCue->getColor());
if (newColor != pMark->fillColor() || newColor != pMark->m_textColor) {
pMark->setBaseColor(newColor);
pMark->setBaseColor(newColor, m_dimBrightThreshold);
}

int hotcueNumber = currentCue->getHotCue();
Expand Down
1 change: 1 addition & 0 deletions src/widget/woverview.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ class WOverview : public WWidget, public TrackDropTarget {
QColor m_passthroughOverlayColor;
QColor m_playedOverlayColor;
QColor m_lowColor;
int m_dimBrightThreshold;
QLabel* m_pPassthroughLabel;

// All WaveformMarks
Expand Down
8 changes: 5 additions & 3 deletions src/widget/wwaveformviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void WWaveformViewer::setup(const QDomNode& node, const SkinContext& context) {
if (m_waveformWidget) {
m_waveformWidget->setup(node, context);
}
m_dimBrightThreshold = m_waveformWidget->getDimBrightThreshold();
}

void WWaveformViewer::resizeEvent(QResizeEvent* /*event*/) {
Expand Down Expand Up @@ -272,13 +273,14 @@ CuePointer WWaveformViewer::getCuePointerFromCueMark(WaveformMarkPointer pMark)
}

void WWaveformViewer::highlightMark(WaveformMarkPointer pMark) {
QColor highlightColor = Color::chooseContrastColor(pMark->fillColor());
pMark->setBaseColor(highlightColor);
QColor highlightColor = Color::chooseContrastColor(pMark->fillColor(),
m_dimBrightThreshold);
pMark->setBaseColor(highlightColor, m_dimBrightThreshold);
}

void WWaveformViewer::unhighlightMark(WaveformMarkPointer pMark) {
QColor originalColor = mixxx::RgbColor::toQColor(getCuePointerFromCueMark(pMark)->getColor());
pMark->setBaseColor(originalColor);
pMark->setBaseColor(originalColor, m_dimBrightThreshold);
}

bool WWaveformViewer::isPlaying() const {
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wwaveformviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class WWaveformViewer : public WWidget, public TrackDropTarget {

WaveformWidgetAbstract* m_waveformWidget;

int m_dimBrightThreshold;

friend class WaveformWidgetFactory;

CuePointer getCuePointerFromCueMark(WaveformMarkPointer pMark) const;
Expand Down

0 comments on commit 53c2bc6

Please sign in to comment.