Skip to content

Commit

Permalink
merge WaveformMarkProperties into WaveformMark class
Browse files Browse the repository at this point in the history
I do not understand why these were separate classes in the first place.
  • Loading branch information
Be-ing committed Aug 15, 2019
1 parent e2c80bc commit a263a84
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 253 deletions.
1 change: 0 additions & 1 deletion build/depends.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,6 @@ def sources(self, build):

"src/waveform/renderers/waveformrenderersignalbase.cpp",
"src/waveform/renderers/waveformmark.cpp",
"src/waveform/renderers/waveformmarkproperties.cpp",
"src/waveform/renderers/waveformmarkset.cpp",
"src/waveform/renderers/waveformmarkrange.cpp",
"src/waveform/renderers/glwaveformrenderersimplesignal.cpp",
Expand Down
106 changes: 86 additions & 20 deletions src/waveform/renderers/waveformmark.cpp
Original file line number Diff line number Diff line change
@@ -1,39 +1,105 @@
#include <QtDebug>

#include "skin/skincontext.h"
#include "waveform/renderers/waveformmarkproperties.h"
#include "waveform/renderers/waveformsignalcolors.h"
#include "widget/wskincolor.h"

#include "waveformmark.h"

WaveformMark::WaveformMark(const QString& group,
const QDomNode& node,
const SkinContext& context,
const WaveformSignalColors& signalColors)
: m_iHotCue(kNoHotCue) {
QString item = context.selectString(node, "Control");
if (!item.isEmpty()) {
m_pPointCos = std::make_unique<ControlProxy>(group, item);
if (item.startsWith("hotcue_") && item.endsWith("_position")) {
m_iHotCue = item.midRef(7, item.count() - 16).toInt() - 1;
namespace {
Qt::Alignment decodeAlignmentFlags(QString alignString, Qt::Alignment defaultFlags) {
QStringList stringFlags = alignString.toLower()
.split("|", QString::SkipEmptyParts);

Qt::Alignment hflags = 0L;
Qt::Alignment vflags = 0L;

for (auto stringFlag : stringFlags) {
if (stringFlag == "center") {
hflags |= Qt::AlignHCenter;
vflags |= Qt::AlignVCenter;
} else if (stringFlag == "left") {
hflags |= Qt::AlignLeft;
} else if (stringFlag == "hcenter") {
hflags |= Qt::AlignHCenter;
} else if (stringFlag == "right") {
hflags |= Qt::AlignRight;
} else if (stringFlag == "top") {
vflags |= Qt::AlignTop;
} else if (stringFlag == "vcenter") {
vflags |= Qt::AlignVCenter;
} else if (stringFlag == "bottom") {
vflags |= Qt::AlignBottom;
}
}
QString visibilityControl = context.selectString(node, "VisibilityControl");
if (!visibilityControl.isEmpty()) {
ConfigKey key = ConfigKey::parseCommaSeparated(visibilityControl);
m_pVisibleCos = std::make_unique<ControlProxy>(key);

if (hflags != Qt::AlignLeft && hflags != Qt::AlignHCenter && hflags != Qt::AlignRight) {
hflags = defaultFlags & Qt::AlignHorizontal_Mask;
}

if (vflags != Qt::AlignTop && vflags != Qt::AlignVCenter && vflags != Qt::AlignBottom) {
vflags = defaultFlags & Qt::AlignVertical_Mask;
}
m_properties = WaveformMarkProperties(node, context, signalColors, m_iHotCue);

return hflags | vflags;
}
} // anonymous namespace

WaveformMark::WaveformMark(const QString& group,
const QDomNode& node,
const SkinContext& context,
const WaveformSignalColors& signalColors,
int hotCue)
: m_iHotCue(hotCue) {
if (hotCue >= 0) {
QString item = "hotcue_" + QString::number(hotCue + 1) + "_position";
m_pPointCos = std::make_unique<ControlProxy>(group, item);
QString control;
if (hotCue != kNoHotCue) {
control = "hotcue_" + QString::number(hotCue + 1) + "_position";
} else {
control = context.selectString(node, "Control");
}
if (!control.isEmpty()) {
m_pPointCos = std::make_unique<ControlProxy>(group, control);
}

QString visibilityControl = context.selectString(node, "VisibilityControl");
if (!visibilityControl.isEmpty()) {
ConfigKey key = ConfigKey::parseCommaSeparated(visibilityControl);
m_pVisibleCos = std::make_unique<ControlProxy>(key);
}

QColor color(context.selectString(node, "Color"));
if (!color.isValid()) {
// As a fallback, grab the color from the parent's AxesColor
color = signalColors.getAxesColor();
qDebug() << "Didn't get mark <Color>, using parent's <AxesColor>:" << color;
} else {
color = WSkinColor::getCorrectColor(color);
}
setBaseColor(color);

m_textColor = context.selectString(node, "TextColor");
if (!m_textColor.isValid()) {
// Read the text color, otherwise use the parent's BgColor.
m_textColor = signalColors.getBgColor();
qDebug() << "Didn't get mark <TextColor>, using parent's <BgColor>:" << m_textColor;
}

QString markAlign = context.selectString(node, "Align");
m_align = decodeAlignmentFlags(markAlign, Qt::AlignBottom | Qt::AlignHCenter);

// Hotcue text is set by the cue's label in the database, not by the skin.
if (hotCue == WaveformMark::kNoHotCue) {
m_text = context.selectString(node, "Text");
}

m_pixmapPath = context.selectString(node, "Pixmap");
if (!m_pixmapPath.isEmpty()) {
m_pixmapPath = context.makeSkinPath(m_pixmapPath);
}
m_properties = WaveformMarkProperties(node, context, signalColors, hotCue);
}

void WaveformMark::setBaseColor(QColor baseColor) {
m_fillColor = baseColor;
m_borderColor = Color::chooseContrastColor(baseColor);
m_labelColor = Color::chooseColorByBrightness(baseColor, QColor(255,255,255,255), QColor(0,0,0,255));
};
42 changes: 25 additions & 17 deletions src/waveform/renderers/waveformmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "control/controlproxy.h"
#include "util/memory.h"

#include "waveform/renderers/waveformmarkproperties.h"
#include "control/controlobject.h"

class SkinContext;
Expand All @@ -18,31 +17,17 @@ class WOverview;
class WaveformMark {
public:
static const int kNoHotCue = -1;
WaveformMark(
const QString& group,
const QDomNode& node,
const SkinContext& context,
const WaveformSignalColors& signalColors);

WaveformMark(
const QString& group,
const QDomNode& node,
const SkinContext& context,
const WaveformSignalColors& signalColors,
int hotCue);

int hotCue = kNoHotCue);

// Disable copying
WaveformMark(const WaveformMark&) = delete;
WaveformMark& operator=(const WaveformMark&) = delete;

const WaveformMarkProperties& getProperties() const {
return m_properties;
};
void setProperties(const WaveformMarkProperties& properties) {
m_properties = properties;
};

int getHotCue() const { return m_iHotCue; };

//The m_pPointCos related function
Expand All @@ -69,13 +54,36 @@ class WaveformMark {
m_pVisibleCos->connectValueChanged(receiver, slot, Qt::AutoConnection);
}

// Sets the appropriate mark colors based on the base color
void setBaseColor(QColor baseColor);
QColor fillColor() const {
return m_fillColor;
}
QColor borderColor() const {
return m_borderColor;
}
QColor labelColor() const {
return m_labelColor;
}

QColor m_textColor;
QString m_text;
Qt::Alignment m_align;
QString m_pixmapPath;

QRectF m_renderedArea;
bool m_bMouseHovering;

private:
std::unique_ptr<ControlProxy> m_pPointCos;
std::unique_ptr<ControlProxy> m_pVisibleCos;
WaveformMarkProperties m_properties;
int m_iHotCue;
QImage m_image;

QColor m_fillColor;
QColor m_borderColor;
QColor m_labelColor;

friend class WaveformRenderMark;
};

Expand Down
96 changes: 0 additions & 96 deletions src/waveform/renderers/waveformmarkproperties.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions src/waveform/renderers/waveformmarkproperties.h

This file was deleted.

2 changes: 2 additions & 0 deletions src/waveform/renderers/waveformmarkset.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class WaveformWidgetRenderer;

// This class helps share code between the WaveformRenderMark and WOverview
// constructors.
class WaveformMarkSet {
public:
WaveformMarkSet();
Expand Down
Loading

0 comments on commit a263a84

Please sign in to comment.