diff options
author | RJ Ryan <rryan@mixxx.org> | 2014-12-09 00:38:17 -0500 |
---|---|---|
committer | RJ Ryan <rryan@mixxx.org> | 2014-12-09 00:51:44 -0500 |
commit | 4fc7b863f91d34bc6ad9d6b3a2c0172a4e62e7b1 (patch) | |
tree | a90a24cacfff43faadbbd557bdab5f13f55cecea /src/widget/wdisplay.cpp | |
parent | 59566d4c263ed82c6fe54a917cc8fa2ede7120d6 (diff) |
Add scalemode support to most widget images.
* Remove WStatusLight SizeMode as DrawMode is more general and covers
its use cases.
* Only call QWidget::setFixedSize if the DrawMode is FIXED.
* Use FIXED as default DrawMode for most widgets for backwards
compatibility.
* Switch most Paintable::draw() calls to rectangle targets instead
of (x,y) points. This allows the DrawMode to do the right behavior
based on the mode.
Diffstat (limited to 'src/widget/wdisplay.cpp')
-rw-r--r-- | src/widget/wdisplay.cpp | 40 |
1 files changed, 24 insertions, 16 deletions
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); } } |