From c10143322cfcafaa942d9c81a4986acf6fa95a50 Mon Sep 17 00:00:00 2001 From: Joerg Date: Sun, 30 Jun 2024 08:10:31 +0200 Subject: [PATCH 1/4] Made Paintable::DrawMode an enum class --- src/widget/paintable.cpp | 54 ++++++++++++++++++---------------- src/widget/paintable.h | 2 +- src/widget/wbattery.cpp | 18 ++++++------ src/widget/wdisplay.cpp | 10 +++---- src/widget/wknobcomposed.cpp | 4 +-- src/widget/wpixmapstore.cpp | 2 +- src/widget/wpushbutton.cpp | 8 ++--- src/widget/wslidercomposed.cpp | 18 ++++++------ src/widget/wspinnybase.cpp | 4 +-- src/widget/wstatuslight.cpp | 12 ++++---- src/widget/wvumeterbase.cpp | 6 ++-- src/widget/wvumeterlegacy.cpp | 6 ++-- src/widget/wwidgetgroup.cpp | 4 +-- 13 files changed, 75 insertions(+), 73 deletions(-) diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index 836f752b5e2..93bcf4b4914 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -16,35 +16,36 @@ // static Paintable::DrawMode Paintable::DrawModeFromString(const QString& str) { if (str.compare("FIXED", Qt::CaseInsensitive) == 0) { - return FIXED; + return DrawMode::FIXED; } else if (str.compare("STRETCH", Qt::CaseInsensitive) == 0) { - return STRETCH; + return DrawMode::STRETCH; } else if (str.compare("STRETCH_ASPECT", Qt::CaseInsensitive) == 0) { - return STRETCH_ASPECT; + return DrawMode::STRETCH_ASPECT; } else if (str.compare("TILE", Qt::CaseInsensitive) == 0) { - return TILE; + return DrawMode::TILE; } // Fall back on the implicit default from before Mixxx supported draw modes. qWarning() << "Unknown DrawMode string in DrawModeFromString:" << str << "using FIXED"; - return FIXED; + return DrawMode::FIXED; } // static QString Paintable::DrawModeToString(DrawMode mode) { switch (mode) { - case FIXED: - return "FIXED"; - case STRETCH: - return "STRETCH"; - case STRETCH_ASPECT: - return "STRETCH_ASPECT"; - case TILE: - return "TILE"; + case DrawMode::FIXED: + return "FIXED"; + case DrawMode::STRETCH: + return "STRETCH"; + case DrawMode::STRETCH_ASPECT: + return "STRETCH_ASPECT"; + case DrawMode::TILE: + return "TILE"; } // Fall back on the implicit default from before Mixxx supported draw modes. - qWarning() << "Unknown DrawMode in DrawModeToString " << mode + qWarning() << "Unknown DrawMode in DrawModeToString " << static_cast(mode) + << "using FIXED"; return "FIXED"; } @@ -82,9 +83,10 @@ Paintable::Paintable(const PixmapSource& source, DrawMode mode, double scaleFact // cache the pixmap. We do not do this for TILE and color schemas. // which can result in a correct but possibly blurry picture at a // Retina display. This can be fixed when switching to QT5 - if (mode == TILE || WPixmapStore::willCorrectColors()) { + if (mode == DrawMode::TILE || WPixmapStore::willCorrectColors()) { #else - if (mode == TILE || mode == Paintable::FIXED || WPixmapStore::willCorrectColors()) { + if (mode == DrawMode::TILE || mode == DrawMode::FIXED || + WPixmapStore::willCorrectColors()) { #endif // The SVG renderer doesn't directly support tiling, so we render // it to a pixmap which will then get tiled. @@ -168,7 +170,7 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, } switch (m_drawMode) { - case FIXED: { + case DrawMode::FIXED: { // Only render the minimum overlapping rectangle between the source // and target. QSizeF fixedSize(math_min(sourceRect.width(), targetRect.width()), @@ -178,7 +180,7 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, drawInternal(adjustedTarget, pPainter, adjustedSource); break; } - case STRETCH_ASPECT: { + case DrawMode::STRETCH_ASPECT: { qreal sx = targetRect.width() / sourceRect.width(); qreal sy = targetRect.height() / sourceRect.height(); @@ -195,10 +197,10 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, } break; } - case STRETCH: + case DrawMode::STRETCH: drawInternal(targetRect, pPainter, sourceRect); break; - case TILE: + case DrawMode::TILE: drawInternal(targetRect, pPainter, sourceRect); break; } @@ -207,7 +209,7 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, void Paintable::drawCentered(const QRectF& targetRect, QPainter* pPainter, const QRectF& sourceRect) { switch (m_drawMode) { - case FIXED: { + case DrawMode::FIXED: { // Only render the minimum overlapping rectangle between the source // and target. QSizeF fixedSize(math_min(sourceRect.width(), targetRect.width()), @@ -220,7 +222,7 @@ void Paintable::drawCentered(const QRectF& targetRect, QPainter* pPainter, drawInternal(adjustedTarget, pPainter, adjustedSource); break; } - case STRETCH_ASPECT: { + case DrawMode::STRETCH_ASPECT: { qreal sx = targetRect.width() / sourceRect.width(); qreal sy = targetRect.height() / sourceRect.height(); @@ -237,10 +239,10 @@ void Paintable::drawCentered(const QRectF& targetRect, QPainter* pPainter, } break; } - case STRETCH: + case DrawMode::STRETCH: drawInternal(targetRect, pPainter, sourceRect); break; - case TILE: + case DrawMode::TILE: // TODO(XXX): What's the right behavior here? Draw the first tile at the // center point and then tile all around it based on that? drawInternal(targetRect, pPainter, sourceRect); @@ -253,7 +255,7 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter, // qDebug() << "Paintable::drawInternal" << DrawModeToString(m_draw_mode) // << targetRect << sourceRect; if (m_pPixmap) { - if (m_drawMode == TILE) { + if (m_drawMode == DrawMode::TILE) { // TODO(rryan): Using a source rectangle doesn't make much sense // with tiling. Ignore the source rect and tile our natural size // across the target rect. What's the right general behavior here? @@ -267,7 +269,7 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter, sourceRect.toRect()); } } else if (m_pSvg) { - if (m_drawMode == TILE) { + if (m_drawMode == DrawMode::TILE) { qWarning() << "Tiled SVG should have been rendered to pixmap!"; } else { // NOTE(rryan): QSvgRenderer render does not clip for us -- it diff --git a/src/widget/paintable.h b/src/widget/paintable.h index 1cb9d258543..19730fd36f4 100644 --- a/src/widget/paintable.h +++ b/src/widget/paintable.h @@ -16,7 +16,7 @@ class QSvgRenderer; // high fidelity. class Paintable { public: - enum DrawMode { + enum class DrawMode { // Draw the image in its native dimensions with no stretching or tiling. FIXED, // Stretch the image. diff --git a/src/widget/wbattery.cpp b/src/widget/wbattery.cpp index d731480119a..0fcf0017c75 100644 --- a/src/widget/wbattery.cpp +++ b/src/widget/wbattery.cpp @@ -24,17 +24,17 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { QDomElement backPath = context.selectElement(node, "BackPath"); if (!backPath.isNull()) { setPixmap(&m_pPixmapBack, - context.getPixmapSource(backPath), - context.selectScaleMode(backPath, Paintable::TILE), - context.getScaleFactor()); + context.getPixmapSource(backPath), + context.selectScaleMode(backPath, Paintable::DrawMode::TILE), + context.getScaleFactor()); } QDomElement chargedPath = context.selectElement(node, "PixmapCharged"); if (!chargedPath.isNull()) { setPixmap(&m_pPixmapCharged, - context.getPixmapSource(chargedPath), - context.selectScaleMode(chargedPath, Paintable::TILE), - context.getScaleFactor()); + context.getPixmapSource(chargedPath), + context.selectScaleMode(chargedPath, Paintable::DrawMode::TILE), + context.getScaleFactor()); } int numberStates = context.selectInt(node, "NumberStates"); @@ -50,7 +50,7 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { // TODO(XXX) inline SVG support via context.getPixmapSource. QString chargingPath = context.nodeToString(pixmapsCharging); Paintable::DrawMode mode = context.selectScaleMode(pixmapsCharging, - Paintable::TILE); + Paintable::DrawMode::TILE); for (int i = 0; i < m_chargingPixmaps.size(); ++i) { PixmapSource source = context.getPixmapSource(chargingPath.arg(i)); setPixmap(&m_chargingPixmaps[i], source, mode, context.getScaleFactor()); @@ -62,7 +62,7 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { // TODO(XXX) inline SVG support via context.getPixmapSource. QString dischargingPath = context.nodeToString(pixmapsDischarging); Paintable::DrawMode mode = context.selectScaleMode(pixmapsDischarging, - Paintable::TILE); + Paintable::DrawMode::TILE); for (int i = 0; i < m_dischargingPixmaps.size(); ++i) { PixmapSource source = context.getPixmapSource(dischargingPath.arg(i)); setPixmap(&m_dischargingPixmaps[i], source, mode, context.getScaleFactor()); @@ -148,7 +148,7 @@ void WBattery::setPixmap(PaintablePointer* ppPixmap, const PixmapSource& source, qDebug() << this << "Error loading pixmap:" << source.getPath(); } else { *ppPixmap = pPixmap; - if (mode == Paintable::FIXED) { + if (mode == Paintable::DrawMode::FIXED) { setFixedSize(pPixmap->size()); } } diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index fe1bdd8a024..d19d364c11b 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -26,8 +26,8 @@ void WDisplay::setup(const QDomNode& node, const SkinContext& context) { QDomElement backPathNode = context.selectElement(node, "BackPath"); if (!backPathNode.isNull()) { setPixmapBackground(context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::TILE), - context.getScaleFactor()); + context.selectScaleMode(backPathNode, Paintable::DrawMode::TILE), + context.getScaleFactor()); } // Number of states @@ -39,7 +39,7 @@ void WDisplay::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode pathMode = - context.selectScaleMode(pathNode, Paintable::FIXED); + context.selectScaleMode(pathNode, Paintable::DrawMode::FIXED); for (int i = 0; i < m_pixmaps.size(); ++i) { setPixmap(&m_pixmaps, i, context.makeSkinPath(path.arg(i)), pathMode, context.getScaleFactor()); @@ -52,7 +52,7 @@ void WDisplay::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode disabledMode = - context.selectScaleMode(disabledNode, Paintable::FIXED); + context.selectScaleMode(disabledNode, Paintable::DrawMode::FIXED); for (int i = 0; i < m_disabledPixmaps.size(); ++i) { setPixmap(&m_disabledPixmaps, i, context.makeSkinPath(disabledPath.arg(i)), @@ -108,7 +108,7 @@ void WDisplay::setPixmap( << "Error loading pixmap:" << filename; } else { (*pPixmaps)[iPos] = pPixmap; - if (mode == Paintable::FIXED) { + if (mode == Paintable::DrawMode::FIXED) { setFixedSize(pPixmap->size()); } } diff --git a/src/widget/wknobcomposed.cpp b/src/widget/wknobcomposed.cpp index 9ad576498c5..93032336d36 100644 --- a/src/widget/wknobcomposed.cpp +++ b/src/widget/wknobcomposed.cpp @@ -33,7 +33,7 @@ void WKnobComposed::setup(const QDomNode& node, const SkinContext& context) { if (!backPathElement.isNull()) { setPixmapBackground( context.getPixmapSource(backPathElement), - context.selectScaleMode(backPathElement, Paintable::STRETCH), + context.selectScaleMode(backPathElement, Paintable::DrawMode::STRETCH), scaleFactor); } @@ -42,7 +42,7 @@ void WKnobComposed::setup(const QDomNode& node, const SkinContext& context) { if (!knobNode.isNull()) { setPixmapKnob( context.getPixmapSource(knobNode), - context.selectScaleMode(knobNode, Paintable::STRETCH), + context.selectScaleMode(knobNode, Paintable::DrawMode::STRETCH), scaleFactor); } diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 75cbdb60574..4fd9775e571 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -14,7 +14,7 @@ PaintablePointer WPixmapStore::getPaintable(const PixmapSource& source, return PaintablePointer(); } QString key = QStringLiteral("%1%2%3").arg(source.getId(), - QString::number(mode), + QString::number(static_cast(mode)), QString::number(scaleFactor)); // See if we have a cached value for the pixmap. diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 8d77e5ff241..24f299b2fb5 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -47,7 +47,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { // backwards compatibility. setPixmapBackground( backgroundSource, - context.selectScaleMode(backPathNode, Paintable::FIXED), + context.selectScaleMode(backPathNode, Paintable::DrawMode::FIXED), context.getScaleFactor()); } } @@ -97,7 +97,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode unpressedMode = - stateContext->selectScaleMode(unpressedNode, Paintable::FIXED); + stateContext->selectScaleMode(unpressedNode, Paintable::DrawMode::FIXED); if (!pixmapSource.isEmpty()) { setPixmap(iState, false, pixmapSource, unpressedMode, context.getScaleFactor()); @@ -108,7 +108,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode pressedMode = - stateContext->selectScaleMode(pressedNode, Paintable::FIXED); + stateContext->selectScaleMode(pressedNode, Paintable::DrawMode::FIXED); if (!pixmapSource.isEmpty()) { setPixmap(iState, true, pixmapSource, pressedMode, context.getScaleFactor()); @@ -265,7 +265,7 @@ void WPushButton::setPixmap(int iState, if (!source.isEmpty()) { qDebug() << "WPushButton: Error loading pixmap:" << source.getPath(); } - } else if (mode == Paintable::FIXED) { + } else if (mode == Paintable::DrawMode::FIXED) { // Set size of widget equal to pixmap size setFixedSize(pPixmap->size()); } diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index c080ab9b6e3..a6c2861b129 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -63,7 +63,7 @@ void WSliderComposed::setup(const QDomNode& node, const SkinContext& context) { PixmapSource sourceSlider = context.getPixmapSource(slider); setSliderPixmap( sourceSlider, - context.selectScaleMode(slider, Paintable::FIXED), + context.selectScaleMode(slider, Paintable::DrawMode::FIXED), scaleFactor); } @@ -76,7 +76,7 @@ void WSliderComposed::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setHandlePixmap( sourceHandle, - context.selectScaleMode(handle, Paintable::FIXED), + context.selectScaleMode(handle, Paintable::DrawMode::FIXED), scaleFactor); // Set up the level bar. @@ -183,7 +183,7 @@ void WSliderComposed::setSliderPixmap(const PixmapSource& sourceSlider, m_pSlider = WPixmapStore::getPaintable(sourceSlider, drawMode, scaleFactor); if (!m_pSlider) { qDebug() << "WSliderComposed: Error loading slider pixmap:" << sourceSlider.getPath(); - } else if (drawMode == Paintable::FIXED) { + } else if (drawMode == Paintable::DrawMode::FIXED) { // Set size of widget, using size of slider pixmap setFixedSize(m_pSlider->size()); } @@ -353,10 +353,10 @@ double WSliderComposed::calculateHandleLength() { Paintable::DrawMode mode = m_pHandle->drawMode(); if (m_bHorizontal) { // Stretch the pixmap to be the height of the widget. - if (mode == Paintable::FIXED || mode == Paintable::STRETCH || - mode == Paintable::TILE || m_pHandle->height() == 0.0) { + if (mode == Paintable::DrawMode::FIXED || mode == Paintable::DrawMode::STRETCH || + mode == Paintable::DrawMode::TILE || m_pHandle->height() == 0.0) { return m_pHandle->width(); - } else if (mode == Paintable::STRETCH_ASPECT) { + } else if (mode == Paintable::DrawMode::STRETCH_ASPECT) { const int iHeight = m_pHandle->height(); if (iHeight == 0) { qDebug() << "WSliderComposed: Invalid height."; @@ -368,10 +368,10 @@ double WSliderComposed::calculateHandleLength() { } } else { // Stretch the pixmap to be the width of the widget. - if (mode == Paintable::FIXED || mode == Paintable::STRETCH || - mode == Paintable::TILE || m_pHandle->width() == 0.0) { + if (mode == Paintable::DrawMode::FIXED || mode == Paintable::DrawMode::STRETCH || + mode == Paintable::DrawMode::TILE || m_pHandle->width() == 0.0) { return m_pHandle->height(); - } else if (mode == Paintable::STRETCH_ASPECT) { + } else if (mode == Paintable::DrawMode::STRETCH_ASPECT) { const int iWidth = m_pHandle->width(); if (iWidth == 0) { qDebug() << "WSliderComposed: Invalid width."; diff --git a/src/widget/wspinnybase.cpp b/src/widget/wspinnybase.cpp index 462a744c8d6..eda433f9fc9 100644 --- a/src/widget/wspinnybase.cpp +++ b/src/widget/wspinnybase.cpp @@ -146,8 +146,8 @@ void WSpinnyBase::setup(const QDomNode& node, m_pBgImage = WImageStore::getImage(context.getPixmapSource(backPathElement), context.getScaleFactor()); Paintable::DrawMode bgmode = context.selectScaleMode(backPathElement, - Paintable::FIXED); - if (m_pBgImage && !m_pBgImage->isNull() && bgmode == Paintable::FIXED) { + Paintable::DrawMode::FIXED); + if (m_pBgImage && !m_pBgImage->isNull() && bgmode == Paintable::DrawMode::FIXED) { setFixedSize(m_pBgImage->size()); } else { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index 8a2540d1966..7c88d94f564 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -40,11 +40,11 @@ void WStatusLight::setup(const QDomNode& node, const SkinContext& context) { if (context.hasNodeSelectElement(node, nodeName, &statusLightNode) || (i == 0 && context.hasNodeSelectElement(node, "PathBack", &statusLightNode)) || (i == 1 && context.hasNodeSelectElement(node, "PathStatusLight", &statusLightNode))) { - setPixmap(i, context.getPixmapSource(statusLightNode), - context.selectScaleMode( - statusLightNode, - Paintable::FIXED), - context.getScaleFactor()); + setPixmap(i, + context.getPixmapSource(statusLightNode), + context.selectScaleMode( + statusLightNode, Paintable::DrawMode::FIXED), + context.getScaleFactor()); } else { m_pixmaps[i].reset(); } @@ -64,7 +64,7 @@ void WStatusLight::setPixmap(int iState, PaintablePointer pPixmap = WPixmapStore::getPaintable(source, mode, scaleFactor); if (pPixmap && !pPixmap->isNull()) { m_pixmaps[iState] = pPixmap; - if (mode == Paintable::FIXED) { + if (mode == Paintable::DrawMode::FIXED) { setFixedSize(pPixmap->size()); } } else { diff --git a/src/widget/wvumeterbase.cpp b/src/widget/wvumeterbase.cpp index 65ae82c0efd..06e8f415b83 100644 --- a/src/widget/wvumeterbase.cpp +++ b/src/widget/wvumeterbase.cpp @@ -46,7 +46,7 @@ void WVuMeterBase::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmapBackground( context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::FIXED), + context.selectScaleMode(backPathNode, Paintable::DrawMode::FIXED), context.getScaleFactor()); } @@ -55,7 +55,7 @@ void WVuMeterBase::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmaps(context.getPixmapSource(vuNode), bHorizontal, - context.selectScaleMode(vuNode, Paintable::FIXED), + context.selectScaleMode(vuNode, Paintable::DrawMode::FIXED), context.getScaleFactor()); m_iPeakHoldSize = context.selectInt(node, "PeakHoldSize"); @@ -98,7 +98,7 @@ void WVuMeterBase::setPixmapBackground( if (!m_pPixmapBack) { qDebug() << metaObject()->className() << "Error loading background pixmap:" << source.getPath(); - } else if (mode == Paintable::FIXED) { + } else if (mode == Paintable::DrawMode::FIXED) { setFixedSize(m_pPixmapBack->size()); } } diff --git a/src/widget/wvumeterlegacy.cpp b/src/widget/wvumeterlegacy.cpp index 7581cd9b2aa..c0dc3feb02a 100644 --- a/src/widget/wvumeterlegacy.cpp +++ b/src/widget/wvumeterlegacy.cpp @@ -41,7 +41,7 @@ void WVuMeterLegacy::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmapBackground( context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::FIXED), + context.selectScaleMode(backPathNode, Paintable::DrawMode::FIXED), context.getScaleFactor()); } @@ -50,7 +50,7 @@ void WVuMeterLegacy::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmaps(context.getPixmapSource(vuNode), bHorizontal, - context.selectScaleMode(vuNode, Paintable::FIXED), + context.selectScaleMode(vuNode, Paintable::DrawMode::FIXED), context.getScaleFactor()); m_iPeakHoldSize = context.selectInt(node, "PeakHoldSize"); @@ -84,7 +84,7 @@ void WVuMeterLegacy::setPixmapBackground( if (!m_pPixmapBack || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() << "Error loading background pixmap:" << source.getPath(); - } else if (mode == Paintable::FIXED) { + } else if (mode == Paintable::DrawMode::FIXED) { setFixedSize(m_pPixmapBack->size()); } } diff --git a/src/widget/wwidgetgroup.cpp b/src/widget/wwidgetgroup.cpp index 497be95fa29..791d9f1668b 100644 --- a/src/widget/wwidgetgroup.cpp +++ b/src/widget/wwidgetgroup.cpp @@ -103,7 +103,7 @@ void WWidgetGroup::setup(const QDomNode& node, const SkinContext& context) { if (!backPathNode.isNull()) { setPixmapBackground( context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::TILE), + context.selectScaleMode(backPathNode, Paintable::DrawMode::TILE), context.getScaleFactor()); } @@ -113,7 +113,7 @@ void WWidgetGroup::setup(const QDomNode& node, const SkinContext& context) { if (!backPathNodeHighlighted.isNull()) { setPixmapBackgroundHighlighted( context.getPixmapSource(backPathNodeHighlighted), - context.selectScaleMode(backPathNodeHighlighted, Paintable::TILE), + context.selectScaleMode(backPathNodeHighlighted, Paintable::DrawMode::TILE), context.getScaleFactor()); } From 8d2da1622f216b3faf858202162ad446712586be Mon Sep 17 00:00:00 2001 From: Joerg Date: Sun, 30 Jun 2024 19:05:16 +0200 Subject: [PATCH 2/4] Changed enum values to TitleCase --- src/widget/paintable.cpp | 68 +++++++++++++++++----------------- src/widget/paintable.h | 8 ++-- src/widget/wbattery.cpp | 10 ++--- src/widget/wdisplay.cpp | 8 ++-- src/widget/wknobcomposed.cpp | 4 +- src/widget/wpushbutton.cpp | 8 ++-- src/widget/wslidercomposed.cpp | 18 ++++----- src/widget/wspinnybase.cpp | 4 +- src/widget/wstatuslight.cpp | 4 +- src/widget/wvumeterbase.cpp | 6 +-- src/widget/wvumeterlegacy.cpp | 6 +-- src/widget/wwidgetgroup.cpp | 4 +- 12 files changed, 74 insertions(+), 74 deletions(-) diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index 93bcf4b4914..2acd78cc642 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -15,39 +15,39 @@ // static Paintable::DrawMode Paintable::DrawModeFromString(const QString& str) { - if (str.compare("FIXED", Qt::CaseInsensitive) == 0) { - return DrawMode::FIXED; - } else if (str.compare("STRETCH", Qt::CaseInsensitive) == 0) { - return DrawMode::STRETCH; - } else if (str.compare("STRETCH_ASPECT", Qt::CaseInsensitive) == 0) { - return DrawMode::STRETCH_ASPECT; - } else if (str.compare("TILE", Qt::CaseInsensitive) == 0) { - return DrawMode::TILE; + if (str.compare("Fixed", Qt::CaseInsensitive) == 0) { + return DrawMode::Fixed; + } else if (str.compare("Stretch", Qt::CaseInsensitive) == 0) { + return DrawMode::Stretch; + } else if (str.compare("StretchAspect", Qt::CaseInsensitive) == 0) { + return DrawMode::StretchAspect; + } else if (str.compare("Tile", Qt::CaseInsensitive) == 0) { + return DrawMode::Tile; } // Fall back on the implicit default from before Mixxx supported draw modes. qWarning() << "Unknown DrawMode string in DrawModeFromString:" - << str << "using FIXED"; - return DrawMode::FIXED; + << str << "using Fixed"; + return DrawMode::Fixed; } // static QString Paintable::DrawModeToString(DrawMode mode) { switch (mode) { - case DrawMode::FIXED: - return "FIXED"; - case DrawMode::STRETCH: - return "STRETCH"; - case DrawMode::STRETCH_ASPECT: - return "STRETCH_ASPECT"; - case DrawMode::TILE: - return "TILE"; + case DrawMode::Fixed: + return "Fixed"; + case DrawMode::Stretch: + return "Stretch"; + case DrawMode::StretchAspect: + return "StretchAspect"; + case DrawMode::Tile: + return "Tile"; } // Fall back on the implicit default from before Mixxx supported draw modes. qWarning() << "Unknown DrawMode in DrawModeToString " << static_cast(mode) - << "using FIXED"; - return "FIXED"; + << "using Fixed"; + return "Fixed"; } Paintable::Paintable(const PixmapSource& source, DrawMode mode, double scaleFactor) @@ -79,13 +79,13 @@ Paintable::Paintable(const PixmapSource& source, DrawMode mode, double scaleFact m_pSvg.reset(pSvg.release()); #ifdef __APPLE__ // Apple does Retina scaling behind the scenes, so we also pass a - // Paintable::FIXED image. On the other targets, it is better to - // cache the pixmap. We do not do this for TILE and color schemas. + // DrawMode::Fixed image. On the other targets, it is better to + // cache the pixmap. We do not do this for Tile and color schemas. // which can result in a correct but possibly blurry picture at a // Retina display. This can be fixed when switching to QT5 - if (mode == DrawMode::TILE || WPixmapStore::willCorrectColors()) { + if (mode == DrawMode::Tile || WPixmapStore::willCorrectColors()) { #else - if (mode == DrawMode::TILE || mode == DrawMode::FIXED || + if (mode == DrawMode::Tile || mode == DrawMode::Fixed || WPixmapStore::willCorrectColors()) { #endif // The SVG renderer doesn't directly support tiling, so we render @@ -170,7 +170,7 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, } switch (m_drawMode) { - case DrawMode::FIXED: { + case DrawMode::Fixed: { // Only render the minimum overlapping rectangle between the source // and target. QSizeF fixedSize(math_min(sourceRect.width(), targetRect.width()), @@ -180,7 +180,7 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, drawInternal(adjustedTarget, pPainter, adjustedSource); break; } - case DrawMode::STRETCH_ASPECT: { + case DrawMode::StretchAspect: { qreal sx = targetRect.width() / sourceRect.width(); qreal sy = targetRect.height() / sourceRect.height(); @@ -197,10 +197,10 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, } break; } - case DrawMode::STRETCH: + case DrawMode::Stretch: drawInternal(targetRect, pPainter, sourceRect); break; - case DrawMode::TILE: + case DrawMode::Tile: drawInternal(targetRect, pPainter, sourceRect); break; } @@ -209,7 +209,7 @@ void Paintable::draw(const QRectF& targetRect, QPainter* pPainter, void Paintable::drawCentered(const QRectF& targetRect, QPainter* pPainter, const QRectF& sourceRect) { switch (m_drawMode) { - case DrawMode::FIXED: { + case DrawMode::Fixed: { // Only render the minimum overlapping rectangle between the source // and target. QSizeF fixedSize(math_min(sourceRect.width(), targetRect.width()), @@ -222,7 +222,7 @@ void Paintable::drawCentered(const QRectF& targetRect, QPainter* pPainter, drawInternal(adjustedTarget, pPainter, adjustedSource); break; } - case DrawMode::STRETCH_ASPECT: { + case DrawMode::StretchAspect: { qreal sx = targetRect.width() / sourceRect.width(); qreal sy = targetRect.height() / sourceRect.height(); @@ -239,10 +239,10 @@ void Paintable::drawCentered(const QRectF& targetRect, QPainter* pPainter, } break; } - case DrawMode::STRETCH: + case DrawMode::Stretch: drawInternal(targetRect, pPainter, sourceRect); break; - case DrawMode::TILE: + case DrawMode::Tile: // TODO(XXX): What's the right behavior here? Draw the first tile at the // center point and then tile all around it based on that? drawInternal(targetRect, pPainter, sourceRect); @@ -255,7 +255,7 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter, // qDebug() << "Paintable::drawInternal" << DrawModeToString(m_draw_mode) // << targetRect << sourceRect; if (m_pPixmap) { - if (m_drawMode == DrawMode::TILE) { + if (m_drawMode == DrawMode::Tile) { // TODO(rryan): Using a source rectangle doesn't make much sense // with tiling. Ignore the source rect and tile our natural size // across the target rect. What's the right general behavior here? @@ -269,7 +269,7 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter, sourceRect.toRect()); } } else if (m_pSvg) { - if (m_drawMode == DrawMode::TILE) { + if (m_drawMode == DrawMode::Tile) { qWarning() << "Tiled SVG should have been rendered to pixmap!"; } else { // NOTE(rryan): QSvgRenderer render does not clip for us -- it diff --git a/src/widget/paintable.h b/src/widget/paintable.h index 19730fd36f4..d9a90c342b0 100644 --- a/src/widget/paintable.h +++ b/src/widget/paintable.h @@ -18,13 +18,13 @@ class Paintable { public: enum class DrawMode { // Draw the image in its native dimensions with no stretching or tiling. - FIXED, + Fixed, // Stretch the image. - STRETCH, + Stretch, // Stretch the image maintaining its aspect ratio. - STRETCH_ASPECT, + StretchAspect, // Tile the image. - TILE + Tile }; Paintable(const PixmapSource& source, DrawMode mode, double scaleFactor); diff --git a/src/widget/wbattery.cpp b/src/widget/wbattery.cpp index 0fcf0017c75..c94fe0c8051 100644 --- a/src/widget/wbattery.cpp +++ b/src/widget/wbattery.cpp @@ -25,7 +25,7 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { if (!backPath.isNull()) { setPixmap(&m_pPixmapBack, context.getPixmapSource(backPath), - context.selectScaleMode(backPath, Paintable::DrawMode::TILE), + context.selectScaleMode(backPath, Paintable::DrawMode::Tile), context.getScaleFactor()); } @@ -33,7 +33,7 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { if (!chargedPath.isNull()) { setPixmap(&m_pPixmapCharged, context.getPixmapSource(chargedPath), - context.selectScaleMode(chargedPath, Paintable::DrawMode::TILE), + context.selectScaleMode(chargedPath, Paintable::DrawMode::Tile), context.getScaleFactor()); } @@ -50,7 +50,7 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { // TODO(XXX) inline SVG support via context.getPixmapSource. QString chargingPath = context.nodeToString(pixmapsCharging); Paintable::DrawMode mode = context.selectScaleMode(pixmapsCharging, - Paintable::DrawMode::TILE); + Paintable::DrawMode::Tile); for (int i = 0; i < m_chargingPixmaps.size(); ++i) { PixmapSource source = context.getPixmapSource(chargingPath.arg(i)); setPixmap(&m_chargingPixmaps[i], source, mode, context.getScaleFactor()); @@ -62,7 +62,7 @@ void WBattery::setup(const QDomNode& node, const SkinContext& context) { // TODO(XXX) inline SVG support via context.getPixmapSource. QString dischargingPath = context.nodeToString(pixmapsDischarging); Paintable::DrawMode mode = context.selectScaleMode(pixmapsDischarging, - Paintable::DrawMode::TILE); + Paintable::DrawMode::Tile); for (int i = 0; i < m_dischargingPixmaps.size(); ++i) { PixmapSource source = context.getPixmapSource(dischargingPath.arg(i)); setPixmap(&m_dischargingPixmaps[i], source, mode, context.getScaleFactor()); @@ -148,7 +148,7 @@ void WBattery::setPixmap(PaintablePointer* ppPixmap, const PixmapSource& source, qDebug() << this << "Error loading pixmap:" << source.getPath(); } else { *ppPixmap = pPixmap; - if (mode == Paintable::DrawMode::FIXED) { + if (mode == Paintable::DrawMode::Fixed) { setFixedSize(pPixmap->size()); } } diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index d19d364c11b..bc0a28b8668 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -26,7 +26,7 @@ void WDisplay::setup(const QDomNode& node, const SkinContext& context) { QDomElement backPathNode = context.selectElement(node, "BackPath"); if (!backPathNode.isNull()) { setPixmapBackground(context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::DrawMode::TILE), + context.selectScaleMode(backPathNode, Paintable::DrawMode::Tile), context.getScaleFactor()); } @@ -39,7 +39,7 @@ void WDisplay::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode pathMode = - context.selectScaleMode(pathNode, Paintable::DrawMode::FIXED); + context.selectScaleMode(pathNode, Paintable::DrawMode::Fixed); for (int i = 0; i < m_pixmaps.size(); ++i) { setPixmap(&m_pixmaps, i, context.makeSkinPath(path.arg(i)), pathMode, context.getScaleFactor()); @@ -52,7 +52,7 @@ void WDisplay::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode disabledMode = - context.selectScaleMode(disabledNode, Paintable::DrawMode::FIXED); + context.selectScaleMode(disabledNode, Paintable::DrawMode::Fixed); for (int i = 0; i < m_disabledPixmaps.size(); ++i) { setPixmap(&m_disabledPixmaps, i, context.makeSkinPath(disabledPath.arg(i)), @@ -108,7 +108,7 @@ void WDisplay::setPixmap( << "Error loading pixmap:" << filename; } else { (*pPixmaps)[iPos] = pPixmap; - if (mode == Paintable::DrawMode::FIXED) { + if (mode == Paintable::DrawMode::Fixed) { setFixedSize(pPixmap->size()); } } diff --git a/src/widget/wknobcomposed.cpp b/src/widget/wknobcomposed.cpp index 93032336d36..a2ba7099bf9 100644 --- a/src/widget/wknobcomposed.cpp +++ b/src/widget/wknobcomposed.cpp @@ -33,7 +33,7 @@ void WKnobComposed::setup(const QDomNode& node, const SkinContext& context) { if (!backPathElement.isNull()) { setPixmapBackground( context.getPixmapSource(backPathElement), - context.selectScaleMode(backPathElement, Paintable::DrawMode::STRETCH), + context.selectScaleMode(backPathElement, Paintable::DrawMode::Stretch), scaleFactor); } @@ -42,7 +42,7 @@ void WKnobComposed::setup(const QDomNode& node, const SkinContext& context) { if (!knobNode.isNull()) { setPixmapKnob( context.getPixmapSource(knobNode), - context.selectScaleMode(knobNode, Paintable::DrawMode::STRETCH), + context.selectScaleMode(knobNode, Paintable::DrawMode::Stretch), scaleFactor); } diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 24f299b2fb5..e6e54ccfbe2 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -47,7 +47,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { // backwards compatibility. setPixmapBackground( backgroundSource, - context.selectScaleMode(backPathNode, Paintable::DrawMode::FIXED), + context.selectScaleMode(backPathNode, Paintable::DrawMode::Fixed), context.getScaleFactor()); } } @@ -97,7 +97,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode unpressedMode = - stateContext->selectScaleMode(unpressedNode, Paintable::DrawMode::FIXED); + stateContext->selectScaleMode(unpressedNode, Paintable::DrawMode::Fixed); if (!pixmapSource.isEmpty()) { setPixmap(iState, false, pixmapSource, unpressedMode, context.getScaleFactor()); @@ -108,7 +108,7 @@ void WPushButton::setup(const QDomNode& node, const SkinContext& context) { // The implicit default in <1.12.0 was FIXED so we keep it for // backwards compatibility. Paintable::DrawMode pressedMode = - stateContext->selectScaleMode(pressedNode, Paintable::DrawMode::FIXED); + stateContext->selectScaleMode(pressedNode, Paintable::DrawMode::Fixed); if (!pixmapSource.isEmpty()) { setPixmap(iState, true, pixmapSource, pressedMode, context.getScaleFactor()); @@ -265,7 +265,7 @@ void WPushButton::setPixmap(int iState, if (!source.isEmpty()) { qDebug() << "WPushButton: Error loading pixmap:" << source.getPath(); } - } else if (mode == Paintable::DrawMode::FIXED) { + } else if (mode == Paintable::DrawMode::Fixed) { // Set size of widget equal to pixmap size setFixedSize(pPixmap->size()); } diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index a6c2861b129..52c6c0c60d8 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -63,7 +63,7 @@ void WSliderComposed::setup(const QDomNode& node, const SkinContext& context) { PixmapSource sourceSlider = context.getPixmapSource(slider); setSliderPixmap( sourceSlider, - context.selectScaleMode(slider, Paintable::DrawMode::FIXED), + context.selectScaleMode(slider, Paintable::DrawMode::Fixed), scaleFactor); } @@ -76,7 +76,7 @@ void WSliderComposed::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setHandlePixmap( sourceHandle, - context.selectScaleMode(handle, Paintable::DrawMode::FIXED), + context.selectScaleMode(handle, Paintable::DrawMode::Fixed), scaleFactor); // Set up the level bar. @@ -183,7 +183,7 @@ void WSliderComposed::setSliderPixmap(const PixmapSource& sourceSlider, m_pSlider = WPixmapStore::getPaintable(sourceSlider, drawMode, scaleFactor); if (!m_pSlider) { qDebug() << "WSliderComposed: Error loading slider pixmap:" << sourceSlider.getPath(); - } else if (drawMode == Paintable::DrawMode::FIXED) { + } else if (drawMode == Paintable::DrawMode::Fixed) { // Set size of widget, using size of slider pixmap setFixedSize(m_pSlider->size()); } @@ -353,10 +353,10 @@ double WSliderComposed::calculateHandleLength() { Paintable::DrawMode mode = m_pHandle->drawMode(); if (m_bHorizontal) { // Stretch the pixmap to be the height of the widget. - if (mode == Paintable::DrawMode::FIXED || mode == Paintable::DrawMode::STRETCH || - mode == Paintable::DrawMode::TILE || m_pHandle->height() == 0.0) { + if (mode == Paintable::DrawMode::Fixed || mode == Paintable::DrawMode::Stretch || + mode == Paintable::DrawMode::Tile || m_pHandle->height() == 0.0) { return m_pHandle->width(); - } else if (mode == Paintable::DrawMode::STRETCH_ASPECT) { + } else if (mode == Paintable::DrawMode::StretchAspect) { const int iHeight = m_pHandle->height(); if (iHeight == 0) { qDebug() << "WSliderComposed: Invalid height."; @@ -368,10 +368,10 @@ double WSliderComposed::calculateHandleLength() { } } else { // Stretch the pixmap to be the width of the widget. - if (mode == Paintable::DrawMode::FIXED || mode == Paintable::DrawMode::STRETCH || - mode == Paintable::DrawMode::TILE || m_pHandle->width() == 0.0) { + if (mode == Paintable::DrawMode::Fixed || mode == Paintable::DrawMode::Stretch || + mode == Paintable::DrawMode::Tile || m_pHandle->width() == 0.0) { return m_pHandle->height(); - } else if (mode == Paintable::DrawMode::STRETCH_ASPECT) { + } else if (mode == Paintable::DrawMode::StretchAspect) { const int iWidth = m_pHandle->width(); if (iWidth == 0) { qDebug() << "WSliderComposed: Invalid width."; diff --git a/src/widget/wspinnybase.cpp b/src/widget/wspinnybase.cpp index eda433f9fc9..a0baf58f70e 100644 --- a/src/widget/wspinnybase.cpp +++ b/src/widget/wspinnybase.cpp @@ -146,8 +146,8 @@ void WSpinnyBase::setup(const QDomNode& node, m_pBgImage = WImageStore::getImage(context.getPixmapSource(backPathElement), context.getScaleFactor()); Paintable::DrawMode bgmode = context.selectScaleMode(backPathElement, - Paintable::DrawMode::FIXED); - if (m_pBgImage && !m_pBgImage->isNull() && bgmode == Paintable::DrawMode::FIXED) { + Paintable::DrawMode::Fixed); + if (m_pBgImage && !m_pBgImage->isNull() && bgmode == Paintable::DrawMode::Fixed) { setFixedSize(m_pBgImage->size()); } else { setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index 7c88d94f564..42af3c4c06b 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -43,7 +43,7 @@ void WStatusLight::setup(const QDomNode& node, const SkinContext& context) { setPixmap(i, context.getPixmapSource(statusLightNode), context.selectScaleMode( - statusLightNode, Paintable::DrawMode::FIXED), + statusLightNode, Paintable::DrawMode::Fixed), context.getScaleFactor()); } else { m_pixmaps[i].reset(); @@ -64,7 +64,7 @@ void WStatusLight::setPixmap(int iState, PaintablePointer pPixmap = WPixmapStore::getPaintable(source, mode, scaleFactor); if (pPixmap && !pPixmap->isNull()) { m_pixmaps[iState] = pPixmap; - if (mode == Paintable::DrawMode::FIXED) { + if (mode == Paintable::DrawMode::Fixed) { setFixedSize(pPixmap->size()); } } else { diff --git a/src/widget/wvumeterbase.cpp b/src/widget/wvumeterbase.cpp index 06e8f415b83..c94309a7979 100644 --- a/src/widget/wvumeterbase.cpp +++ b/src/widget/wvumeterbase.cpp @@ -46,7 +46,7 @@ void WVuMeterBase::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmapBackground( context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::DrawMode::FIXED), + context.selectScaleMode(backPathNode, Paintable::DrawMode::Fixed), context.getScaleFactor()); } @@ -55,7 +55,7 @@ void WVuMeterBase::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmaps(context.getPixmapSource(vuNode), bHorizontal, - context.selectScaleMode(vuNode, Paintable::DrawMode::FIXED), + context.selectScaleMode(vuNode, Paintable::DrawMode::Fixed), context.getScaleFactor()); m_iPeakHoldSize = context.selectInt(node, "PeakHoldSize"); @@ -98,7 +98,7 @@ void WVuMeterBase::setPixmapBackground( if (!m_pPixmapBack) { qDebug() << metaObject()->className() << "Error loading background pixmap:" << source.getPath(); - } else if (mode == Paintable::DrawMode::FIXED) { + } else if (mode == Paintable::DrawMode::Fixed) { setFixedSize(m_pPixmapBack->size()); } } diff --git a/src/widget/wvumeterlegacy.cpp b/src/widget/wvumeterlegacy.cpp index c0dc3feb02a..cd649b0dfb4 100644 --- a/src/widget/wvumeterlegacy.cpp +++ b/src/widget/wvumeterlegacy.cpp @@ -41,7 +41,7 @@ void WVuMeterLegacy::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmapBackground( context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::DrawMode::FIXED), + context.selectScaleMode(backPathNode, Paintable::DrawMode::Fixed), context.getScaleFactor()); } @@ -50,7 +50,7 @@ void WVuMeterLegacy::setup(const QDomNode& node, const SkinContext& context) { // compatibility. setPixmaps(context.getPixmapSource(vuNode), bHorizontal, - context.selectScaleMode(vuNode, Paintable::DrawMode::FIXED), + context.selectScaleMode(vuNode, Paintable::DrawMode::Fixed), context.getScaleFactor()); m_iPeakHoldSize = context.selectInt(node, "PeakHoldSize"); @@ -84,7 +84,7 @@ void WVuMeterLegacy::setPixmapBackground( if (!m_pPixmapBack || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() << "Error loading background pixmap:" << source.getPath(); - } else if (mode == Paintable::DrawMode::FIXED) { + } else if (mode == Paintable::DrawMode::Fixed) { setFixedSize(m_pPixmapBack->size()); } } diff --git a/src/widget/wwidgetgroup.cpp b/src/widget/wwidgetgroup.cpp index 791d9f1668b..fa37e43c05a 100644 --- a/src/widget/wwidgetgroup.cpp +++ b/src/widget/wwidgetgroup.cpp @@ -103,7 +103,7 @@ void WWidgetGroup::setup(const QDomNode& node, const SkinContext& context) { if (!backPathNode.isNull()) { setPixmapBackground( context.getPixmapSource(backPathNode), - context.selectScaleMode(backPathNode, Paintable::DrawMode::TILE), + context.selectScaleMode(backPathNode, Paintable::DrawMode::Tile), context.getScaleFactor()); } @@ -113,7 +113,7 @@ void WWidgetGroup::setup(const QDomNode& node, const SkinContext& context) { if (!backPathNodeHighlighted.isNull()) { setPixmapBackgroundHighlighted( context.getPixmapSource(backPathNodeHighlighted), - context.selectScaleMode(backPathNodeHighlighted, Paintable::DrawMode::TILE), + context.selectScaleMode(backPathNodeHighlighted, Paintable::DrawMode::Tile), context.getScaleFactor()); } From ab99424b8ef2ca4163c4b12e6d766fb70bfd9ca3 Mon Sep 17 00:00:00 2001 From: Joerg Date: Mon, 1 Jul 2024 20:16:22 +0200 Subject: [PATCH 3/4] Implemented fast map lookup for backward compatible DrawMode strings --- src/widget/paintable.cpp | 52 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index 2acd78cc642..e7ffb01350b 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -15,39 +15,39 @@ // static Paintable::DrawMode Paintable::DrawModeFromString(const QString& str) { - if (str.compare("Fixed", Qt::CaseInsensitive) == 0) { + static const QMap stringMap = { + {"FIXED", DrawMode::Fixed}, + {"STRETCH", DrawMode::Stretch}, + {"STRETCH_ASPECT", DrawMode::StretchAspect}, + {"TILE", DrawMode::Tile}}; + + auto it = stringMap.find(str.toUpper()); + if (it != stringMap.end()) { + return it.value(); + } else { + qWarning() << "Unknown DrawMode string passed to DrawModeFromString:" + << str << "using DrawMode::Fixed as fallback"; return DrawMode::Fixed; - } else if (str.compare("Stretch", Qt::CaseInsensitive) == 0) { - return DrawMode::Stretch; - } else if (str.compare("StretchAspect", Qt::CaseInsensitive) == 0) { - return DrawMode::StretchAspect; - } else if (str.compare("Tile", Qt::CaseInsensitive) == 0) { - return DrawMode::Tile; } - - // Fall back on the implicit default from before Mixxx supported draw modes. - qWarning() << "Unknown DrawMode string in DrawModeFromString:" - << str << "using Fixed"; - return DrawMode::Fixed; } // static QString Paintable::DrawModeToString(DrawMode mode) { - switch (mode) { - case DrawMode::Fixed: - return "Fixed"; - case DrawMode::Stretch: - return "Stretch"; - case DrawMode::StretchAspect: - return "StretchAspect"; - case DrawMode::Tile: - return "Tile"; - } - // Fall back on the implicit default from before Mixxx supported draw modes. - qWarning() << "Unknown DrawMode in DrawModeToString " << static_cast(mode) + static const QMap modeMap = { + {DrawMode::Fixed, "FIXED"}, + {DrawMode::Stretch, "STRETCH"}, + {DrawMode::StretchAspect, "STRETCH_ASPECT"}, + {DrawMode::Tile, "TILE"}}; - << "using Fixed"; - return "Fixed"; + auto it = modeMap.find(mode); + if (it != modeMap.end()) { + return it.value(); + } else { + qWarning() << "Unknown DrawMode passed to DrawModeToString " + << static_cast(mode) << "using FIXED as fallback"; + DEBUG_ASSERT(false); + return "FIXED"; + } } Paintable::Paintable(const PixmapSource& source, DrawMode mode, double scaleFactor) From 74fac0ad1b96dc2dc2527b81738cdb5575436138 Mon Sep 17 00:00:00 2001 From: Joerg Date: Mon, 1 Jul 2024 21:24:24 +0200 Subject: [PATCH 4/4] Use early return style --- src/widget/paintable.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widget/paintable.cpp b/src/widget/paintable.cpp index 2e6058981a0..a2d337687d3 100644 --- a/src/widget/paintable.cpp +++ b/src/widget/paintable.cpp @@ -22,13 +22,13 @@ Paintable::DrawMode Paintable::DrawModeFromString(const QString& str) { {"TILE", DrawMode::Tile}}; auto it = stringMap.find(str.toUpper()); - if (it != stringMap.end()) { - return it.value(); - } else { + if (it == stringMap.end()) { qWarning() << "Unknown DrawMode string passed to DrawModeFromString:" << str << "using DrawMode::Fixed as fallback"; return DrawMode::Fixed; } + + return it.value(); } // static @@ -40,14 +40,14 @@ QString Paintable::DrawModeToString(DrawMode mode) { {DrawMode::Tile, "TILE"}}; auto it = modeMap.find(mode); - if (it != modeMap.end()) { - return it.value(); - } else { + if (it == modeMap.end()) { qWarning() << "Unknown DrawMode passed to DrawModeToString " << static_cast(mode) << "using FIXED as fallback"; DEBUG_ASSERT(false); return "FIXED"; } + + return it.value(); } Paintable::Paintable(const PixmapSource& source, DrawMode mode, double scaleFactor)