diff options
-rw-r--r-- | res/skins/LateNight/deck.xml | 6 | ||||
-rw-r--r-- | src/widget/wdisplay.cpp | 40 | ||||
-rw-r--r-- | src/widget/wdisplay.h | 2 | ||||
-rw-r--r-- | src/widget/wknobcomposed.cpp | 32 | ||||
-rw-r--r-- | src/widget/wknobcomposed.h | 2 | ||||
-rw-r--r-- | src/widget/wpushbutton.cpp | 43 | ||||
-rw-r--r-- | src/widget/wpushbutton.h | 3 | ||||
-rw-r--r-- | src/widget/wslidercomposed.cpp | 106 | ||||
-rw-r--r-- | src/widget/wslidercomposed.h | 6 | ||||
-rw-r--r-- | src/widget/wstatuslight.cpp | 55 | ||||
-rw-r--r-- | src/widget/wstatuslight.h | 8 | ||||
-rw-r--r-- | src/widget/wvumeter.cpp | 28 | ||||
-rw-r--r-- | src/widget/wvumeter.h | 5 | ||||
-rw-r--r-- | src/widget/wwidgetgroup.cpp | 7 |
14 files changed, 173 insertions, 170 deletions
diff --git a/res/skins/LateNight/deck.xml b/res/skins/LateNight/deck.xml index a650fdd8b1..290f8f6085 100644 --- a/res/skins/LateNight/deck.xml +++ b/res/skins/LateNight/deck.xml @@ -322,9 +322,9 @@ <Size>2me,10f</Size> <TooltipId>vinylcontrol_status</TooltipId> <NumberPos>3</NumberPos> - <PathStatusLight sizemode="RESIZE">btn_vinylcontrol_indicator_horizontal1.png</PathStatusLight> - <PathStatusLight2 sizemode="RESIZE">btn_vinylcontrol_indicator_horizontal2.png</PathStatusLight2> - <PathStatusLight3 sizemode="RESIZE">btn_vinylcontrol_indicator_horizontal3.png</PathStatusLight3> + <PathStatusLight scalemode="STRETCH">btn_vinylcontrol_indicator_horizontal1.png</PathStatusLight> + <PathStatusLight2 scalemode="STRETCH">btn_vinylcontrol_indicator_horizontal2.png</PathStatusLight2> + <PathStatusLight3 scalemode="STRETCH">btn_vinylcontrol_indicator_horizontal3.png</PathStatusLight3> <Connection> <ConfigKey>[Channel<Variable name="channum"/>],vinylcontrol_status</ConfigKey> </Connection> diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index 81eaddc969..e0a613195b 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -40,28 +40,36 @@ WDisplay::~WDisplay() { void WDisplay::setup(QDomNode node, const SkinContext& context) { // Set background pixmap if available if (context.hasNode(node, "BackPath")) { - QString mode_str = context.selectAttributeString( - context.selectElement(node, "BackPath"), "scalemode", "TILE"); - setPixmapBackground(context.getPixmapSource(context.selectNode(node, "BackPath")), - Paintable::DrawModeFromString(mode_str)); + QDomElement backPathNode = context.selectElement(node, "BackPath"); + setPixmapBackground(context.getPixmapSource(backPathNode), + context.selectScaleMode(backPathNode, Paintable::TILE)); } // Number of states setPositions(context.selectInt(node, "NumberStates")); - // Load knob pixmaps - QString path = context.selectString(node, "Path"); + QDomElement pathNode = context.selectElement(node, "Path"); + QString path = context.nodeToString(pathNode); + // The implicit default in <1.12.0 was FIXED so we keep it for + // backwards compatibility. + Paintable::DrawMode pathMode = + context.selectScaleMode(pathNode, Paintable::FIXED); for (int i = 0; i < m_pixmaps.size(); ++i) { - setPixmap(&m_pixmaps, i, context.getSkinPath(path.arg(i))); + setPixmap(&m_pixmaps, i, context.getSkinPath(path.arg(i)), pathMode); } // See if disabled images is defined, and load them... if (context.hasNode(node, "DisabledPath")) { - QString disabledPath = context.selectString(node, "DisabledPath"); + QDomElement disabledNode = context.selectElement(node, "DisabledPath"); + QString disabledPath = context.nodeToString(disabledNode); + // The implicit default in <1.12.0 was FIXED so we keep it for + // backwards compatibility. + Paintable::DrawMode disabledMode = + context.selectScaleMode(disabledNode, Paintable::FIXED); for (int i = 0; i < m_disabledPixmaps.size(); ++i) { setPixmap(&m_disabledPixmaps, i, - context.getSkinPath(disabledPath.arg(i))); + context.getSkinPath(disabledPath.arg(i)), disabledMode); } m_bDisabledLoaded = true; } @@ -96,21 +104,21 @@ void WDisplay::setPixmapBackground(PixmapSource source, } void WDisplay::setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos, - const QString& filename) { + const QString& filename, Paintable::DrawMode mode) { if (iPos < 0 || iPos >= pPixmaps->size()) { return; } PixmapSource source(filename); - PaintablePointer pPixmap = WPixmapStore::getPaintable(source, - Paintable::TILE); - + PaintablePointer pPixmap = WPixmapStore::getPaintable(source, mode); if (pPixmap.isNull() || pPixmap->isNull()) { qDebug() << metaObject()->className() << "Error loading pixmap:" << filename; } else { (*pPixmaps)[iPos] = pPixmap; - setFixedSize(pPixmap->size()); + if (mode == Paintable::FIXED) { + setFixedSize(pPixmap->size()); + } } } @@ -170,7 +178,7 @@ void WDisplay::paintEvent(QPaintEvent*) { p.drawPrimitive(QStyle::PE_Widget, option); if (m_pPixmapBack) { - m_pPixmapBack->draw(0, 0, &p); + m_pPixmapBack->draw(rect(), &p); } // If we are disabled, use the disabled pixmaps. If not, use the regular @@ -197,6 +205,6 @@ void WDisplay::paintEvent(QPaintEvent*) { PaintablePointer pPixmap = pixmaps[idx]; if (pPixmap) { - pPixmap->draw(0, 0, &p); + pPixmap->draw(rect(), &p); } } diff --git a/src/widget/wdisplay.h b/src/widget/wdisplay.h index 26433ee85d..7d99542f82 100644 --- a/src/widget/wdisplay.h +++ b/src/widget/wdisplay.h @@ -46,7 +46,7 @@ class WDisplay : public WWidget { private: void setPixmap(QVector<PaintablePointer>* pPixmaps, int iPos, - const QString& filename); + const QString& filename, Paintable::DrawMode mode); void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); diff --git a/src/widget/wknobcomposed.cpp b/src/widget/wknobcomposed.cpp index 79337cafe6..f37f63b56b 100644 --- a/src/widget/wknobcomposed.cpp +++ b/src/widget/wknobcomposed.cpp @@ -1,5 +1,6 @@ #include <QStylePainter> #include <QStyleOption> +#include <QTransform> #include "widget/wknobcomposed.h" @@ -18,15 +19,16 @@ void WKnobComposed::setup(QDomNode node, const SkinContext& context) { // Set background pixmap if available if (context.hasNode(node, "BackPath")) { - QString mode_str = context.selectAttributeString( - context.selectElement(node, "BackPath"), "scalemode", "TILE"); - setPixmapBackground(context.getPixmapSource(context.selectNode(node, "BackPath")), - Paintable::DrawModeFromString(mode_str)); + QDomElement backPathElement = context.selectElement(node, "BackPath"); + setPixmapBackground(context.getPixmapSource(backPathElement), + context.selectScaleMode(backPathElement, Paintable::TILE)); } - // Set background pixmap if available + // Set knob pixmap if available if (context.hasNode(node, "Knob")) { - setPixmapKnob(context.getPixmapSource(context.selectNode(node, "Knob"))); + QDomElement knobNode = context.selectElement(node, "Knob"); + setPixmapKnob(context.getPixmapSource(knobNode), + context.selectScaleMode(knobNode, Paintable::STRETCH)); } if (context.hasNode(node, "MinAngle")) { @@ -52,8 +54,9 @@ void WKnobComposed::setPixmapBackground(PixmapSource source, } } -void WKnobComposed::setPixmapKnob(PixmapSource source) { - m_pKnob = WPixmapStore::getPaintable(source, Paintable::STRETCH); +void WKnobComposed::setPixmapKnob(PixmapSource source, + Paintable::DrawMode mode) { + m_pKnob = WPixmapStore::getPaintable(source, mode); if (m_pKnob.isNull() || m_pKnob->isNull()) { qDebug() << metaObject()->className() << "Error loading knob pixmap:" << source.getPath(); @@ -83,18 +86,25 @@ void WKnobComposed::paintEvent(QPaintEvent* e) { p.drawPrimitive(QStyle::PE_Widget, option); if (m_pPixmapBack) { - m_pPixmapBack->draw(0, 0, &p); + m_pPixmapBack->draw(rect(), &p); } + QTransform transform; if (!m_pKnob.isNull() && !m_pKnob->isNull()) { - p.translate(width() / 2.0, height() / 2.0); + qreal tx = width() / 2.0; + qreal ty = height() / 2.0; + transform.translate(-tx, -ty); + p.translate(tx, ty); // We update m_dCurrentAngle since onConnectedControlChanged uses it for // no-op detection. m_dCurrentAngle = m_dMinAngle + (m_dMaxAngle - m_dMinAngle) * getControlParameterDisplay(); p.rotate(m_dCurrentAngle); - m_pKnob->draw(-m_pKnob->width() / 2.0, -m_pKnob->height() / 2.0, &p); + // Need to convert from QRect to a QRectF to avoid losing precison. + QRectF targetRect = rect(); + m_pKnob->drawCentered(transform.mapRect(targetRect), &p, + m_pKnob->rect()); } } diff --git a/src/widget/wknobcomposed.h b/src/widget/wknobcomposed.h index decb5d2bbd..404a146012 100644 --- a/src/widget/wknobcomposed.h +++ b/src/widget/wknobcomposed.h @@ -32,7 +32,7 @@ class WKnobComposed : public WWidget { private: void clear(); void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); - void setPixmapKnob(PixmapSource source); + void setPixmapKnob(PixmapSource source, Paintable::DrawMode mode); double m_dCurrentAngle; PaintablePointer m_pKnob; diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 294d1503a9..5c82126893 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -58,11 +58,13 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { // Set background pixmap if available if (context.hasNode(node, "BackPath")) { - QString mode_str = context.selectAttributeString( - context.selectElement(node, "BackPath"), "scalemode", "TILE"); - PixmapSource backgroundSource = context.getPixmapSource(context.selectNode(node, "BackPath")); + QDomElement backPathNode = context.selectElement(node, "BackPath"); + PixmapSource backgroundSource = context.getPixmapSource(backPathNode); if (!backgroundSource.isEmpty()) { - setPixmapBackground(backgroundSource, Paintable::DrawModeFromString(mode_str)); + // The implicit default in <1.12.0 was FIXED so we keep it for + // backwards compatibility. + setPixmapBackground(backgroundSource, + context.selectScaleMode(backPathNode, Paintable::FIXED)); } } @@ -77,16 +79,24 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { int iState = stateContext.selectInt(state, "Number"); if (iState < m_iNoStates) { - PixmapSource pixmapSource = stateContext.getPixmapSource( - stateContext.selectNode(state, "Unpressed")); + QDomElement unpressedNode = stateContext.selectElement(state, "Unpressed"); + PixmapSource pixmapSource = stateContext.getPixmapSource(unpressedNode); + // The implicit default in <1.12.0 was FIXED so we keep it for + // backwards compatibility. + Paintable::DrawMode unpressedMode = + stateContext.selectScaleMode(unpressedNode, Paintable::FIXED); if (!pixmapSource.isEmpty()) { - setPixmap(iState, false, pixmapSource); + setPixmap(iState, false, pixmapSource, unpressedMode); } - pixmapSource = stateContext.getPixmapSource( - stateContext.selectNode(state, "Pressed")); + QDomElement pressedNode = stateContext.selectElement(state, "Pressed"); + pixmapSource = stateContext.getPixmapSource(pressedNode); + // The implicit default in <1.12.0 was FIXED so we keep it for + // backwards compatibility. + Paintable::DrawMode pressedMode = + stateContext.selectScaleMode(pressedNode, Paintable::FIXED); if (!pixmapSource.isEmpty()) { - setPixmap(iState, true, pixmapSource); + setPixmap(iState, true, pixmapSource, pressedMode); } m_text.replace(iState, stateContext.selectString(state, "Text")); @@ -205,7 +215,8 @@ void WPushButton::setStates(int iStates) { m_align.resize(iStates); } -void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource source) { +void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource source, + Paintable::DrawMode mode) { QVector<PaintablePointer>& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -213,15 +224,13 @@ void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource source) { return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(source, - Paintable::STRETCH); - + PaintablePointer pPixmap = WPixmapStore::getPaintable(source, mode); if (pPixmap.isNull() || pPixmap->isNull()) { // Only log if it looks like the user tried to specify a pixmap. if (!source.isEmpty()) { qDebug() << "WPushButton: Error loading pixmap:" << source.getPath(); } - } else { + } else if (mode == Paintable::FIXED) { // Set size of widget equal to pixmap size setFixedSize(pPixmap->size()); } @@ -277,7 +286,7 @@ void WPushButton::paintEvent(QPaintEvent* e) { } if (m_pPixmapBack) { - m_pPixmapBack->draw(0, 0, &p); + m_pPixmapBack->draw(rect(), &p); } const QVector<PaintablePointer>& pixmaps = m_bPressed ? @@ -300,7 +309,7 @@ void WPushButton::paintEvent(QPaintEvent* e) { PaintablePointer pPixmap = pixmaps.at(idx); if (!pPixmap.isNull() && !pPixmap->isNull()) { - pPixmap->draw(0, 0, &p); + pPixmap->draw(rect(), &p); } QString text = m_text.at(idx); diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index 99f62f79de..5433e47e9e 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -86,7 +86,8 @@ class WPushButton : public WWidget { void restyleAndRepaint(); // Associates a pixmap of a given state of the button with the widget - void setPixmap(int iState, bool bPressed, PixmapSource source); + void setPixmap(int iState, bool bPressed, PixmapSource source, + Paintable::DrawMode mode); // Associates a background pixmap with the widget. This is only needed if // the button pixmaps contains alpha channel values. diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index 98e4a4ff9c..810ccec223 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -50,13 +50,20 @@ void WSliderComposed::setup(QDomNode node, const SkinContext& context) { unsetPixmaps(); if (context.hasNode(node, "Slider")) { - PixmapSource sourceSlider = context.getPixmapSource(context.selectNode(node, "Slider")); - setSliderPixmap(sourceSlider); + QDomElement slider = context.selectElement(node, "Slider"); + // The implicit default in <1.12.0 was FIXED so we keep it for backwards + // compatibility. + PixmapSource sourceSlider = context.getPixmapSource(slider); + setSliderPixmap(sourceSlider, context.selectScaleMode(slider, Paintable::FIXED)); } - PixmapSource sourceHandle = context.getPixmapSource(context.selectNode(node, "Handle")); + QDomElement handle = context.selectElement(node, "Handle"); + PixmapSource sourceHandle = context.getPixmapSource(handle); bool h = context.selectBool(node, "Horizontal", false); - setHandlePixmap(h, sourceHandle); + // The implicit default in <1.12.0 was FIXED so we keep it for backwards + // compatibility. + setHandlePixmap(h, sourceHandle, + context.selectScaleMode(handle, Paintable::FIXED)); if (context.hasNode(node, "EventWhileDrag")) { if (context.selectString(node, "EventWhileDrag").contains("no")) { @@ -76,44 +83,26 @@ void WSliderComposed::setup(QDomNode node, const SkinContext& context) { } } -void WSliderComposed::setSliderPixmap(PixmapSource sourceSlider) { - m_pSlider = WPixmapStore::getPaintable(sourceSlider, - Paintable::STRETCH); +void WSliderComposed::setSliderPixmap(PixmapSource sourceSlider, + Paintable::DrawMode drawMode) { + m_pSlider = WPixmapStore::getPaintable(sourceSlider, drawMode); if (!m_pSlider) { qDebug() << "WSliderComposed: Error loading slider pixmap:" << sourceSlider.getPath(); - } else { + } else if (drawMode == Paintable::FIXED) { // Set size of widget, using size of slider pixmap setFixedSize(m_pSlider->size()); } } -void WSliderComposed::setHandlePixmap(bool bHorizontal, PixmapSource sourceHandle) { +void WSliderComposed::setHandlePixmap(bool bHorizontal, + PixmapSource sourceHandle, + Paintable::DrawMode mode) { m_bHorizontal = bHorizontal; - m_pHandle = WPixmapStore::getPaintable(sourceHandle, - Paintable::STRETCH); + m_pHandle = WPixmapStore::getPaintable(sourceHandle, mode); + m_dHandleLength = calculateHandleLength(); if (!m_pHandle) { qDebug() << "WSliderComposed: Error loading handle pixmap:" << sourceHandle.getPath(); } else { - if (m_bHorizontal) { - // Stretch the pixmap to be the height of the widget. - if (m_pHandle->height() != 0.0) { - const qreal aspect = static_cast<double>(m_pHandle->width()) / - static_cast<double>(m_pHandle->height()); - m_dHandleLength = aspect * height(); - } else { - m_dHandleLength = m_pHandle->width(); - } - } else { - // Stretch the pixmap to be the width of the widget. - if (m_pHandle->width() != 0.0) { - const qreal aspect = static_cast<double>(m_pHandle->height()) / - static_cast<double>(m_pHandle->width()); - m_dHandleLength = aspect * width(); - } else { - m_dHandleLength = m_pHandle->height(); - } - } - // Value is unused in WSliderComposed. onConnectedControlChanged(getControlParameter(), 0); update(); @@ -220,16 +209,16 @@ void WSliderComposed::paintEvent(QPaintEvent *) { p.drawPrimitive(QStyle::PE_Widget, option); if (!m_pSlider.isNull() && !m_pSlider->isNull()) { - m_pSlider->draw(0, 0, &p); + m_pSlider->draw(rect(), &p); } if (!m_pHandle.isNull() && !m_pHandle->isNull()) { if (m_bHorizontal) { - // Stretch the pixmap to be the height of the widget. + // The handle's draw mode determines whether it is stretched. QRectF targetRect(m_dPos, 0, m_dHandleLength, height()); m_pHandle->draw(targetRect, &p); } else { - // Stretch the pixmap to be the width of the widget. + // The handle's draw mode determines whether it is stretched. QRectF targetRect(0, m_dPos, width(), m_dHandleLength); m_pHandle->draw(targetRect, &p); } @@ -240,26 +229,7 @@ void WSliderComposed::resizeEvent(QResizeEvent* pEvent) { Q_UNUSED(pEvent); m_dOldValue = -1; m_dPos = -1; - - if (m_bHorizontal) { - // Stretch the pixmap to be the height of the widget. - if (m_pHandle->height() != 0.0) { - const qreal aspect = static_cast<double>(m_pHandle->width()) / - static_cast<double>(m_pHandle->height()); - m_dHandleLength = aspect * height(); - } else { - m_dHandleLength = m_pHandle->width(); - } - } else { - // Stretch the pixmap to be the width of the widget. - if (m_pHandle->width() != 0.0) { - const qreal aspect = static_cast<double>(m_pHandle->height()) / - static_cast<double>(m_pHandle->width()); - m_dHandleLength = aspect * width(); - } else { - m_dHandleLength = m_pHandle->height(); - } - } + m_dHandleLength = calculateHandleLength(); // Re-calculate m_dPos based on our new width/height. onConnectedControlChanged(getControlParameter(), 0); @@ -310,3 +280,31 @@ void WSliderComposed::fillDebugTooltip(QStringList* debug) { << QString("SliderLength: %1").arg(sliderLength) << QString("HandleLength: %1").arg(m_dHandleLength); } + +double WSliderComposed::calculateHandleLength() { + if (m_pHandle) { + 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) { + return m_pHandle->width(); + } else if (mode == Paintable::STRETCH_ASPECT) { + const qreal aspect = static_cast<double>(m_pHandle->width()) / + static_cast<double>(m_pHandle->height()); + return aspect * height(); + } + } 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) { + return m_pHandle->height(); + } else if (mode == Paintable::STRETCH_ASPECT) { + const qreal aspect = static_cast<double>(m_pHandle->height()) / + static_cast<double>(m_pHandle->width()); + return aspect * width(); + } + } + } + return 0; +} diff --git a/src/widget/wslidercomposed.h b/src/widget/wslidercomposed.h index 6e570d9ab3..c5f21387e8 100644 --- a/src/widget/wslidercomposed.h +++ b/src/widget/wslidercomposed.h @@ -43,8 +43,9 @@ class WSliderComposed : public WWidget { virtual ~WSliderComposed(); void setup(QDomNode node, const SkinContext& context); - void setSliderPixmap(PixmapSource sourceSlider); - void setHandlePixmap(bool bHorizontal, PixmapSource sourceHandle); + void setSliderPixmap(PixmapSource sourceSlider, Paintable::DrawMode mode); + void setHandlePixmap(bool bHorizontal, PixmapSource sourceHandle, + Paintable::DrawMode mode); inline bool isHorizontal() const { return m_bHorizontal; }; public slots: @@ -60,6 +61,7 @@ class WSliderComposed : public WWidget { virtual void resizeEvent(QResizeEvent* e); private: + double calculateHandleLength(); void unsetPixmaps(); double m_dOldValue; diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index 773ea43d65..5b38a5d9f5 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -47,16 +47,6 @@ void WStatusLight::setNoPos(int iNoPos) { m_pixmaps.resize(iNoPos); } -WStatusLight::SizeMode WStatusLight::SizeModeFromString(QString str) { - if (str.toUpper() == "FIXED") { - return FIXED; - } else if (str.toUpper() == "RESIZE") { - return RESIZE; - } - qWarning() << "Unknown status light size mode " << str << ", using FIXED"; - return FIXED; -} - void WStatusLight::setup(QDomNode node, const SkinContext& context) { // Number of states. Add one to account for the background. setNoPos(context.selectInt(node, "NumberPos") + 1); @@ -66,49 +56,34 @@ void WStatusLight::setup(QDomNode node, const SkinContext& context) { // Accept either PathStatusLight or PathStatusLight1 for value 1, QString nodeName = QString("PathStatusLight%1").arg(i); if (context.hasNode(node, nodeName)) { - QString mode = context.selectAttributeString( - context.selectElement(node, nodeName), "sizemode", "FIXED"); - setPixmap(i, context.getPixmapSource(context.selectNode(node, nodeName)), - SizeModeFromString(mode)); + QDomElement statusLightNode = context.selectElement(node, nodeName); + setPixmap(i, context.getPixmapSource(statusLightNode), + context.selectScaleMode(statusLightNode, Paintable::FIXED)); } else if (i == 0 && context.hasNode(node, "PathBack")) { - QString mode = context.selectAttributeString( - context.selectElement(node, "PathBack"), "sizemode", "FIXED"); - setPixmap(i, context.getPixmapSource(context.selectNode(node, "PathBack")), - SizeModeFromString(mode)); + QDomElement statusLightNode = context.selectElement(node, "PathBack"); + setPixmap(i, context.getPixmapSource(statusLightNode), + context.selectScaleMode(statusLightNode, Paintable::FIXED)); } else if (i == 1 && context.hasNode(node, "PathStatusLight")) { - QString mode = context.selectAttributeString( - context.selectElement(node, "PathStatusLight"), "sizemode", "FIXED"); - setPixmap(i, context.getPixmapSource(context.selectNode(node, "PathStatusLight")), - SizeModeFromString(mode)); + QDomElement statusLightNode = context.selectElement(node, "PathStatusLight"); + setPixmap(i, context.getPixmapSource(statusLightNode), + context.selectScaleMode(statusLightNode, Paintable::FIXED)); } else { m_pixmaps[i].clear(); } } } -void WStatusLight::setPixmap(int iState, PixmapSource source, SizeMode mode) { +void WStatusLight::setPixmap(int iState, PixmapSource source, + Paintable::DrawMode mode) { if (iState < 0 || iState >= m_pixmaps.size()) { return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(source, - Paintable::STRETCH); - + PaintablePointer pPixmap = WPixmapStore::getPaintable(source, mode); if (!pPixmap.isNull() && !pPixmap->isNull()) { m_pixmaps[iState] = pPixmap; - - switch (mode) { - case RESIZE: - // Allow the pixmap to stretch or tile. - setBaseSize(pPixmap->size()); - break; - case FIXED: - // Set size of widget equal to pixmap size - setFixedSize(pPixmap->size()); - break; - default: - setFixedSize(pPixmap->size()); - break; + if (mode == Paintable::FIXED) { + setFixedSize(pPixmap->size()); } } else { qDebug() << "WStatusLight: Error loading pixmap:" << source.getPath() << iState; @@ -155,5 +130,5 @@ void WStatusLight::paintEvent(QPaintEvent *) { return; } - pPixmap->draw(0, 0, &p); + pPixmap->draw(rect(), &p); } diff --git a/src/widget/wstatuslight.h b/src/widget/wstatuslight.h index 4c241cd48f..b6419f22bf 100644 --- a/src/widget/wstatuslight.h +++ b/src/widget/wstatuslight.h @@ -34,16 +34,10 @@ class WStatusLight : public WWidget { Q_OBJECT public: - enum SizeMode { - FIXED, - RESIZE, - }; - WStatusLight(QWidget *parent=0); virtual ~WStatusLight(); void setup(QDomNode node, const SkinContext& context); - static SizeMode SizeModeFromString(QString str); public slots: void onConnectedControlChanged(double dParameter, double dValue); @@ -52,7 +46,7 @@ class WStatusLight : public WWidget { void paintEvent(QPaintEvent *); private: - void setPixmap(int iState, PixmapSource source, SizeMode mode); + void setPixmap(int iState, PixmapSource source, Paintable::DrawMode mode); void setNoPos(int iNoPos); // Current position diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index 72ec367771..75bb6b2a80 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -58,10 +58,18 @@ void WVuMeter::setup(QDomNode node, const SkinContext& context) { // Set background pixmap if available if (context.hasNode(node, "PathBack")) { - setPixmapBackground(context.getPixmapSource(context.selectNode(node, "PathBack"))); + QDomElement backPathNode = context.selectElement(node, "PathBack"); + // The implicit default in <1.12.0 was FIXED so we keep it for backwards + // compatibility. + setPixmapBackground(context.getPixmapSource(backPathNode), + context.selectScaleMode(backPathNode, Paintable::FIXED)); } - setPixmaps(context.getPixmapSource(context.selectNode(node, "PathVu")), bHorizontal); + QDomElement vuNode = context.selectElement(node, "PathVu"); + // The implicit default in <1.12.0 was FIXED so we keep it for backwards + // compatibility. + setPixmaps(context.getPixmapSource(vuNode), bHorizontal, + context.selectScaleMode(vuNode, Paintable::FIXED)); m_iPeakHoldSize = context.selectInt(node, "PeakHoldSize"); if (m_iPeakHoldSize < 0 || m_iPeakHoldSize > 100) @@ -80,21 +88,19 @@ void WVuMeter::setup(QDomNode node, const SkinContext& context) { m_iPeakFallTime = DEFAULT_FALLTIME; } -void WVuMeter::setPixmapBackground(PixmapSource source) { - m_pPixmapBack = WPixmapStore::getPaintable(source, - Paintable::TILE); +void WVuMeter::setPixmapBackground(PixmapSource source, Paintable::DrawMode mode) { + m_pPixmapBack = WPixmapStore::getPaintable(source, mode); if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() << "Error loading background pixmap:" << source.getPath(); - } else { + } else if (mode == Paintable::FIXED) { setFixedSize(m_pPixmapBack->size()); } } void WVuMeter::setPixmaps(PixmapSource source, - bool bHorizontal) { - m_pPixmapVu = WPixmapStore::getPaintable(source, - Paintable::STRETCH); + bool bHorizontal, Paintable::DrawMode mode) { + m_pPixmapVu = WPixmapStore::getPaintable(source, mode); if (m_pPixmapVu.isNull() || m_pPixmapVu->isNull()) { qDebug() << "WVuMeter: Error loading vu pixmap" << source.getPath(); } else { @@ -162,8 +168,8 @@ void WVuMeter::paintEvent(QPaintEvent *) { p.drawPrimitive(QStyle::PE_Widget, option); if (!m_pPixmapBack.isNull() && !m_pPixmapBack->isNull()) { - // Draw background. - m_pPixmapBack->draw(0, 0, &p); + // Draw background. DrawMode takes care of whether to stretch or not. + m_pPixmapBack->draw(rect(), &p); } if (!m_pPixmapVu.isNull() && !m_pPixmapVu->isNull()) { diff --git a/src/widget/wvumeter.h b/src/widget/wvumeter.h index 26669bd44f..f4e6e02abf 100644 --- a/src/widget/wvumeter.h +++ b/src/widget/wvumeter.h @@ -36,9 +36,10 @@ class WVuMeter : public WWidget { virtual ~WVuMeter(); void setup(QDomNode node, const SkinContext& context); - void setPixmapBackground(PixmapSource source); + void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); void setPixmaps(PixmapSource source, - bool bHorizontal=false); + bool bHorizontal, + Paintable::DrawMode mode); void onConnectedControlChanged(double dParameter, double dValue); protected slots: diff --git a/src/widget/wwidgetgroup.cpp b/src/widget/wwidgetgroup.cpp index 3de66f80d9..c5df44f91c 100644 --- a/src/widget/wwidgetgroup.cpp +++ b/src/widget/wwidgetgroup.cpp @@ -83,10 +83,9 @@ void WWidgetGroup::setup(QDomNode node, const SkinContext& context) { // Set background pixmap if available if (context.hasNode(node, "BackPath")) { - QString mode_str = context.selectAttributeString( - context.selectElement(node, "BackPath"), "scalemode", "TILE"); - setPixmapBackground(context.getPixmapSource(context.selectNode(node, "BackPath")), - Paintable::DrawModeFromString(mode_str)); + QDomElement backPathNode = context.selectElement(node, "BackPath"); + setPixmapBackground(context.getPixmapSource(backPathNode), + context.selectScaleMode(backPathNode, Paintable::TILE)); } QLayout* pLayout = NULL; |