Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/widget/wknobcomposed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ WKnobComposed::WKnobComposed(QWidget* pParent)
m_dArcThickness(0),
m_dArcBgThickness(0),
m_arcUnipolar(true),
m_arcReversed(false),
m_arcPenCap(Qt::FlatCap),
m_renderTimer(mixxx::Duration::fromMillis(20),
mixxx::Duration::fromSeconds(1)) {
connect(&m_renderTimer, SIGNAL(update()),
Expand Down Expand Up @@ -63,9 +65,14 @@ void WKnobComposed::setup(const QDomNode& node, const SkinContext& context) {
m_dArcBgThickness *= scaleFactor;
m_arcBgColor = WSkinColor::getCorrectColor(context.selectColor(node, "ArcBgColor"));
}
if (context.selectBool(node, "ArcRoundCaps", false)) {
m_arcPenCap = Qt::RoundCap;
}
// ToDo: Make these properties configurable by the connected control.
// Example: Meta knobs that are fully dry when centered, or parameters
// that work reversed, like microphone ducking or BitCrusher parameters.
m_arcUnipolar = context.selectBool(node, "ArcUnipolar", false);
// ToDo(ronso0) Also allow customizing the pen shape?
// Qt::FlatCap (default) | Qt::RoundCap
m_arcReversed = context.selectBool(node, "ArcReversed", false);
}

m_dKnobCenterXOffset *= scaleFactor;
Expand Down Expand Up @@ -161,22 +168,29 @@ void WKnobComposed::drawArc(QPainter* pPainter) {
QPointF bottomRight = QPointF((centerX + m_dArcRadius), (centerY + m_dArcRadius));
QRectF rect = QRectF(topLeft, bottomRight);

// draw background arc
if (m_dArcBgThickness > 0.0) {
QPen arcBgPen = QPen(m_arcBgColor);
arcBgPen.setWidth(m_dArcBgThickness);
arcBgPen.setCapStyle(Qt::FlatCap);
arcBgPen.setCapStyle(m_arcPenCap);
pPainter->setPen(arcBgPen);
pPainter->drawArc(rect, (90 - m_dMinAngle) * 16, (m_dMinAngle - m_dMaxAngle) * 16);
}

// draw foreground arc
QPen arcPen = QPen(m_arcColor);
arcPen.setWidth(m_dArcThickness);
arcPen.setCapStyle(Qt::FlatCap);
arcPen.setCapStyle(m_arcPenCap);

pPainter->setPen(arcPen);
if (m_arcUnipolar) {
// draw arc from minAngle to current position
pPainter->drawArc(rect, (90 - m_dMinAngle) * 16, (m_dCurrentAngle - m_dMinAngle) * -16);
if (m_arcReversed) {
// draw arc from maxAngle to current position
pPainter->drawArc(rect, (90 - m_dCurrentAngle) * 16, (m_dMaxAngle - m_dCurrentAngle) * -16);
} else {
// draw arc from minAngle to current position
pPainter->drawArc(rect, (90 - m_dMinAngle) * 16, (m_dCurrentAngle - m_dMinAngle) * -16);
}
} else {
// draw arc from center to current position
pPainter->drawArc(rect, 90 * 16, m_dCurrentAngle * -16);
Expand Down
2 changes: 2 additions & 0 deletions src/widget/wknobcomposed.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class WKnobComposed : public WWidget {
QColor m_arcColor;
QColor m_arcBgColor;
bool m_arcUnipolar;
bool m_arcReversed;
Qt::PenCapStyle m_arcPenCap;
WidgetRenderTimer m_renderTimer;

friend class KnobEventHandler<WKnobComposed>;
Expand Down