diff options
66 files changed, 414 insertions, 299 deletions
diff --git a/build/depends.py b/build/depends.py index a8a6b52583..479e2fe271 100644 --- a/build/depends.py +++ b/build/depends.py @@ -791,6 +791,7 @@ class MixxxCore(Feature): "skin/colorschemeparser.cpp", "skin/propertybinder.cpp", "skin/tooltips.cpp", + "skin/skincontext.cpp", "sampleutil.cpp", "trackinfoobject.cpp", diff --git a/src/configobject.cpp b/src/configobject.cpp index c9ea8342df..ec49a700ad 100644 --- a/src/configobject.cpp +++ b/src/configobject.cpp @@ -34,6 +34,7 @@ #include "widget/wwidget.h" #include "util/cmdlineargs.h" +#include "xmlparse.h" ConfigKey::ConfigKey() { } @@ -430,8 +431,8 @@ template <class ValueType> ConfigObject<ValueType>::ConfigObject(QDomNode node) while (!ctrl.isNull()) { if(ctrl.nodeName() == "control") { - QString group = WWidget::selectNodeQString(ctrl, "group"); - QString key = WWidget::selectNodeQString(ctrl, "key"); + QString group = XmlParse::selectNodeQString(ctrl, "group"); + QString key = XmlParse::selectNodeQString(ctrl, "key"); ConfigKey k(group, key); ValueType m(ctrl); set(k, m); diff --git a/src/skin/colorschemeparser.cpp b/src/skin/colorschemeparser.cpp index 96141e1098..2d98f98fe1 100644 --- a/src/skin/colorschemeparser.cpp +++ b/src/skin/colorschemeparser.cpp @@ -5,7 +5,7 @@ #include "widget/wimagestore.h" #include "widget/wskincolor.h" #include "widget/wwidget.h" - +#include "xmlparse.h" #include "skin/imgsource.h" #include "skin/imgloader.h" #include "skin/imgcolor.h" @@ -27,7 +27,7 @@ void ColorSchemeParser::setupLegacyColorSchemes(QDomElement docElem, } while (!sch.isNull() && !found) { - QString thisname = WWidget::selectNodeQString(sch, "Name"); + QString thisname = XmlParse::selectNodeQString(sch, "Name"); if (thisname == schname) { found = true; } else { @@ -71,9 +71,9 @@ ImgSource* ColorSchemeParser::parseFilters(QDomNode filt) { } else if (name == "hueinv") { ret = new ImgHueInv(ret); } else if (name == "add") { - ret = new ImgAdd(ret, WWidget::selectNodeInt(f, "Amount")); + ret = new ImgAdd(ret, XmlParse::selectNodeInt(f, "Amount")); } else if (name == "scalewhite") { - ret = new ImgScaleWhite(ret, WWidget::selectNodeFloat(f, "Amount")); + ret = new ImgScaleWhite(ret, XmlParse::selectNodeFloat(f, "Amount")); } else if (name == "hsvtweak") { int hmin = 0; int hmax = 359; @@ -88,20 +88,20 @@ ImgSource* ColorSchemeParser::parseFilters(QDomNode filt) { int sconst = 0; int vconst = 0; - if (!f.namedItem("HMin").isNull()) { hmin = WWidget::selectNodeInt(f, "HMin"); } - if (!f.namedItem("HMax").isNull()) { hmax = WWidget::selectNodeInt(f, "HMax"); } - if (!f.namedItem("SMin").isNull()) { smin = WWidget::selectNodeInt(f, "SMin"); } - if (!f.namedItem("SMax").isNull()) { smax = WWidget::selectNodeInt(f, "SMax"); } - if (!f.namedItem("VMin").isNull()) { vmin = WWidget::selectNodeInt(f, "VMin"); } - if (!f.namedItem("VMax").isNull()) { vmax = WWidget::selectNodeInt(f, "VMax"); } + if (!f.namedItem("HMin").isNull()) { hmin = XmlParse::selectNodeInt(f, "HMin"); } + if (!f.namedItem("HMax").isNull()) { hmax = XmlParse::selectNodeInt(f, "HMax"); } + if (!f.namedItem("SMin").isNull()) { smin = XmlParse::selectNodeInt(f, "SMin"); } + if (!f.namedItem("SMax").isNull()) { smax = XmlParse::selectNodeInt(f, "SMax"); } + if (!f.namedItem("VMin").isNull()) { vmin = XmlParse::selectNodeInt(f, "VMin"); } + if (!f.namedItem("VMax").isNull()) { vmax = XmlParse::selectNodeInt(f, "VMax"); } - if (!f.namedItem("HConst").isNull()) { hconst = WWidget::selectNodeInt(f, "HConst"); } - if (!f.namedItem("SConst").isNull()) { sconst = WWidget::selectNodeInt(f, "SConst"); } - if (!f.namedItem("VConst").isNull()) { vconst = WWidget::selectNodeInt(f, "VConst"); } + if (!f.namedItem("HConst").isNull()) { hconst = XmlParse::selectNodeInt(f, "HConst"); } + if (!f.namedItem("SConst").isNull()) { sconst = XmlParse::selectNodeInt(f, "SConst"); } + if (!f.namedItem("VConst").isNull()) { vconst = XmlParse::selectNodeInt(f, "VConst"); } - if (!f.namedItem("HFact").isNull()) { hfact = WWidget::selectNodeFloat(f, "HFact"); } - if (!f.namedItem("SFact").isNull()) { sfact = WWidget::selectNodeFloat(f, "SFact"); } - if (!f.namedItem("VFact").isNull()) { vfact = WWidget::selectNodeFloat(f, "VFact"); } + if (!f.namedItem("HFact").isNull()) { hfact = XmlParse::selectNodeFloat(f, "HFact"); } + if (!f.namedItem("SFact").isNull()) { sfact = XmlParse::selectNodeFloat(f, "SFact"); } + if (!f.namedItem("VFact").isNull()) { vfact = XmlParse::selectNodeFloat(f, "VFact"); } ret = new ImgHSVTweak(ret, hmin, hmax, smin, smax, vmin, vmax, hfact, hconst, sfact, sconst, vfact, vconst); diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 78ce514e8c..9a6cc757f0 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -27,6 +27,7 @@ #include "skin/colorschemeparser.h" #include "skin/propertybinder.h" +#include "skin/skincontext.h" #include "widget/wwidget.h" #include "widget/wknob.h" @@ -92,13 +93,14 @@ LegacySkinParser::LegacySkinParser(ConfigObject<ConfigValue>* pConfig, ControllerManager* pControllerManager, Library* pLibrary, VinylControlManager* pVCMan) - : m_pConfig(pConfig), - m_pKeyboard(pKeyboard), - m_pPlayerManager(pPlayerManager), - m_pControllerManager(pControllerManager), - m_pLibrary(pLibrary), - m_pVCManager(pVCMan), - m_pParent(NULL) { + : m_pConfig(pConfig), + m_pKeyboard(pKeyboard), + m_pPlayerManager(pPlayerManager), + m_pControllerManager(pControllerManager), + m_pLibrary(pLibrary), + m_pVCManager(pVCMan), + m_pParent(NULL), + m_pContext(NULL) { } LegacySkinParser::~LegacySkinParser() { @@ -276,6 +278,7 @@ QWidget* LegacySkinParser::parseSkin(QString skinPath, QWidget* pParent) { // created parent so MixxxApp can use it for nefarious purposes ( // fullscreen mostly) --bkgood m_pParent = pParent; + m_pContext = new SkinContext(); return parseNode(skinDocument); } @@ -491,7 +494,7 @@ QWidget* LegacySkinParser::parseSplitter(QDomElement node) { QWidget* LegacySkinParser::parseWidgetGroup(QDomElement node) { WWidgetGroup* pGroup = new WWidgetGroup(m_pParent); setupWidget(node, pGroup); - pGroup->setup(node); + pGroup->setup(node, *m_pContext); setupConnections(node, pGroup); QDomNode childrenNode = XmlParse::selectNode(node, "Children"); @@ -634,7 +637,7 @@ QWidget* LegacySkinParser::parseBackground(QDomElement node, QWidget* LegacySkinParser::parsePushButton(QDomElement node) { WPushButton* p = new WPushButton(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -644,7 +647,7 @@ QWidget* LegacySkinParser::parsePushButton(QDomElement node) { QWidget* LegacySkinParser::parseSliderComposed(QDomElement node) { WSliderComposed* p = new WSliderComposed(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -675,7 +678,7 @@ QWidget* LegacySkinParser::parseOverview(QDomElement node) { m_pPlayerManager, SLOT(slotLoadToPlayer(QString, QString))); setupWidget(node, overviewWidget); - overviewWidget->setup(node); + overviewWidget->setup(node, *m_pContext); setupConnections(node, overviewWidget); overviewWidget->installEventFilter(m_pKeyboard); overviewWidget->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -708,7 +711,7 @@ QWidget* LegacySkinParser::parseVisual(QDomElement node) { WWaveformViewer* viewer = new WWaveformViewer(pSafeChannelStr, m_pConfig, m_pParent); viewer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); WaveformWidgetFactory* factory = WaveformWidgetFactory::instance(); - factory->setWaveformWidget(viewer, node); + factory->setWaveformWidget(viewer, node, *m_pContext); //qDebug() << "::parseVisual: parent" << m_pParent << m_pParent->size(); //qDebug() << "::parseVisual: viewer" << viewer << viewer->size(); @@ -757,7 +760,7 @@ QWidget* LegacySkinParser::parseText(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -794,7 +797,7 @@ QWidget* LegacySkinParser::parseTrackProperty(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -818,7 +821,7 @@ QWidget* LegacySkinParser::parseTrackProperty(QDomElement node) { QWidget* LegacySkinParser::parseVuMeter(QDomElement node) { WVuMeter * p = new WVuMeter(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -828,7 +831,7 @@ QWidget* LegacySkinParser::parseVuMeter(QDomElement node) { QWidget* LegacySkinParser::parseStatusLight(QDomElement node) { WStatusLight * p = new WStatusLight(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -838,7 +841,7 @@ QWidget* LegacySkinParser::parseStatusLight(QDomElement node) { QWidget* LegacySkinParser::parseDisplay(QDomElement node) { WDisplay * p = new WDisplay(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -866,7 +869,7 @@ QWidget* LegacySkinParser::parseNumberRate(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -890,7 +893,7 @@ QWidget* LegacySkinParser::parseNumberPos(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -908,7 +911,7 @@ QWidget* LegacySkinParser::parseNumber(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -926,7 +929,7 @@ QWidget* LegacySkinParser::parseLabel(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -944,7 +947,7 @@ QWidget* LegacySkinParser::parseTime(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } @@ -957,7 +960,7 @@ QWidget* LegacySkinParser::parseTime(QDomElement node) { QWidget* LegacySkinParser::parseKnob(QDomElement node) { WKnob * p = new WKnob(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -967,7 +970,7 @@ QWidget* LegacySkinParser::parseKnob(QDomElement node) { QWidget* LegacySkinParser::parseKnobComposed(QDomElement node) { WKnobComposed* p = new WKnobComposed(m_pParent); setupWidget(node, p); - p->setup(node); + p->setup(node, *m_pContext); setupConnections(node, p); p->installEventFilter(m_pKeyboard); p->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -991,7 +994,7 @@ QWidget* LegacySkinParser::parseSpinny(QDomElement node) { connect(spinny, SIGNAL(trackDropped(QString, QString)), m_pPlayerManager, SLOT(slotLoadToPlayer(QString, QString))); - spinny->setup(node, pSafeChannelStr); + spinny->setup(node, *m_pContext, pSafeChannelStr); setupConnections(node, spinny); spinny->installEventFilter(m_pKeyboard); spinny->installEventFilter(m_pControllerManager->getControllerLearningEventFilter()); @@ -1001,7 +1004,7 @@ QWidget* LegacySkinParser::parseSpinny(QDomElement node) { QWidget* LegacySkinParser::parseSearchBox(QDomElement node) { WSearchLineEdit* pLineEditSearch = new WSearchLineEdit(m_pConfig, m_pParent); setupWidget(node, pLineEditSearch); - pLineEditSearch->setup(node); + pLineEditSearch->setup(node, *m_pContext); // Connect search box signals to the library connect(pLineEditSearch, SIGNAL(search(const QString&)), @@ -1225,7 +1228,7 @@ QWidget* LegacySkinParser::parseKey(QDomElement node) { // on the node and setupWidget() will set the widget style. If the style is // set before the palette is set then the custom palette will not take // effect which breaks color scheme support. - p->setup(node); + p->setup(node, *m_pContext); if (p->getComposedWidget()) { setupWidget(node, p->getComposedWidget(), false); } diff --git a/src/skin/legacyskinparser.h b/src/skin/legacyskinparser.h index b9945a57a3..d1dc761892 100644 --- a/src/skin/legacyskinparser.h +++ b/src/skin/legacyskinparser.h @@ -17,6 +17,7 @@ class Library; class MixxxKeyboard; class PlayerManager; class ControllerManager; +class SkinContext; class LegacySkinParser : public QObject, public SkinParser { Q_OBJECT @@ -90,7 +91,8 @@ class LegacySkinParser : public QObject, public SkinParser { ControllerManager* m_pControllerManager; Library* m_pLibrary; VinylControlManager* m_pVCManager; - QWidget *m_pParent; + QWidget* m_pParent; + SkinContext* m_pContext; Tooltips m_tooltips; static QList<const char*> s_channelStrs; static QMutex s_safeStringMutex; diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp new file mode 100644 index 0000000000..d6cf1c31c7 --- /dev/null +++ b/src/skin/skincontext.cpp @@ -0,0 +1,68 @@ +#include "skin/skincontext.h" + +SkinContext::SkinContext() { +} + +SkinContext::SkinContext(const SkinContext& parent) + : m_variables(parent.variables()) { +} + +SkinContext::~SkinContext() { +} + +QString SkinContext::variable(const QString& name) const { + return m_variables.value(name, QString()); +} + +void SkinContext::setVariable(const QString& name, const QString& value) { + m_variables[name] = value; +} + +bool SkinContext::hasNode(const QDomNode& node, const QString& nodeName) const { + return !selectNode(node, nodeName).isNull(); +} + +QDomNode SkinContext::selectNode(const QDomNode& node, + const QString& nodeName) const { + QDomNode child = node.firstChild(); + while (!child.isNull()) { + if (child.nodeName() == nodeName) { + return child; + } + child = child.nextSibling(); + } + return child; +} + +QDomElement SkinContext::selectElement(const QDomNode& node, + const QString& nodeName) const { + QDomNode child = selectNode(node, nodeName); + return child.toElement(); +} + +QString SkinContext::selectString(const QDomNode& node, + const QString& nodeName) const { + QDomNode child = selectNode(node, nodeName); + return child.isNull() ? "" : child.toElement().text(); +} + +float SkinContext::selectFloat(const QDomNode& node, + const QString& nodeName) const { + bool ok = false; + float conv = selectElement(node, nodeName).text().toFloat(&ok); + return ok ? conv : 0.0f; +} + +double SkinContext::selectDouble(const QDomNode& node, + const QString& nodeName) const { + bool ok = false; + double conv = selectElement(node, nodeName).text().toDouble(&ok); + return ok ? conv : 0.0; +} + +int SkinContext::selectInt(const QDomNode& node, + const QString& nodeName) const { + bool ok = false; + int conv = selectElement(node, nodeName).text().toInt(&ok); + return ok ? conv : 0; +} diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h new file mode 100644 index 0000000000..8f0b3fc14a --- /dev/null +++ b/src/skin/skincontext.h @@ -0,0 +1,33 @@ +#ifndef SKINCONTEXT_H +#define SKINCONTEXT_H + +#include <QHash> +#include <QString> +#include <QDomNode> +#include <QDomElement> + +class SkinContext { + public: + SkinContext(); + SkinContext(const SkinContext& parent); + virtual ~SkinContext(); + + QString variable(const QString& name) const; + const QHash<QString, QString>& variables() const { + return m_variables; + } + void setVariable(const QString& name, const QString& value); + + bool hasNode(const QDomNode& node, const QString& nodeName) const; + QDomNode selectNode(const QDomNode& node, const QString& nodeName) const; + QDomElement selectElement(const QDomNode& node, const QString& nodeName) const; + QString selectString(const QDomNode& node, const QString& nodeName) const; + float selectFloat(const QDomNode& node, const QString& nodeName) const; + double selectDouble(co |