From 1ef5e64a640989bcaa969c286819f920331c3408 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 12 Jul 2014 18:41:23 +0200 Subject: [PATCH 01/90] first version of variables in attributes + State as contextNode --- src/skin/skincontext.cpp | 62 ++++++++++++++++++++++++++++++++++++++ src/skin/skincontext.h | 4 ++- src/widget/wpushbutton.cpp | 16 ++++++---- 3 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 43235782bac7..e3a699e6fb2a 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -258,6 +258,9 @@ QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { } } + + parseTree(svgNode, &SkinContext::setVariablesInAttributes); + // Save the new svg in a temp file to use it with setPixmap QTemporaryFile svgFile; svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); @@ -312,3 +315,62 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { return pixmapPath; } + + +void SkinContext::setVariablesInAttributes(const QDomNode& node) const { + QDomNamedNodeMap attributes = node.attributes(); + uint i; + int pos; + QString varName, varValue, attributeValue, propName, match, replacement; + QStringList captured; + QDomAttr attribute; + QRegExp rx("var\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) + + for (i=0; i < attributes.length(); i++){ + + attribute = attributes.item(i).toAttr(); + attributeValue = attribute.value(); + pos = 0; + + while ((pos = rx.indexIn(attributeValue, pos)) != -1) { + captured = rx.capturedTexts(); + qWarning() << "AAAAA " << captured.length() << " '" << captured.join("', '") << "'\n"; + match = rx.cap(0); + + varName = rx.cap(3); + if (varName.length()){ // var( prop, name ) + propName = rx.cap(1); + varName = rx.cap(3); + varValue = variable(varName); + replacement = varValue.length() ? propName + ":" + varValue : ""; + } else{ // var( name ) + + varName = rx.cap(1); + replacement = variable(varName); + } + + qDebug() << "setting " << replacement << " as " << match << "in "<< attributeValue << "\n"; + + attributeValue.replace(pos, match.length(), replacement); + pos += replacement.length(); + } + + attribute.setValue(attributeValue); + } + +} + +void SkinContext::parseTree(const QDomNode& node, void (SkinContext::*callback)(const QDomNode& node)const) const { + + (this->*callback)( node ); + QDomNodeList children = node.childNodes(); + QDomNode child; + uint i; + + for (i=0; i m_variables; diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 245057f065e5..0268448bea27 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -68,23 +68,27 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { // Load pixmaps for associated states QDomNode state = context.selectNode(node, "State"); while (!state.isNull()) { - if (state.isElement() && state.nodeName() == "State") { - int iState = context.selectInt(state, "Number"); + if (state.isElement()) { + // support for variables in State elements + SkinContext* stateContext = new SkinContext(context); + stateContext->updateVariables(state); + + int iState = stateContext->selectInt(state, "Number"); if (iState < m_iNoStates) { QString pixmapPath; - pixmapPath = context.getPixmapPath(context.selectNode(state, "Unpressed")); + pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Unpressed")); if (!pixmapPath.isEmpty()) { setPixmap(iState, false, pixmapPath); } - pixmapPath = context.getPixmapPath(context.selectNode(state, "Pressed")); + pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Pressed")); if (!pixmapPath.isEmpty()) { setPixmap(iState, true, pixmapPath); } - m_text.replace(iState, context.selectString(state, "Text")); - QString alignment = context.selectString(state, "Alignment"); + m_text.replace(iState, stateContext->selectString(state, "Text")); + QString alignment = stateContext->selectString(state, "Alignment"); if (alignment == "left") { m_align.replace(iState, Qt::AlignLeft); } else if (alignment == "right") { From 951212d25a4e48a12b96d7864db55232e81ca1fd Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 19 Jul 2014 14:53:46 +0200 Subject: [PATCH 02/90] context --- src/skin/skincontext.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index e3a699e6fb2a..f5e818f63e93 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -321,20 +321,31 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { QDomNamedNodeMap attributes = node.attributes(); uint i; int pos; - QString varName, varValue, attributeValue, propName, match, replacement; + QString varName, varValue, attributeValue, attributeName, + propName, match, replacement; QStringList captured; QDomAttr attribute; QRegExp rx("var\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) + QRegExp nameRx("^var-([a-zA-Z0-9_-]+)$"); // var-attribute-name; for (i=0; i < attributes.length(); i++){ attribute = attributes.item(i).toAttr(); attributeValue = attribute.value(); + attributeName = attribute.name(); + + // searching variable attributes + if ((pos = rx.indexIn(attributeValue, pos)) != -1) { + captured = rx.capturedTexts(); + + } + + + // searching vars in the attribute value pos = 0; - while ((pos = rx.indexIn(attributeValue, pos)) != -1) { captured = rx.capturedTexts(); - qWarning() << "AAAAA " << captured.length() << " '" << captured.join("', '") << "'\n"; + // qWarning() << "AAAAA " << captured.length() << " '" << captured.join("', '") << "'\n"; match = rx.cap(0); varName = rx.cap(3); @@ -355,6 +366,8 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { pos += replacement.length(); } + + attribute.setValue(attributeValue); } From ad7473f1715fc298ff3ba390c424b9a44ee7d04d Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 19 Jul 2014 14:58:39 +0200 Subject: [PATCH 03/90] merge inline svg --- handle-horizontal-10x25-1.svg | 0 handle-horizontal-10x25-2.svg | 0 handle-horizontal-10x30-green.svg | 0 handle-horizontal-10x30-purple.svg | 0 handle-vertical-15x12-1.svg | 0 handle-vertical-15x12-2.svg | 0 handle-vertical-25x12-1.svg | 0 handle-vertical-25x12-2.svg | 0 handle-vertical-30x15-green.svg | 0 handle-vertical-30x15-purple.svg | 0 slider-horizontal-60x25-High.svg | 0 slider-horizontal-60x25-Low.svg | 0 slider-horizontal-60x25-Mid.svg | 0 slider-horizontal-60x30.svg | 0 slider-vertical-15x79.svg | 0 slider-vertical-25x75.svg | 0 slider-vertical-25x90.svg | 0 slider-vertical-30x125.svg | 0 18 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 handle-horizontal-10x25-1.svg create mode 100644 handle-horizontal-10x25-2.svg create mode 100644 handle-horizontal-10x30-green.svg create mode 100644 handle-horizontal-10x30-purple.svg create mode 100644 handle-vertical-15x12-1.svg create mode 100644 handle-vertical-15x12-2.svg create mode 100644 handle-vertical-25x12-1.svg create mode 100644 handle-vertical-25x12-2.svg create mode 100644 handle-vertical-30x15-green.svg create mode 100644 handle-vertical-30x15-purple.svg create mode 100644 slider-horizontal-60x25-High.svg create mode 100644 slider-horizontal-60x25-Low.svg create mode 100644 slider-horizontal-60x25-Mid.svg create mode 100644 slider-horizontal-60x30.svg create mode 100644 slider-vertical-15x79.svg create mode 100644 slider-vertical-25x75.svg create mode 100644 slider-vertical-25x90.svg create mode 100644 slider-vertical-30x125.svg diff --git a/handle-horizontal-10x25-1.svg b/handle-horizontal-10x25-1.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-horizontal-10x25-2.svg b/handle-horizontal-10x25-2.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-horizontal-10x30-green.svg b/handle-horizontal-10x30-green.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-horizontal-10x30-purple.svg b/handle-horizontal-10x30-purple.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-vertical-15x12-1.svg b/handle-vertical-15x12-1.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-vertical-15x12-2.svg b/handle-vertical-15x12-2.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-vertical-25x12-1.svg b/handle-vertical-25x12-1.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-vertical-25x12-2.svg b/handle-vertical-25x12-2.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-vertical-30x15-green.svg b/handle-vertical-30x15-green.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/handle-vertical-30x15-purple.svg b/handle-vertical-30x15-purple.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-horizontal-60x25-High.svg b/slider-horizontal-60x25-High.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-horizontal-60x25-Low.svg b/slider-horizontal-60x25-Low.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-horizontal-60x25-Mid.svg b/slider-horizontal-60x25-Mid.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-horizontal-60x30.svg b/slider-horizontal-60x30.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-vertical-15x79.svg b/slider-vertical-15x79.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-vertical-25x75.svg b/slider-vertical-25x75.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-vertical-25x90.svg b/slider-vertical-25x90.svg new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/slider-vertical-30x125.svg b/slider-vertical-30x125.svg new file mode 100644 index 000000000000..e69de29bb2d1 From 99634ecebd9df7dc84ad0b3b1d540d4a6a5c1777 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 19 Jul 2014 14:59:54 +0200 Subject: [PATCH 04/90] cleaning --- handle-horizontal-10x25-1.svg | 0 handle-horizontal-10x25-2.svg | 0 handle-horizontal-10x30-green.svg | 0 handle-horizontal-10x30-purple.svg | 0 handle-vertical-15x12-1.svg | 0 handle-vertical-15x12-2.svg | 0 handle-vertical-25x12-1.svg | 0 handle-vertical-25x12-2.svg | 0 handle-vertical-30x15-green.svg | 0 handle-vertical-30x15-purple.svg | 0 slider-horizontal-60x25-High.svg | 0 slider-horizontal-60x25-Low.svg | 0 slider-horizontal-60x25-Mid.svg | 0 slider-horizontal-60x30.svg | 0 slider-vertical-15x79.svg | 0 slider-vertical-25x75.svg | 0 slider-vertical-25x90.svg | 0 slider-vertical-30x125.svg | 0 18 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 handle-horizontal-10x25-1.svg delete mode 100644 handle-horizontal-10x25-2.svg delete mode 100644 handle-horizontal-10x30-green.svg delete mode 100644 handle-horizontal-10x30-purple.svg delete mode 100644 handle-vertical-15x12-1.svg delete mode 100644 handle-vertical-15x12-2.svg delete mode 100644 handle-vertical-25x12-1.svg delete mode 100644 handle-vertical-25x12-2.svg delete mode 100644 handle-vertical-30x15-green.svg delete mode 100644 handle-vertical-30x15-purple.svg delete mode 100644 slider-horizontal-60x25-High.svg delete mode 100644 slider-horizontal-60x25-Low.svg delete mode 100644 slider-horizontal-60x25-Mid.svg delete mode 100644 slider-horizontal-60x30.svg delete mode 100644 slider-vertical-15x79.svg delete mode 100644 slider-vertical-25x75.svg delete mode 100644 slider-vertical-25x90.svg delete mode 100644 slider-vertical-30x125.svg diff --git a/handle-horizontal-10x25-1.svg b/handle-horizontal-10x25-1.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-horizontal-10x25-2.svg b/handle-horizontal-10x25-2.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-horizontal-10x30-green.svg b/handle-horizontal-10x30-green.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-horizontal-10x30-purple.svg b/handle-horizontal-10x30-purple.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-vertical-15x12-1.svg b/handle-vertical-15x12-1.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-vertical-15x12-2.svg b/handle-vertical-15x12-2.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-vertical-25x12-1.svg b/handle-vertical-25x12-1.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-vertical-25x12-2.svg b/handle-vertical-25x12-2.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-vertical-30x15-green.svg b/handle-vertical-30x15-green.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/handle-vertical-30x15-purple.svg b/handle-vertical-30x15-purple.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-horizontal-60x25-High.svg b/slider-horizontal-60x25-High.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-horizontal-60x25-Low.svg b/slider-horizontal-60x25-Low.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-horizontal-60x25-Mid.svg b/slider-horizontal-60x25-Mid.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-horizontal-60x30.svg b/slider-horizontal-60x30.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-vertical-15x79.svg b/slider-vertical-15x79.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-vertical-25x75.svg b/slider-vertical-25x75.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-vertical-25x90.svg b/slider-vertical-25x90.svg deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/slider-vertical-30x125.svg b/slider-vertical-30x125.svg deleted file mode 100644 index e69de29bb2d1..000000000000 From c278d3f61529298559371cb79d093fb6204e84f7 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 29 Jul 2014 14:30:10 +0200 Subject: [PATCH 05/90] cleaning --- src/skin/skincontext.cpp | 83 +++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index f5e818f63e93..a8099f84f2e7 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -318,15 +318,16 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { void SkinContext::setVariablesInAttributes(const QDomNode& node) const { - QDomNamedNodeMap attributes = node.attributes(); + QDomNamedNodeMap attributes = node.attributes(); + QDomElement element = node.toElement(); uint i; int pos; QString varName, varValue, attributeValue, attributeName, - propName, match, replacement; + propName, match, replacement; QStringList captured; QDomAttr attribute; - QRegExp rx("var\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) - QRegExp nameRx("^var-([a-zA-Z0-9_-]+)$"); // var-attribute-name; + QRegExp rx("var\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) + QRegExp nameRx("^var-([^=\\s]+)$"); // var-attribute-name; for (i=0; i < attributes.length(); i++){ @@ -334,43 +335,45 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { attributeValue = attribute.value(); attributeName = attribute.name(); - // searching variable attributes - if ((pos = rx.indexIn(attributeValue, pos)) != -1) { - captured = rx.capturedTexts(); - - } + // searching variable attributes : var-attribute_name="variable_name" + if (nameRx.indexIn(attributeName) != -1) { + if (!(varValue = variable(attributeValue)).isNull()){ + // qDebug() << "setting " << varValue << " as attribute " << nameRx.cap(1) << " \n"; + element.setAttribute( nameRx.cap(1), varValue); + } + } - // searching vars in the attribute value - pos = 0; + pos = 0; + // searching vars in the attribute value (styles or classes) while ((pos = rx.indexIn(attributeValue, pos)) != -1) { - captured = rx.capturedTexts(); - // qWarning() << "AAAAA " << captured.length() << " '" << captured.join("', '") << "'\n"; - match = rx.cap(0); - - varName = rx.cap(3); - if (varName.length()){ // var( prop, name ) - propName = rx.cap(1); - varName = rx.cap(3); - varValue = variable(varName); - replacement = varValue.length() ? propName + ":" + varValue : ""; - } else{ // var( name ) - - varName = rx.cap(1); - replacement = variable(varName); - } - - qDebug() << "setting " << replacement << " as " << match << "in "<< attributeValue << "\n"; - - attributeValue.replace(pos, match.length(), replacement); - pos += replacement.length(); - } - - - + captured = rx.capturedTexts(); + // qWarning() << "AAAAA " << captured.length() << " '" << captured.join("', '") << "'\n"; + match = rx.cap(0); + + varName = rx.cap(3); + if (varName.length()){ // var( prop, name ) + propName = rx.cap(1); + varName = rx.cap(3); + varValue = variable(varName); + replacement = varValue.length() ? propName + ":" + varValue : ""; + } else{ // var( name ) + + varName = rx.cap(1); + replacement = variable(varName); + } + + // qDebug() << "setting " << replacement << " as " << match << "in "<< attributeValue << "\n"; + + attributeValue.replace(pos, match.length(), replacement); + pos += replacement.length(); + } + + + attribute.setValue(attributeValue); } - + } void SkinContext::parseTree(const QDomNode& node, void (SkinContext::*callback)(const QDomNode& node)const) const { @@ -381,9 +384,9 @@ void SkinContext::parseTree(const QDomNode& node, void (SkinContext::*callback)( uint i; for (i=0; i Date: Thu, 31 Jul 2014 19:19:29 +0200 Subject: [PATCH 06/90] support for multiple variables in one svg file --- src/skin/skincontext.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index a8099f84f2e7..211a4ff218c6 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -233,16 +233,15 @@ QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { // replace variables QDomNodeList variablesElements = svgElement.elementsByTagName("Variable"); - uint variableIndex; + int i=variablesElements.length()-1; QDomElement varElement; QString varName, varValue; QDomNode varNode, varParentNode, oldChild; QDomText varValueNode; - for (variableIndex=0; variableIndex < variablesElements.length(); variableIndex++){ + while ( i >= 0 && (varNode = variablesElements.item(i)).isNull() == false ){ // retrieve value - varNode = variablesElements.item(variableIndex); varElement = varNode.toElement(); varName = varElement.attribute("name"); varValue = variable(varName); @@ -256,6 +255,8 @@ QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { // replaceChild has a really weird behaviour so I add this check qDebug() << "SVG : unable to replace dom node changed. \n"; } + + --i; } From 3d9a313653d6532598493bf713af89efc6dc93ce Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Fri, 1 Aug 2014 20:21:31 +0200 Subject: [PATCH 07/90] qscript in svg + templateHooks for custom template behavior depending on vars --- src/skin/skincontext.cpp | 147 ++++++++++++++++++++++++++++++++------- src/skin/skincontext.h | 4 +- 2 files changed, 125 insertions(+), 26 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 211a4ff218c6..62497f23fb1b 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -259,6 +259,7 @@ QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { --i; } + parseScriptsInSvg(svgNode); parseTree(svgNode, &SkinContext::setVariablesInAttributes); @@ -273,7 +274,8 @@ QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { if( svgFile.open() ){ // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; QTextStream out(&svgFile); - svgNode.save( out, -1 ); + // svgNode.save( out, -1 ); + svgNode.save( out, 2 ); svgFile.close(); svgTempFileName = svgFile.fileName(); } else { @@ -327,8 +329,27 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { propName, match, replacement; QStringList captured; QDomAttr attribute; - QRegExp rx("var\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) - QRegExp nameRx("^var-([^=\\s]+)$"); // var-attribute-name; + + + QScriptValue global = m_scriptEngine.globalObject(); + QScriptValue hookNames; + + hookNames = global.property("hookNames").call( global ); + + QString hooksPattern; + + if( hookNames.toString().length() ){ + hooksPattern = hookNames.property("toPattern").call(hookNames).toString(); + // qDebug() << "PATTERN : " << hooksPattern << "\n"; + } else { + hooksPattern = "variable"; + } + + // QRegExp rx("("+hooksPattern+")\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) + QRegExp rx("\\s*("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // var( part1 [, part2]... ) + + + QRegExp nameRx("^(var|expr)-([^=\\s]+)$"); // var-attribute-name; for (i=0; i < attributes.length(); i++){ @@ -338,39 +359,33 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { // searching variable attributes : var-attribute_name="variable_name" if (nameRx.indexIn(attributeName) != -1) { - if (!(varValue = variable(attributeValue)).isNull()){ + + if(nameRx.cap(1) == "var"){ + varValue = variable(attributeValue); + } else if(nameRx.cap(1) == "expr"){ + varValue = evaluate(attributeValue).toString(); + } + + // qDebug() << "Qstring : " << nameRx.cap(0) << " -> " << varValue.length() << "\n"; + if (varValue.length()){ // qDebug() << "setting " << varValue << " as attribute " << nameRx.cap(1) << " \n"; - element.setAttribute( nameRx.cap(1), varValue); + element.setAttribute( nameRx.cap(2), varValue); } + + continue; } - pos = 0; - // searching vars in the attribute value (styles or classes) + // searching expressions in the attribute value (styles or classes) while ((pos = rx.indexIn(attributeValue, pos)) != -1) { captured = rx.capturedTexts(); - // qWarning() << "AAAAA " << captured.length() << " '" << captured.join("', '") << "'\n"; match = rx.cap(0); + qDebug() << "Expression : " << match << "\n"; - varName = rx.cap(3); - if (varName.length()){ // var( prop, name ) - propName = rx.cap(1); - varName = rx.cap(3); - varValue = variable(varName); - replacement = varValue.length() ? propName + ":" + varValue : ""; - } else{ // var( name ) - - varName = rx.cap(1); - replacement = variable(varName); - } - - // qDebug() << "setting " << replacement << " as " << match << "in "<< attributeValue << "\n"; - + replacement = evaluate( match ).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); - } - - + } attribute.setValue(attributeValue); } @@ -391,3 +406,85 @@ void SkinContext::parseTree(const QDomNode& node, void (SkinContext::*callback)( } } + +// +void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { + + // clone svg to don't alter xml input + QDomNode svgNode = svgSkinNode.cloneNode(true); + QDomElement svgElement = svgNode.toElement(); + + // parse script content + QDomNodeList scriptElements = svgElement.elementsByTagName("script"); + int i = 0; + QString expression; + QDomNode scriptNode; + + /* + QString hookablePrototype = "\ + this.templateHooks = {};\ + \ + this.regexpQuote = function (str, delimiter) {\ + return String(str).replace(\ + new RegExp(\ + '[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]',\ + 'g'\ + ),\ + '\\$&'\ + );\ + }\ + \ + this.hookNames = function(){\ + var hookNames = ['var'];\ + for( var i in this.templateHooks )\ + hookNames.push(i);\ + \ + hookNames.toPattern = function(){\ + // for( var i in this )\ + // this[i] = regexpQuote(this[i]);\ + return this.join('|');\ + }\ + \ + return hookNames;\ + }\ + "; + */ + + + while ( !(scriptNode = scriptElements.item(i)).isNull() && ++i ){ + // retrieve script + expression = nodeToString(scriptNode); + m_scriptEngine.evaluate( expression ); + } + + /** / + QScriptValue global = m_scriptEngine.globalObject(); + QScriptValue hookNames; + + if( scriptElements.length() ){ + hookNames = global.property("hookNames").call( global ); + + // qDebug() << "SVG : script. \n" << global.property("hookNames").toString() << "\n"; + qDebug() << "SVG : script. \n" << hookNames.toString() << "\n"; + } + /**/ +} + +QScriptValue SkinContext::evaluate(QString expression) const { + QString shell = "\ + (function(){\n\ + var out = '';\n\ + try{\n\ + out = " + expression + ";\n\ + } catch(e){ \n\ + print(e);\n\ + }\n\ + return out;\n\ + })();\n\ + "; + QScriptValue out = m_scriptEngine.evaluate(shell); + + // qDebug() << shell << "\n"; + qDebug() << expression << " -> " << out.toString() << "\n"; + return out; +} diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 072bd1261b40..021489b8bed7 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -68,7 +68,9 @@ class SkinContext { QString variableNodeToText(const QDomElement& element) const; QString setVariablesInSvg(const QDomNode& svgNode) const; void setVariablesInAttributes(const QDomNode& node) const; - + void parseScriptsInSvg(const QDomNode& svgNode) const; + QScriptValue evaluate(QString expression) const; + mutable QScriptEngine m_scriptEngine; QHash m_variables; QString m_skinBasePath; From 783134a01f2dd5c5a85124374e8d46da92acd17a Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 2 Aug 2014 20:16:28 +0200 Subject: [PATCH 08/90] support for src attribute on script elements --- src/skin/skincontext.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 62497f23fb1b..539b8d9147c2 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -420,7 +420,7 @@ void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { QString expression; QDomNode scriptNode; - /* + /**/ QString hookablePrototype = "\ this.templateHooks = {};\ \ @@ -448,11 +448,22 @@ void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { return hookNames;\ }\ "; - */ - + // m_scriptEngine.evaluate( hookablePrototype ); + /**/ + QFile scriptFile; while ( !(scriptNode = scriptElements.item(i)).isNull() && ++i ){ // retrieve script + if( scriptNode.toElement().hasAttribute("src") ){ + // qDebug() << "script fil !!!! \n"; + QFile scriptFile( getSkinPath( scriptNode.toElement().attribute("src") ) ); + scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); + + QTextStream in(&scriptFile); + // qDebug() << scriptFile.size() << in.readAll(); + m_scriptEngine.evaluate( in.readAll() ); + } + expression = nodeToString(scriptNode); m_scriptEngine.evaluate( expression ); } From 5f58332cbb158126d3dd1a6a664a7c3391aaca69 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 3 Aug 2014 20:11:04 +0200 Subject: [PATCH 09/90] cleaning + polishing --- src/skin/skincontext.cpp | 39 ++------------------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 539b8d9147c2..2300cddb66ca 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -346,7 +346,7 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { } // QRegExp rx("("+hooksPattern+")\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) - QRegExp rx("\\s*("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // var( part1 [, part2]... ) + QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // var( part1 [, part2]... ) QRegExp nameRx("^(var|expr)-([^=\\s]+)$"); // var-attribute-name; @@ -382,7 +382,7 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { match = rx.cap(0); qDebug() << "Expression : " << match << "\n"; - replacement = evaluate( match ).toString(); + replacement = evaluate( "this.templateHooks." + match ).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); } @@ -420,47 +420,12 @@ void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { QString expression; QDomNode scriptNode; - /**/ - QString hookablePrototype = "\ - this.templateHooks = {};\ - \ - this.regexpQuote = function (str, delimiter) {\ - return String(str).replace(\ - new RegExp(\ - '[.\\\\+*?\\[\\^\\]$(){}=!<>|:\\' + (delimiter || '') + '-]',\ - 'g'\ - ),\ - '\\$&'\ - );\ - }\ - \ - this.hookNames = function(){\ - var hookNames = ['var'];\ - for( var i in this.templateHooks )\ - hookNames.push(i);\ - \ - hookNames.toPattern = function(){\ - // for( var i in this )\ - // this[i] = regexpQuote(this[i]);\ - return this.join('|');\ - }\ - \ - return hookNames;\ - }\ - "; - // m_scriptEngine.evaluate( hookablePrototype ); - /**/ - - QFile scriptFile; while ( !(scriptNode = scriptElements.item(i)).isNull() && ++i ){ // retrieve script if( scriptNode.toElement().hasAttribute("src") ){ - // qDebug() << "script fil !!!! \n"; QFile scriptFile( getSkinPath( scriptNode.toElement().attribute("src") ) ); scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); - QTextStream in(&scriptFile); - // qDebug() << scriptFile.size() << in.readAll(); m_scriptEngine.evaluate( in.readAll() ); } From cdcf3a27ed1b5d6e14fd630451871cb5878e9cd2 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 4 Aug 2014 02:13:19 +0200 Subject: [PATCH 10/90] cleaning --- src/skin/skincontext.cpp | 101 ++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 61 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 2300cddb66ca..498b777656fc 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -274,7 +274,6 @@ QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { if( svgFile.open() ){ // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; QTextStream out(&svgFile); - // svgNode.save( out, -1 ); svgNode.save( out, 2 ); svgFile.close(); svgTempFileName = svgFile.fileName(); @@ -331,25 +330,20 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { QDomAttr attribute; - QScriptValue global = m_scriptEngine.globalObject(); - QScriptValue hookNames; - - hookNames = global.property("hookNames").call( global ); - - QString hooksPattern; + QScriptValue global = m_scriptEngine.globalObject(); + QScriptValue hookNames; + QString hooksPattern; - if( hookNames.toString().length() ){ - hooksPattern = hookNames.property("toPattern").call(hookNames).toString(); - // qDebug() << "PATTERN : " << hooksPattern << "\n"; - } else { - hooksPattern = "variable"; - } - - // QRegExp rx("("+hooksPattern+")\\(\\s*([^\\(\\),\\s]+)(\\s*,\\s*([^\\(\\),\\s]+))?\\s*\\)"); // var( part1 [, part2] ) - QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // var( part1 [, part2]... ) + hookNames = global.property("hookNames").call( global ); + if( hookNames.toString().length() ){ + hooksPattern = hookNames.property("toPattern").call(hookNames).toString(); + } else { + hooksPattern = "variable"; + } - QRegExp nameRx("^(var|expr)-([^=\\s]+)$"); // var-attribute-name; + QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) + QRegExp nameRx("^(var|expr)-([^=\\s]+)$"); // var-attribute_name="var_name"; for (i=0; i < attributes.length(); i++){ @@ -359,16 +353,14 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { // searching variable attributes : var-attribute_name="variable_name" if (nameRx.indexIn(attributeName) != -1) { - - if(nameRx.cap(1) == "var"){ - varValue = variable(attributeValue); - } else if(nameRx.cap(1) == "expr"){ - varValue = evaluate(attributeValue).toString(); - } - - // qDebug() << "Qstring : " << nameRx.cap(0) << " -> " << varValue.length() << "\n"; + + if(nameRx.cap(1) == "var"){ + varValue = variable(attributeValue); + } else if(nameRx.cap(1) == "expr"){ + varValue = evaluateTemplateExpression(attributeValue).toString(); + } + if (varValue.length()){ - // qDebug() << "setting " << varValue << " as attribute " << nameRx.cap(1) << " \n"; element.setAttribute( nameRx.cap(2), varValue); } @@ -382,10 +374,10 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { match = rx.cap(0); qDebug() << "Expression : " << match << "\n"; - replacement = evaluate( "this.templateHooks." + match ).toString(); + replacement = evaluateTemplateExpression( "this.templateHooks." + match ).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); - } + } attribute.setValue(attributeValue); } @@ -407,7 +399,6 @@ void SkinContext::parseTree(const QDomNode& node, void (SkinContext::*callback)( } -// void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input @@ -423,44 +414,32 @@ void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { while ( !(scriptNode = scriptElements.item(i)).isNull() && ++i ){ // retrieve script if( scriptNode.toElement().hasAttribute("src") ){ - QFile scriptFile( getSkinPath( scriptNode.toElement().attribute("src") ) ); - scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); - QTextStream in(&scriptFile); - m_scriptEngine.evaluate( in.readAll() ); - } + QFile scriptFile( getSkinPath( scriptNode.toElement().attribute("src") ) ); + scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); + QTextStream in(&scriptFile); + m_scriptEngine.evaluate( in.readAll() ); + } expression = nodeToString(scriptNode); m_scriptEngine.evaluate( expression ); } - /** / - QScriptValue global = m_scriptEngine.globalObject(); - QScriptValue hookNames; - - if( scriptElements.length() ){ - hookNames = global.property("hookNames").call( global ); - - // qDebug() << "SVG : script. \n" << global.property("hookNames").toString() << "\n"; - qDebug() << "SVG : script. \n" << hookNames.toString() << "\n"; - } - /**/ } -QScriptValue SkinContext::evaluate(QString expression) const { +QScriptValue SkinContext::evaluateTemplateExpression(QString expression) const { QString shell = "\ - (function(){\n\ - var out = '';\n\ - try{\n\ - out = " + expression + ";\n\ - } catch(e){ \n\ - print(e);\n\ - }\n\ - return out;\n\ - })();\n\ - "; - QScriptValue out = m_scriptEngine.evaluate(shell); - - // qDebug() << shell << "\n"; - qDebug() << expression << " -> " << out.toString() << "\n"; - return out; + (function(){\n\ + var out = '';\n\ + try{\n\ + out = " + expression + ";\n\ + } catch(e){ \n\ + print(e);\n\ + }\n\ + return out;\n\ + })();\n\ + "; + QScriptValue out = m_scriptEngine.evaluate(shell); + + // qDebug() << expression << " -> " << out.toString() << "\n"; + return out; } From 5a256b733cdc0df0000a38e4b622e3ab47448af1 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 4 Aug 2014 02:19:12 +0200 Subject: [PATCH 11/90] cleaning --- src/skin/skincontext.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 021489b8bed7..c8a7c7912393 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -69,7 +69,7 @@ class SkinContext { QString setVariablesInSvg(const QDomNode& svgNode) const; void setVariablesInAttributes(const QDomNode& node) const; void parseScriptsInSvg(const QDomNode& svgNode) const; - QScriptValue evaluate(QString expression) const; + QScriptValue evaluateTemplateExpression(QString expression) const; mutable QScriptEngine m_scriptEngine; QHash m_variables; From eb1365a04e7c2c5f54ca49a477e3a0dac792b678 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 7 Aug 2014 02:16:39 +0200 Subject: [PATCH 12/90] debug badly removed test --- src/widget/wpushbutton.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 0268448bea27..cccb6baab9bd 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -68,7 +68,7 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { // Load pixmaps for associated states QDomNode state = context.selectNode(node, "State"); while (!state.isNull()) { - if (state.isElement()) { + if (state.isElement() && state.nodeName() == "State") { // support for variables in State elements SkinContext* stateContext = new SkinContext(context); stateContext->updateVariables(state); From 18cc4056cd4f11a8ea07daaf05ca346d769631f3 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 13 Aug 2014 21:10:39 +0200 Subject: [PATCH 13/90] cleaning + testing script debug --- src/skin/skincontext.cpp | 31 +++++++++++++------ src/waveform/renderers/waveformrenderbeat.cpp | 2 +- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 498b777656fc..53816faa9556 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -342,6 +342,8 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { hooksPattern = "variable"; } + // qDebug() << "hooksPattern : " << hooksPattern << "\n"; + QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) QRegExp nameRx("^(var|expr)-([^=\\s]+)$"); // var-attribute_name="var_name"; @@ -354,11 +356,11 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { // searching variable attributes : var-attribute_name="variable_name" if (nameRx.indexIn(attributeName) != -1) { - if(nameRx.cap(1) == "var"){ - varValue = variable(attributeValue); - } else if(nameRx.cap(1) == "expr"){ + // if(nameRx.cap(1) == "var"){ + // varValue = variable(attributeValue); + // } else if(nameRx.cap(1) == "expr"){ varValue = evaluateTemplateExpression(attributeValue).toString(); - } + // } if (varValue.length()){ element.setAttribute( nameRx.cap(2), varValue); @@ -368,13 +370,13 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { } pos = 0; - // searching expressions in the attribute value (styles or classes) + // searching hooks in the attribute value while ((pos = rx.indexIn(attributeValue, pos)) != -1) { captured = rx.capturedTexts(); match = rx.cap(0); - qDebug() << "Expression : " << match << "\n"; - - replacement = evaluateTemplateExpression( "this.templateHooks." + match ).toString(); + QString tmp = "templateHooks." + match; + // qDebug() << "expression : " << tmp << "\n"; + replacement = evaluateTemplateExpression( tmp ).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); } @@ -433,13 +435,24 @@ QScriptValue SkinContext::evaluateTemplateExpression(QString expression) const { try{\n\ out = " + expression + ";\n\ } catch(e){ \n\ - print(e);\n\ + print( e );\n\ }\n\ return out;\n\ })();\n\ "; QScriptValue out = m_scriptEngine.evaluate(shell); + // e object example : + // print( ' in ' + '\"" + expression.replace("'", "\'") + "\"' );\n + // Debug [Main]: message -> Can't find variable: borderPath + // Debug [Main]: lineNumber -> 4 + // Debug [Main]: sourceId -> 139754315634944 + // Debug [Main]: fileName -> + // Debug [Main]: expressionBeginOffset -> 86 + // Debug [Main]: expressionCaretOffset -> 96 + // Debug [Main]: expressionEndOffset -> 96 + // Debug [Main]: name -> ReferenceError + // qDebug() << expression << " -> " << out.toString() << "\n"; return out; } diff --git a/src/waveform/renderers/waveformrenderbeat.cpp b/src/waveform/renderers/waveformrenderbeat.cpp index 5acdb69909b2..b1be51752491 100644 --- a/src/waveform/renderers/waveformrenderbeat.cpp +++ b/src/waveform/renderers/waveformrenderbeat.cpp @@ -81,7 +81,7 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) { while (it->hasNext()) { int beatPosition = it->next(); double xBeatPoint = m_waveformRenderer->transformSampleIndexInRendererWorld(beatPosition); - + // If we don't have enough space, double the size. if (beatCount >= m_beats.size()) { m_beats.resize(m_beats.size() * 2); From 7586486f4711b0e520afdbec814390ec34e781a9 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 14 Aug 2014 02:55:08 +0200 Subject: [PATCH 14/90] precise beat in waveform --- src/waveform/renderers/waveformrenderbeat.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/waveform/renderers/waveformrenderbeat.cpp b/src/waveform/renderers/waveformrenderbeat.cpp index b1be51752491..48a6cb98219f 100644 --- a/src/waveform/renderers/waveformrenderbeat.cpp +++ b/src/waveform/renderers/waveformrenderbeat.cpp @@ -71,7 +71,7 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) { painter->setRenderHint(QPainter::Antialiasing); QPen beatPen(m_beatColor); - beatPen.setWidthF(1.5); + beatPen.setWidthF(1); painter->setPen(beatPen); const float rendererHeight = m_waveformRenderer->getHeight(); @@ -82,6 +82,8 @@ void WaveformRenderBeat::draw(QPainter* painter, QPaintEvent* /*event*/) { int beatPosition = it->next(); double xBeatPoint = m_waveformRenderer->transformSampleIndexInRendererWorld(beatPosition); + xBeatPoint = qRound(xBeatPoint); + // If we don't have enough space, double the size. if (beatCount >= m_beats.size()) { m_beats.resize(m_beats.size() * 2); From 5922fce7dd5ab7d13fea8364b315534a5001d35b Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 19 Aug 2014 23:51:57 +0200 Subject: [PATCH 15/90] clean exception management for template hooks --- src/skin/skincontext.cpp | 41 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 53816faa9556..6a3bb28b5f3c 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -374,8 +374,8 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { while ((pos = rx.indexIn(attributeValue, pos)) != -1) { captured = rx.capturedTexts(); match = rx.cap(0); - QString tmp = "templateHooks." + match; - // qDebug() << "expression : " << tmp << "\n"; + QString tmp = "templateHooks." + match; + // qDebug() << "expression : " << tmp << "\n"; replacement = evaluateTemplateExpression( tmp ).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); @@ -429,30 +429,15 @@ void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { } QScriptValue SkinContext::evaluateTemplateExpression(QString expression) const { - QString shell = "\ - (function(){\n\ - var out = '';\n\ - try{\n\ - out = " + expression + ";\n\ - } catch(e){ \n\ - print( e );\n\ - }\n\ - return out;\n\ - })();\n\ - "; - QScriptValue out = m_scriptEngine.evaluate(shell); - - // e object example : - // print( ' in ' + '\"" + expression.replace("'", "\'") + "\"' );\n - // Debug [Main]: message -> Can't find variable: borderPath - // Debug [Main]: lineNumber -> 4 - // Debug [Main]: sourceId -> 139754315634944 - // Debug [Main]: fileName -> - // Debug [Main]: expressionBeginOffset -> 86 - // Debug [Main]: expressionCaretOffset -> 96 - // Debug [Main]: expressionEndOffset -> 96 - // Debug [Main]: name -> ReferenceError - - // qDebug() << expression << " -> " << out.toString() << "\n"; - return out; + QScriptValue out = m_scriptEngine.evaluate(expression); + if(m_scriptEngine.hasUncaughtException()){ + qDebug() + << "SVG script exception : " << out.toString() + << "Empty string returned"; + + // return an empty string as remplacement for the in-attribute expression + return QString(); + } else { + return out; + } } From d421390f3e3aa6e9a42f602e2a0a7458284be522 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 00:14:54 +0200 Subject: [PATCH 16/90] remove var-name attributes support --- src/skin/skincontext.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 6a3bb28b5f3c..52c5c4a16aa6 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -345,7 +345,7 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { // qDebug() << "hooksPattern : " << hooksPattern << "\n"; QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) - QRegExp nameRx("^(var|expr)-([^=\\s]+)$"); // var-attribute_name="var_name"; + QRegExp nameRx("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; for (i=0; i < attributes.length(); i++){ @@ -356,14 +356,10 @@ void SkinContext::setVariablesInAttributes(const QDomNode& node) const { // searching variable attributes : var-attribute_name="variable_name" if (nameRx.indexIn(attributeName) != -1) { - // if(nameRx.cap(1) == "var"){ - // varValue = variable(attributeValue); - // } else if(nameRx.cap(1) == "expr"){ - varValue = evaluateTemplateExpression(attributeValue).toString(); - // } + varValue = evaluateTemplateExpression(attributeValue).toString(); if (varValue.length()){ - element.setAttribute( nameRx.cap(2), varValue); + element.setAttribute( nameRx.cap(1), varValue); } continue; @@ -414,7 +410,6 @@ void SkinContext::parseScriptsInSvg(const QDomNode& svgSkinNode) const { QDomNode scriptNode; while ( !(scriptNode = scriptElements.item(i)).isNull() && ++i ){ - // retrieve script if( scriptNode.toElement().hasAttribute("src") ){ QFile scriptFile( getSkinPath( scriptNode.toElement().attribute("src") ) ); scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); From 60b698ac662ba8f9d3fabb22ba918fc2ea4dbfc5 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 12:57:16 +0200 Subject: [PATCH 17/90] splitting svg parser from skincontext to dedicated class --- build/depends.py | 1 + src/skin/skincontext.cpp | 203 ++---------------------------------- src/skin/skincontext.h | 6 -- src/skin/svgparser.cpp | 220 +++++++++++++++++++++++++++++++++++++++ src/skin/svgparser.h | 55 ++++++++++ 5 files changed, 282 insertions(+), 203 deletions(-) create mode 100644 src/skin/svgparser.cpp create mode 100644 src/skin/svgparser.h diff --git a/build/depends.py b/build/depends.py index ed468bb35fe0..f30e95222ce2 100644 --- a/build/depends.py +++ b/build/depends.py @@ -879,6 +879,7 @@ def sources(self, build): "skin/colorschemeparser.cpp", "skin/tooltips.cpp", "skin/skincontext.cpp", + "skin/svgparser.cpp", "sampleutil.cpp", "trackinfoobject.cpp", diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 52c5c4a16aa6..772fb3944f4d 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -4,6 +4,7 @@ #include #include "skin/skincontext.h" +#include "skin/svgparser.h" SkinContext::SkinContext() { } @@ -207,91 +208,16 @@ QString SkinContext::nodeToString(const QDomNode& node) const { return result.join(""); } - -// look for the document of a node -QDomDocument SkinContext::getDocument(const QDomNode& node) const { - - QDomDocument document; - QDomNode parentNode = node; - while( !parentNode.isNull() ){ - if( parentNode.isDocument() ) - document = parentNode.toDocument(); - parentNode = parentNode.parentNode(); - } - - return document; -} - - -// replaces Variables nodes in an svg dom tree -QString SkinContext::setVariablesInSvg(const QDomNode& svgSkinNode) const { - - // clone svg to don't alter xml input - QDomNode svgNode = svgSkinNode.cloneNode(true); - QDomDocument document = getDocument(svgNode); - QDomElement svgElement = svgNode.toElement(); - - // replace variables - QDomNodeList variablesElements = svgElement.elementsByTagName("Variable"); - int i=variablesElements.length()-1; - QDomElement varElement; - QString varName, varValue; - QDomNode varNode, varParentNode, oldChild; - QDomText varValueNode; - - while ( i >= 0 && (varNode = variablesElements.item(i)).isNull() == false ){ - - // retrieve value - varElement = varNode.toElement(); - varName = varElement.attribute("name"); - varValue = variable(varName); - - // replace node by its value - varParentNode = varNode.parentNode(); - varValueNode = document.createTextNode(varValue); - oldChild = varParentNode.replaceChild( varValueNode, varNode ); - - if( oldChild.isNull() ){ - // replaceChild has a really weird behaviour so I add this check - qDebug() << "SVG : unable to replace dom node changed. \n"; - } - - --i; - } - - parseScriptsInSvg(svgNode); - - parseTree(svgNode, &SkinContext::setVariablesInAttributes); - - // Save the new svg in a temp file to use it with setPixmap - QTemporaryFile svgFile; - svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); - - // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove( false ); - - QString svgTempFileName; - if( svgFile.open() ){ - // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; - QTextStream out(&svgFile); - svgNode.save( out, 2 ); - svgFile.close(); - svgTempFileName = svgFile.fileName(); - } else { - qDebug() << "Unable to open temp file for inline svg \n"; - } - - return svgTempFileName; -} - QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; + const SvgParser* scaler = new SvgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = setVariablesInSvg(svgNode); + // pixmapPath = setVariablesInSvg(svgNode); + pixmapPath = scaler->setVariablesInSvg(svgNode); } else { // filename pixmapName = nodeToString(pixmapNode); @@ -305,7 +231,8 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { document.setContent(file); QDomNode svgNode = document.elementsByTagName("svg").item(0); - pixmapPath = setVariablesInSvg(svgNode); + // pixmapPath = setVariablesInSvg(svgNode); + pixmapPath = scaler->setVariablesInSvg(svgNode); file->close(); } } else { @@ -318,121 +245,3 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { return pixmapPath; } - -void SkinContext::setVariablesInAttributes(const QDomNode& node) const { - QDomNamedNodeMap attributes = node.attributes(); - QDomElement element = node.toElement(); - uint i; - int pos; - QString varName, varValue, attributeValue, attributeName, - propName, match, replacement; - QStringList captured; - QDomAttr attribute; - - - QScriptValue global = m_scriptEngine.globalObject(); - QScriptValue hookNames; - QString hooksPattern; - - hookNames = global.property("hookNames").call( global ); - - if( hookNames.toString().length() ){ - hooksPattern = hookNames.property("toPattern").call(hookNames).toString(); - } else { - hooksPattern = "variable"; - } - - // qDebug() << "hooksPattern : " << hooksPattern << "\n"; - - QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) - QRegExp nameRx("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; - - for (i=0; i < attributes.length(); i++){ - - attribute = attributes.item(i).toAttr(); - attributeValue = attribute.value(); - attributeName = attribute.name(); - - // searching variable attributes : var-attribute_name="variable_name" - if (nameRx.indexIn(attributeName) != -1) { - - varValue = evaluateTemplateExpression(attributeValue).toString(); - - if (varValue.length()){ - element.setAttribute( nameRx.cap(1), varValue); - } - - continue; - } - - pos = 0; - // searching hooks in the attribute value - while ((pos = rx.indexIn(attributeValue, pos)) != -1) { - captured = rx.capturedTexts(); - match = rx.cap(0); - QString tmp = "templateHooks." + match; - // qDebug() << "expression : " << tmp << "\n"; - replacement = evaluateTemplateExpression( tmp ).toString(); - attributeValue.replace(pos, match.length(), replacement); - pos += replacement.length(); - } - - attribute.setValue(attributeValue); - } - -} - -void SkinContext::parseTree(const QDomNode& node, void (SkinContext::*callback)(const QDomNode& node)const) const { - - (this->*callback)( node ); - QDomNodeList children = node.childNodes(); - QDomNode child; - uint i; - - for (i=0; i m_variables; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp new file mode 100644 index 000000000000..8c216df39d7a --- /dev/null +++ b/src/skin/svgparser.cpp @@ -0,0 +1,220 @@ +#include +#include +#include +#include + +#include "skin/svgparser.h" + +SvgParser::SvgParser() { +} + +SvgParser::SvgParser(const SkinContext& parent) + : m_variables(parent.variables()) { + // m_skinBasePath(parent.m_skinBasePath) { + QScriptValue context = m_scriptEngine.currentContext()->activationObject(); + for (QHash::const_iterator it = m_variables.begin(); + it != m_variables.end(); ++it) { + context.setProperty(it.key(), it.value()); + } + + p_context = &parent; + +} + +SvgParser::~SvgParser() { +} + +// look for the document of a node +QDomDocument SvgParser::getDocument(const QDomNode& node) const { + + QDomDocument document; + QDomNode parentNode = node; + while( !parentNode.isNull() ){ + if( parentNode.isDocument() ) + document = parentNode.toDocument(); + parentNode = parentNode.parentNode(); + } + + return document; +} + + +// replaces Variables nodes in an svg dom tree +QString SvgParser::setVariablesInSvg(const QDomNode& svgSkinNode) const { + + // clone svg to don't alter xml input + QDomNode svgNode = svgSkinNode.cloneNode(true); + QDomDocument document = getDocument(svgNode); + QDomElement svgElement = svgNode.toElement(); + + // replace variables + QDomNodeList variablesElements = svgElement.elementsByTagName("Variable"); + int i=variablesElements.length()-1; + QDomElement varElement; + QString varName, varValue; + QDomNode varNode, varParentNode, oldChild; + QDomText varValueNode; + + while ( i >= 0 && (varNode = variablesElements.item(i)).isNull() == false ){ + + // retrieve value + varElement = varNode.toElement(); + varName = varElement.attribute("name"); + varValue = p_context->variable(varName); + + // replace node by its value + varParentNode = varNode.parentNode(); + varValueNode = document.createTextNode(varValue); + oldChild = varParentNode.replaceChild( varValueNode, varNode ); + + if( oldChild.isNull() ){ + // replaceChild has a really weird behaviour so I add this check + qDebug() << "SVG : unable to replace dom node changed. \n"; + } + + --i; + } + + parseScriptsInSvg(svgNode); + + parseTree(svgNode, &SvgParser::setVariablesInAttributes); + + // Save the new svg in a temp file to use it with setPixmap + QTemporaryFile svgFile; + svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); + + // the file will be removed before being parsed in skin if set to true + svgFile.setAutoRemove( false ); + + QString svgTempFileName; + if( svgFile.open() ){ + // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; + QTextStream out(&svgFile); + svgNode.save( out, 2 ); + svgFile.close(); + svgTempFileName = svgFile.fileName(); + } else { + qDebug() << "Unable to open temp file for inline svg \n"; + } + + return svgTempFileName; +} + + +void SvgParser::setVariablesInAttributes(const QDomNode& node) const { + QDomNamedNodeMap attributes = node.attributes(); + QDomElement element = node.toElement(); + uint i; + int pos; + QString varName, varValue, attributeValue, attributeName, + propName, match, replacement; + QStringList captured; + QDomAttr attribute; + + + QScriptValue global = m_scriptEngine.globalObject(); + QScriptValue hookNames; + QString hooksPattern; + + hookNames = global.property("hookNames").call( global ); + + if( hookNames.toString().length() ){ + hooksPattern = hookNames.property("toPattern").call(hookNames).toString(); + } else { + hooksPattern = "variable"; + } + + // qDebug() << "hooksPattern : " << hooksPattern << "\n"; + + QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) + QRegExp nameRx("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; + + for (i=0; i < attributes.length(); i++){ + + attribute = attributes.item(i).toAttr(); + attributeValue = attribute.value(); + attributeName = attribute.name(); + + // searching variable attributes : var-attribute_name="variable_name" + if (nameRx.indexIn(attributeName) != -1) { + + varValue = evaluateTemplateExpression(attributeValue).toString(); + + if (varValue.length()){ + element.setAttribute( nameRx.cap(1), varValue); + } + + continue; + } + + pos = 0; + // searching hooks in the attribute value + while ((pos = rx.indexIn(attributeValue, pos)) != -1) { + captured = rx.capturedTexts(); + match = rx.cap(0); + QString tmp = "templateHooks." + match; + // qDebug() << "expression : " << tmp << "\n"; + replacement = evaluateTemplateExpression( tmp ).toString(); + attributeValue.replace(pos, match.length(), replacement); + pos += replacement.length(); + } + + attribute.setValue(attributeValue); + } + +} + +void SvgParser::parseTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { + + (this->*callback)( node ); + QDomNodeList children = node.childNodes(); + QDomNode child; + uint i; + + for (i=0; igetSkinPath( scriptNode.toElement().attribute("src") ) ); + scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); + QTextStream in(&scriptFile); + m_scriptEngine.evaluate( in.readAll() ); + } + + expression = p_context->nodeToString(scriptNode); + m_scriptEngine.evaluate(expression); + } + +} + +QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { + QScriptValue out = m_scriptEngine.evaluate(expression); + if(m_scriptEngine.hasUncaughtException()){ + qDebug() + << "SVG script exception : " << out.toString() + << "Empty string returned"; + + // return an empty string as remplacement for the in-attribute expression + return QString(); + } else { + return out; + } +} diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h new file mode 100644 index 000000000000..4433b51328be --- /dev/null +++ b/src/skin/svgparser.h @@ -0,0 +1,55 @@ +#ifndef SVGPARSER_H +#define SVGPARSER_H + +#include +#include +#include +#include +#include +#include + +#include "skin/skincontext.h" + + +// A class for managing the svg files +class SvgParser { + public: + SvgParser(); + SvgParser(const SkinContext& parent); + virtual ~SvgParser(); + + + // Variable lookup and modification methods. + QString variable(const QString& name) const; + const QHash& variables() const { + return m_variables; + } + void setVariable(const QString& name, const QString& value); + + + // Updates the SkinContext with all the children of node. + void updateVariables(const QDomNode& node); + // Updates the SkinContext with 'element', a node. + void updateVariable(const QDomElement& element); + + // Methods for evaluating nodes given the context. + QDomDocument getDocument(const QDomNode& node) const; + void parseTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; + + + QString setVariablesInSvg(const QDomNode& svgNode) const; + + + private: + void setVariablesInAttributes(const QDomNode& node) const; + void parseScriptsInSvg(const QDomNode& svgNode) const; + QScriptValue evaluateTemplateExpression(QString expression) const; + + mutable QScriptEngine m_scriptEngine; + QHash m_variables; + QString m_skinBasePath; + const SkinContext * p_context; + +}; + +#endif /* SVGPARSER_H */ From ae36056ac39ef6fa2ad7e9b1e4e9eece32e95ea2 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 13:09:11 +0200 Subject: [PATCH 18/90] cleaning names --- src/skin/skincontext.cpp | 6 ++---- src/skin/svgparser.cpp | 7 +++---- src/skin/svgparser.h | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 772fb3944f4d..049d7142e23c 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -216,8 +216,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - // pixmapPath = setVariablesInSvg(svgNode); - pixmapPath = scaler->setVariablesInSvg(svgNode); + pixmapPath = scaler->setVariables(svgNode); } else { // filename pixmapName = nodeToString(pixmapNode); @@ -231,8 +230,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { document.setContent(file); QDomNode svgNode = document.elementsByTagName("svg").item(0); - // pixmapPath = setVariablesInSvg(svgNode); - pixmapPath = scaler->setVariablesInSvg(svgNode); + pixmapPath = scaler->setVariables(svgNode); file->close(); } } else { diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 8c216df39d7a..300847bc5ff6 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -10,7 +10,6 @@ SvgParser::SvgParser() { SvgParser::SvgParser(const SkinContext& parent) : m_variables(parent.variables()) { - // m_skinBasePath(parent.m_skinBasePath) { QScriptValue context = m_scriptEngine.currentContext()->activationObject(); for (QHash::const_iterator it = m_variables.begin(); it != m_variables.end(); ++it) { @@ -40,7 +39,7 @@ QDomDocument SvgParser::getDocument(const QDomNode& node) const { // replaces Variables nodes in an svg dom tree -QString SvgParser::setVariablesInSvg(const QDomNode& svgSkinNode) const { +QString SvgParser::setVariables(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); @@ -75,7 +74,7 @@ QString SvgParser::setVariablesInSvg(const QDomNode& svgSkinNode) const { --i; } - parseScriptsInSvg(svgNode); + parseScriptElements(svgNode); parseTree(svgNode, &SvgParser::setVariablesInAttributes); @@ -179,7 +178,7 @@ void SvgParser::parseTree(const QDomNode& node, void (SvgParser::*callback)(cons } -void SvgParser::parseScriptsInSvg(const QDomNode& svgSkinNode) const { +void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 4433b51328be..1fa38b029dfb 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -37,12 +37,12 @@ class SvgParser { void parseTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QString setVariablesInSvg(const QDomNode& svgNode) const; + QString setVariables(const QDomNode& svgNode) const; private: void setVariablesInAttributes(const QDomNode& node) const; - void parseScriptsInSvg(const QDomNode& svgNode) const; + void parseScriptElements(const QDomNode& svgNode) const; QScriptValue evaluateTemplateExpression(QString expression) const; mutable QScriptEngine m_scriptEngine; From 90cd66287045e3bb3b9fe462754b860c2b25d5d5 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 13:31:53 +0200 Subject: [PATCH 19/90] splitting setVariables and temp file handling --- src/skin/skincontext.cpp | 4 +-- src/skin/svgparser.cpp | 66 +++++++++++++++++++++------------------- src/skin/svgparser.h | 3 +- 3 files changed, 38 insertions(+), 35 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 049d7142e23c..22104e69e046 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -216,7 +216,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = scaler->setVariables(svgNode); + pixmapPath = scaler->parseSvgTree(svgNode); } else { // filename pixmapName = nodeToString(pixmapNode); @@ -230,7 +230,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { document.setContent(file); QDomNode svgNode = document.elementsByTagName("svg").item(0); - pixmapPath = scaler->setVariables(svgNode); + pixmapPath = scaler->parseSvgTree(svgNode); file->close(); } } else { diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 300847bc5ff6..86bd5379f653 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -37,12 +37,41 @@ QDomDocument SvgParser::getDocument(const QDomNode& node) const { return document; } - -// replaces Variables nodes in an svg dom tree -QString SvgParser::setVariables(const QDomNode& svgSkinNode) const { +QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); + + setVariables(svgNode); + + parseScriptElements(svgNode); + + parseTree(svgNode, &SvgParser::setVariablesInAttributes); + + // Save the new svg in a temp file to use it with setPixmap + QTemporaryFile svgFile; + svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); + + // the file will be removed before being parsed in skin if set to true + svgFile.setAutoRemove( false ); + + QString svgTempFileName; + if( svgFile.open() ){ + // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; + QTextStream out(&svgFile); + svgNode.save( out, 2 ); + svgFile.close(); + svgTempFileName = svgFile.fileName(); + } else { + qDebug() << "Unable to open temp file for inline svg \n"; + } + + return svgTempFileName; +} + +// replaces Variables nodes in an svg dom tree +void SvgParser::setVariables(const QDomNode& svgNode) const { + QDomDocument document = getDocument(svgNode); QDomElement svgElement = svgNode.toElement(); @@ -73,30 +102,6 @@ QString SvgParser::setVariables(const QDomNode& svgSkinNode) const { --i; } - - parseScriptElements(svgNode); - - parseTree(svgNode, &SvgParser::setVariablesInAttributes); - - // Save the new svg in a temp file to use it with setPixmap - QTemporaryFile svgFile; - svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); - - // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove( false ); - - QString svgTempFileName; - if( svgFile.open() ){ - // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; - QTextStream out(&svgFile); - svgNode.save( out, 2 ); - svgFile.close(); - svgTempFileName = svgFile.fileName(); - } else { - qDebug() << "Unable to open temp file for inline svg \n"; - } - - return svgTempFileName; } @@ -180,11 +185,8 @@ void SvgParser::parseTree(const QDomNode& node, void (SvgParser::*callback)(cons void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { - // clone svg to don't alter xml input - QDomNode svgNode = svgSkinNode.cloneNode(true); - QDomElement svgElement = svgNode.toElement(); - // parse script content + QDomElement svgElement = svgSkinNode.toElement(); QDomNodeList scriptElements = svgElement.elementsByTagName("script"); int i = 0; QString expression; @@ -212,7 +214,7 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { << "Empty string returned"; // return an empty string as remplacement for the in-attribute expression - return QString(); + return m_scriptEngine.nullValue(); } else { return out; } diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 1fa38b029dfb..852e5eb68578 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -37,7 +37,8 @@ class SvgParser { void parseTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QString setVariables(const QDomNode& svgNode) const; + QString parseSvgTree(const QDomNode& svgSkinNode) const; + void setVariables(const QDomNode& svgNode) const; private: From b58b03f56f0ed913f2395053c9f8f8b7783f3dfd Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 13:56:38 +0200 Subject: [PATCH 20/90] svgparser able to open svg files directly --- src/skin/skincontext.cpp | 11 +---------- src/skin/svgparser.cpp | 14 ++++++++++++++ src/skin/svgparser.h | 1 + 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 22104e69e046..d56870c45c4e 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -223,16 +223,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - - QFile* file = new QFile(pixmapName); - if(file->open(QIODevice::ReadWrite | QIODevice::Text)){ - QDomDocument document; - document.setContent(file); - QDomNode svgNode = document.elementsByTagName("svg").item(0); - - pixmapPath = scaler->parseSvgTree(svgNode); - file->close(); - } + pixmapPath = scaler->parseSvgFile(pixmapName); } else { pixmapPath = pixmapName; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 86bd5379f653..b475992f85ce 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -37,6 +37,20 @@ QDomDocument SvgParser::getDocument(const QDomNode& node) const { return document; } +QString SvgParser::parseSvgFile(const QString& svgFileName) const { + QFile* file = new QFile(svgFileName); + if(file->open(QIODevice::ReadWrite | QIODevice::Text)){ + QDomDocument document; + document.setContent(file); + QDomNode svgNode = document.elementsByTagName("svg").item(0); + QString pixmapPath = parseSvgTree(svgNode); + file->close(); + return pixmapPath; + } else { + return svgFileName; + } +} + QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 852e5eb68578..a171105aa90a 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -38,6 +38,7 @@ class SvgParser { QString parseSvgTree(const QDomNode& svgSkinNode) const; + QString parseSvgFile(const QString& svgFileName) const; void setVariables(const QDomNode& svgNode) const; From a8840d2da5dfc82037717983ce78ec2d0f1c4acf Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 14:45:27 +0200 Subject: [PATCH 21/90] coherent methods naming --- src/skin/svgparser.cpp | 8 ++++---- src/skin/svgparser.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b475992f85ce..6a83d093f963 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -56,11 +56,11 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); - setVariables(svgNode); + parseVariableElements(svgNode); parseScriptElements(svgNode); - parseTree(svgNode, &SvgParser::setVariablesInAttributes); + parseTree(svgNode, &SvgParser::parseAttributes); // Save the new svg in a temp file to use it with setPixmap QTemporaryFile svgFile; @@ -84,7 +84,7 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { } // replaces Variables nodes in an svg dom tree -void SvgParser::setVariables(const QDomNode& svgNode) const { +void SvgParser::parseVariableElements(const QDomNode& svgNode) const { QDomDocument document = getDocument(svgNode); QDomElement svgElement = svgNode.toElement(); @@ -119,7 +119,7 @@ void SvgParser::setVariables(const QDomNode& svgNode) const { } -void SvgParser::setVariablesInAttributes(const QDomNode& node) const { +void SvgParser::parseAttributes(const QDomNode& node) const { QDomNamedNodeMap attributes = node.attributes(); QDomElement element = node.toElement(); uint i; diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index a171105aa90a..8966947f6ec0 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -39,11 +39,11 @@ class SvgParser { QString parseSvgTree(const QDomNode& svgSkinNode) const; QString parseSvgFile(const QString& svgFileName) const; - void setVariables(const QDomNode& svgNode) const; + void parseVariableElements(const QDomNode& svgNode) const; private: - void setVariablesInAttributes(const QDomNode& node) const; + void parseAttributes(const QDomNode& node) const; void parseScriptElements(const QDomNode& svgNode) const; QScriptValue evaluateTemplateExpression(QString expression) const; From fe98fe0eaed0e5986a847f0a5be1867642ab310c Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 14:47:14 +0200 Subject: [PATCH 22/90] coherent methods naming --- src/skin/svgparser.cpp | 2 +- src/skin/svgparser.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 6a83d093f963..913a4bffce76 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -60,7 +60,7 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { parseScriptElements(svgNode); - parseTree(svgNode, &SvgParser::parseAttributes); + scanTree(svgNode, &SvgParser::parseAttributes); // Save the new svg in a temp file to use it with setPixmap QTemporaryFile svgFile; diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 8966947f6ec0..c5b4c6db4cc0 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -34,7 +34,7 @@ class SvgParser { // Methods for evaluating nodes given the context. QDomDocument getDocument(const QDomNode& node) const; - void parseTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; + void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; QString parseSvgTree(const QDomNode& svgSkinNode) const; From 1c74ba4eead897ca32c4b532a28e3764d8cdf8d3 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 20 Aug 2014 14:48:58 +0200 Subject: [PATCH 23/90] coherent methods naming --- src/skin/svgparser.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 913a4bffce76..27e6d0d55425 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -182,7 +182,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { } -void SvgParser::parseTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { +void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { (this->*callback)( node ); QDomNodeList children = node.childNodes(); @@ -192,7 +192,7 @@ void SvgParser::parseTree(const QDomNode& node, void (SvgParser::*callback)(cons for (i=0; i Date: Thu, 21 Aug 2014 22:54:01 +0200 Subject: [PATCH 24/90] cleaning patterns in attributes --- src/skin/svgparser.cpp | 70 +++++++++++++++++++++++++++++------------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 27e6d0d55425..3218cea1b758 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -15,9 +15,8 @@ SvgParser::SvgParser(const SkinContext& parent) it != m_variables.end(); ++it) { context.setProperty(it.key(), it.value()); } - + p_context = &parent; - } SvgParser::~SvgParser() { @@ -83,6 +82,33 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { return svgTempFileName; } + +QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { + + // Save the new svg in a temp file to use it with setPixmap + QTemporaryFile svgFile; + svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); + + // the file will be removed before being parsed in skin if set to true + svgFile.setAutoRemove( false ); + + QString svgTempFileName; + if( svgFile.open() ){ + // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; + QTextStream out(&svgFile); + svgNode.save( out, 2 ); + svgFile.close(); + svgTempFileName = svgFile.fileName(); + } else { + qDebug() << "Unable to open temp file for inline svg \n"; + } + + return svgTempFileName; +} + + + + // replaces Variables nodes in an svg dom tree void SvgParser::parseVariableElements(const QDomNode& svgNode) const { @@ -133,19 +159,19 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QScriptValue global = m_scriptEngine.globalObject(); QScriptValue hookNames; QString hooksPattern; + QRegExp hookRx, nameRx; hookNames = global.property("hookNames").call( global ); if( hookNames.toString().length() ){ - hooksPattern = hookNames.property("toPattern").call(hookNames).toString(); - } else { - hooksPattern = "variable"; + hooksPattern = hookNames.property("toPattern") + .call(hookNames).toString(); + hookRx.setPattern("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) + // qDebug() << "hooksPattern : " << hooksPattern << "\n"; } - // qDebug() << "hooksPattern : " << hooksPattern << "\n"; - QRegExp rx("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) - QRegExp nameRx("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; + nameRx.setPattern("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; for (i=0; i < attributes.length(); i++){ @@ -153,28 +179,28 @@ void SvgParser::parseAttributes(const QDomNode& node) const { attributeValue = attribute.value(); attributeName = attribute.name(); - // searching variable attributes : var-attribute_name="variable_name" + // searching variable attributes : + // expr-attribute_name="variable_name|expression" if (nameRx.indexIn(attributeName) != -1) { - varValue = evaluateTemplateExpression(attributeValue).toString(); - if (varValue.length()){ element.setAttribute( nameRx.cap(1), varValue); } - continue; } - pos = 0; - // searching hooks in the attribute value - while ((pos = rx.indexIn(attributeValue, pos)) != -1) { - captured = rx.capturedTexts(); - match = rx.cap(0); - QString tmp = "templateHooks." + match; - // qDebug() << "expression : " << tmp << "\n"; - replacement = evaluateTemplateExpression( tmp ).toString(); - attributeValue.replace(pos, match.length(), replacement); - pos += replacement.length(); + if( !hookRx.isEmpty() ){ + // searching hooks in the attribute value + pos = 0; + while ((pos = hookRx.indexIn(attributeValue, pos)) != -1) { + captured = hookRx.capturedTexts(); + match = hookRx.cap(0); + QString tmp = "templateHooks." + match; + // qDebug() << "expression : " << tmp << "\n"; + replacement = evaluateTemplateExpression( tmp ).toString(); + attributeValue.replace(pos, match.length(), replacement); + pos += replacement.length(); + } } attribute.setValue(attributeValue); From caaea32803209fae88fa0e335751205b4cf91b88 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 21 Aug 2014 22:59:07 +0200 Subject: [PATCH 25/90] removing QTempFile include --- src/skin/skincontext.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index d56870c45c4e..e465fb3bb755 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "skin/skincontext.h" #include "skin/svgparser.h" @@ -216,7 +215,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = scaler->parseSvgTree(svgNode); + pixmapPath = scaler->parseSvgTree(svgNode); } else { // filename pixmapName = nodeToString(pixmapNode); From dce1e89ed17080806343aaf905cf14adbe9aaf92 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 23 Aug 2014 20:24:56 +0200 Subject: [PATCH 26/90] prettyprint --- src/skin/skincontext.cpp | 6 ++-- src/skin/svgparser.cpp | 70 ++++++++++++++++++++-------------------- src/skin/svgparser.h | 3 +- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index e465fb3bb755..64e4f2e75424 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -209,20 +209,20 @@ QString SkinContext::nodeToString(const QDomNode& node) const { QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - const SvgParser* scaler = new SvgParser(*this); + const SvgParser* pSvgParser = new SvgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = scaler->parseSvgTree(svgNode); + pixmapPath = pSvgParser->parseSvgTree(svgNode); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = scaler->parseSvgFile(pixmapName); + pixmapPath = pSvgParser->parseSvgFile(pixmapName); } else { pixmapPath = pixmapName; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 3218cea1b758..655e01626fd8 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -12,11 +12,11 @@ SvgParser::SvgParser(const SkinContext& parent) : m_variables(parent.variables()) { QScriptValue context = m_scriptEngine.currentContext()->activationObject(); for (QHash::const_iterator it = m_variables.begin(); - it != m_variables.end(); ++it) { + it != m_variables.end(); ++it) { context.setProperty(it.key(), it.value()); } - p_context = &parent; + m_pContext = &parent; } SvgParser::~SvgParser() { @@ -27,9 +27,10 @@ QDomDocument SvgParser::getDocument(const QDomNode& node) const { QDomDocument document; QDomNode parentNode = node; - while( !parentNode.isNull() ){ - if( parentNode.isDocument() ) + while (!parentNode.isNull()) { + if (parentNode.isDocument()) { document = parentNode.toDocument(); + } parentNode = parentNode.parentNode(); } @@ -38,7 +39,7 @@ QDomDocument SvgParser::getDocument(const QDomNode& node) const { QString SvgParser::parseSvgFile(const QString& svgFileName) const { QFile* file = new QFile(svgFileName); - if(file->open(QIODevice::ReadWrite | QIODevice::Text)){ + if (file->open(QIODevice::ReadWrite|QIODevice::Text)) { QDomDocument document; document.setContent(file); QDomNode svgNode = document.elementsByTagName("svg").item(0); @@ -56,9 +57,7 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { QDomNode svgNode = svgSkinNode.cloneNode(true); parseVariableElements(svgNode); - parseScriptElements(svgNode); - scanTree(svgNode, &SvgParser::parseAttributes); // Save the new svg in a temp file to use it with setPixmap @@ -66,13 +65,13 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove( false ); + svgFile.setAutoRemove(false); QString svgTempFileName; - if( svgFile.open() ){ + if (svgFile.open()){ // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; QTextStream out(&svgFile); - svgNode.save( out, 2 ); + svgNode.save(out, 2); svgFile.close(); svgTempFileName = svgFile.fileName(); } else { @@ -90,13 +89,13 @@ QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove( false ); + svgFile.setAutoRemove(false); QString svgTempFileName; - if( svgFile.open() ){ + if (svgFile.open()) { // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; QTextStream out(&svgFile); - svgNode.save( out, 2 ); + svgNode.save(out, 2); svgFile.close(); svgTempFileName = svgFile.fileName(); } else { @@ -123,19 +122,19 @@ void SvgParser::parseVariableElements(const QDomNode& svgNode) const { QDomNode varNode, varParentNode, oldChild; QDomText varValueNode; - while ( i >= 0 && (varNode = variablesElements.item(i)).isNull() == false ){ + while (i >= 0 && (varNode = variablesElements.item(i)).isNull() == false) { // retrieve value varElement = varNode.toElement(); varName = varElement.attribute("name"); - varValue = p_context->variable(varName); + varValue = m_pContext->variable(varName); // replace node by its value varParentNode = varNode.parentNode(); varValueNode = document.createTextNode(varValue); - oldChild = varParentNode.replaceChild( varValueNode, varNode ); + oldChild = varParentNode.replaceChild(varValueNode, varNode); - if( oldChild.isNull() ){ + if (oldChild.isNull()) { // replaceChild has a really weird behaviour so I add this check qDebug() << "SVG : unable to replace dom node changed. \n"; } @@ -161,9 +160,9 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QString hooksPattern; QRegExp hookRx, nameRx; - hookNames = global.property("hookNames").call( global ); + hookNames = global.property("hookNames").call(global); - if( hookNames.toString().length() ){ + if (hookNames.toString().length()) { hooksPattern = hookNames.property("toPattern") .call(hookNames).toString(); hookRx.setPattern("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) @@ -173,7 +172,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { nameRx.setPattern("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; - for (i=0; i < attributes.length(); i++){ + for (i=0; i < attributes.length(); i++) { attribute = attributes.item(i).toAttr(); attributeValue = attribute.value(); @@ -183,13 +182,13 @@ void SvgParser::parseAttributes(const QDomNode& node) const { // expr-attribute_name="variable_name|expression" if (nameRx.indexIn(attributeName) != -1) { varValue = evaluateTemplateExpression(attributeValue).toString(); - if (varValue.length()){ - element.setAttribute( nameRx.cap(1), varValue); + if (varValue.length()) { + element.setAttribute(nameRx.cap(1), varValue); } continue; } - if( !hookRx.isEmpty() ){ + if (!hookRx.isEmpty()) { // searching hooks in the attribute value pos = 0; while ((pos = hookRx.indexIn(attributeValue, pos)) != -1) { @@ -197,7 +196,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { match = hookRx.cap(0); QString tmp = "templateHooks." + match; // qDebug() << "expression : " << tmp << "\n"; - replacement = evaluateTemplateExpression( tmp ).toString(); + replacement = evaluateTemplateExpression(tmp).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); } @@ -210,15 +209,16 @@ void SvgParser::parseAttributes(const QDomNode& node) const { void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { - (this->*callback)( node ); + (this->*callback)(node); QDomNodeList children = node.childNodes(); QDomNode child; uint i; - for (i=0; igetSkinPath( scriptNode.toElement().attribute("src") ) ); - scriptFile.open(QIODevice::ReadOnly | QIODevice::Text); + while (!(scriptNode = scriptElements.item(i)).isNull() && ++i) { + if (scriptNode.toElement().hasAttribute("src")) { + QFile scriptFile(m_pContext->getSkinPath(scriptNode.toElement().attribute("src"))); + scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); - m_scriptEngine.evaluate( in.readAll() ); + m_scriptEngine.evaluate(in.readAll()); } - expression = p_context->nodeToString(scriptNode); + expression = m_pContext->nodeToString(scriptNode); m_scriptEngine.evaluate(expression); } @@ -248,7 +248,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { QScriptValue out = m_scriptEngine.evaluate(expression); - if(m_scriptEngine.hasUncaughtException()){ + if (m_scriptEngine.hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() << "Empty string returned"; diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index c5b4c6db4cc0..8a006fc22574 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -39,6 +39,7 @@ class SvgParser { QString parseSvgTree(const QDomNode& svgSkinNode) const; QString parseSvgFile(const QString& svgFileName) const; + QString saveToTempFile(const QDomNode& svgNode) const; void parseVariableElements(const QDomNode& svgNode) const; @@ -50,7 +51,7 @@ class SvgParser { mutable QScriptEngine m_scriptEngine; QHash m_variables; QString m_skinBasePath; - const SkinContext * p_context; + const SkinContext * m_pContext; }; From 75863cdd4450f86e228e7d3034f6d902b04952e1 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 27 Aug 2014 12:07:06 +0200 Subject: [PATCH 27/90] prettyprint + code dup removal --- src/skin/svgparser.cpp | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 655e01626fd8..271e756a47d4 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -60,28 +60,9 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { parseScriptElements(svgNode); scanTree(svgNode, &SvgParser::parseAttributes); - // Save the new svg in a temp file to use it with setPixmap - QTemporaryFile svgFile; - svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); - - // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove(false); - - QString svgTempFileName; - if (svgFile.open()){ - // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; - QTextStream out(&svgFile); - svgNode.save(out, 2); - svgFile.close(); - svgTempFileName = svgFile.fileName(); - } else { - qDebug() << "Unable to open temp file for inline svg \n"; - } - - return svgTempFileName; + return saveToTempFile(svgNode); } - QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { // Save the new svg in a temp file to use it with setPixmap @@ -105,9 +86,6 @@ QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { return svgTempFileName; } - - - // replaces Variables nodes in an svg dom tree void SvgParser::parseVariableElements(const QDomNode& svgNode) const { @@ -169,7 +147,6 @@ void SvgParser::parseAttributes(const QDomNode& node) const { // qDebug() << "hooksPattern : " << hooksPattern << "\n"; } - nameRx.setPattern("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; for (i=0; i < attributes.length(); i++) { @@ -222,7 +199,6 @@ void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const } } - void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { // parse script content From 83f442d5d2e0688af633a5dba007c6bfeddd39ef Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 27 Aug 2014 13:35:43 +0200 Subject: [PATCH 28/90] 80 char per line max --- src/skin/svgparser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 271e756a47d4..6953e93fc819 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -143,11 +143,14 @@ void SvgParser::parseAttributes(const QDomNode& node) const { if (hookNames.toString().length()) { hooksPattern = hookNames.property("toPattern") .call(hookNames).toString(); - hookRx.setPattern("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // hook( arg1 [, arg2]... ) + + // hook_name( arg1 [, arg2]... ) + hookRx.setPattern("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); // qDebug() << "hooksPattern : " << hooksPattern << "\n"; } - nameRx.setPattern("^expr-([^=\\s]+)$"); // expr-attribute_name="var_name"; + // expr-attribute_name="var_name"; + nameRx.setPattern("^expr-([^=\\s]+)$"); for (i=0; i < attributes.length(); i++) { @@ -164,7 +167,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { } continue; } - + if (!hookRx.isEmpty()) { // searching hooks in the attribute value pos = 0; From 9ac3868829a029c4b39e9f63cd9bc3f7fb47647d Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 4 Sep 2014 16:05:58 +0200 Subject: [PATCH 29/90] beginning --- src/skin/skincontext.cpp | 33 +++++++++++++++++++++++++++++++++ src/skin/skincontext.h | 1 + src/skin/svgparser.cpp | 12 ++++++++++-- src/skin/svgparser.h | 3 ++- src/widget/wpixmapstore.cpp | 26 ++++++++++++++++++++++++++ src/widget/wpixmapstore.h | 2 ++ src/widget/wpushbutton.cpp | 9 +++++---- 7 files changed, 79 insertions(+), 7 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 64e4f2e75424..c7024cfff97d 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -233,3 +233,36 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { return pixmapPath; } + +QByteArray SkinContext::getPixmapBundle(const QDomNode& pixmapNode) const { + /**/ + QString pixmapPath, pixmapName; + const SvgParser* pSvgParser = new SvgParser(*this); + + if (!pixmapNode.isNull()) { + QDomNode svgNode = selectNode(pixmapNode, "svg"); + if (!svgNode.isNull()) { + // inline svg + pixmapPath = pSvgParser->saveToTempFile( + pSvgParser->parseSvgTree(svgNode) ); + } else { + // filename + pixmapName = nodeToString(pixmapNode); + if (!pixmapName.isEmpty()) { + pixmapName = getSkinPath(pixmapName); + if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { + pixmapPath = pSvgParser->parseAsQByteArray(pixmapName); + } else { + pixmapPath = pixmapName; + } + } + } + } + + /**/ + QByteArray tmp; + return tmp; +} + + + diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index a6d3fb880587..0ef83dbb2ba7 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -61,6 +61,7 @@ class SkinContext { QString defaultValue) const; QString nodeToString(const QDomNode& node) const; QString getPixmapPath(const QDomNode& pixmapNode) const; + QByteArray getPixmapBundle(const QDomNode& pixmapNode) const; private: QString variableNodeToText(const QDomElement& element) const; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 6953e93fc819..84d9548961c7 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -51,7 +51,7 @@ QString SvgParser::parseSvgFile(const QString& svgFileName) const { } } -QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { +QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); @@ -60,7 +60,8 @@ QString SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { parseScriptElements(svgNode); scanTree(svgNode, &SvgParser::parseAttributes); - return saveToTempFile(svgNode); + // return saveToTempFile(svgNode); + return svgNode; } QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { @@ -86,6 +87,13 @@ QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { return svgTempFileName; } +QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { + QByteArray out; + QTextStream textStream(&out); + svgNode.save(textStream, 2); + return out; +} + // replaces Variables nodes in an svg dom tree void SvgParser::parseVariableElements(const QDomNode& svgNode) const { diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 8a006fc22574..bfef437b876a 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -37,9 +37,10 @@ class SvgParser { void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QString parseSvgTree(const QDomNode& svgSkinNode) const; + QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; QString parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; + QByteArray parseToQByteArray(const QDomNode& svgNode) const; void parseVariableElements(const QDomNode& svgNode) const; diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 5c4ad0acff79..b354773340dd 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -68,6 +68,32 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) } } +Paintable::Paintable(const QByteArray& pixmapData, DrawMode mode) + : m_draw_mode(mode) { + if (fileName.endsWith(".svg", Qt::CaseInsensitive)) { + if (mode == STRETCH) { + m_pSvg.reset(new QSvgRenderer(pixmapData)); + } else if (mode == TILE) { + // The SVG renderer doesn't directly support tiling, so we render + // it to a pixmap which will then get tiled. + QSvgRenderer renderer(pixmap); + QImage copy_buffer(renderer.defaultSize(), QImage::Format_ARGB32); + copy_buffer.fill(0x00000000); // Transparent black. + m_pPixmap.reset(new QPixmap(renderer.defaultSize())); + QPainter painter(©_buffer); + renderer.render(&painter); + m_pPixmap->convertFromImage(copy_buffer); + } else { + qWarning() << "Error, unknown drawing mode!"; + } + } else { + QPixmap * pPixmap = new QPixmap(); + pPixmap.loadFromData(pixmapData); + m_pPixmap.reset(pPixmap); + } +} + + bool Paintable::isNull() const { if (!m_pPixmap.isNull()) { return m_pPixmap->isNull(); diff --git a/src/widget/wpixmapstore.h b/src/widget/wpixmapstore.h index 6744a307b2cd..88d08c5b616d 100644 --- a/src/widget/wpixmapstore.h +++ b/src/widget/wpixmapstore.h @@ -73,6 +73,8 @@ class WPixmapStore { public: static PaintablePointer getPaintable(const QString& fileName, Paintable::DrawMode mode); + static PaintablePointer getPaintable(const QByteArray& fileName, + Paintable::DrawMode mode); static QPixmap* getPixmapNoCache(const QString& fileName); static void setLoader(QSharedPointer ld); diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index cccb6baab9bd..bac14aef5fca 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -202,7 +202,8 @@ void WPushButton::setStates(int iStates) { m_align.resize(iStates); } -void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { +// void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { +template void WPushButton::setPixmap(int iState, bool bPressed, const pixmapBundle sPixmapBundle) { QVector& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -210,13 +211,13 @@ void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, + PaintablePointer pPixmap = WPixmapStore::getPaintable(sPixmapBundle, Paintable::STRETCH); if (pPixmap.isNull() || pPixmap->isNull()) { // Only log if it looks like the user tried to specify a pixmap. - if (!filename.isEmpty()) { - qDebug() << "WPushButton: Error loading pixmap:" << filename; + if (!sPixmapBundle.isEmpty()) { + qDebug() << "WPushButton: Error loading pixmap:" << sPixmapBundle; } } else { // Set size of widget equal to pixmap size From 31024eae7af4d333063c7dd382c825f2ab1d1c98 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Fri, 5 Sep 2014 17:05:24 +0200 Subject: [PATCH 30/90] buildable wip --- src/skin/skincontext.cpp | 12 ++++++------ src/skin/svgparser.cpp | 11 ++++++----- src/skin/svgparser.h | 4 ++-- src/widget/wpixmapstore.cpp | 2 ++ src/widget/wpushbutton.cpp | 9 +++++---- src/widget/wpushbutton.h | 2 ++ 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index c7024cfff97d..37bebd6f1abe 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -215,14 +215,14 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = pSvgParser->parseSvgTree(svgNode); + pixmapPath = pSvgParser->saveToTempFile(pSvgParser->parseSvgTree(svgNode)); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = pSvgParser->parseSvgFile(pixmapName); + pixmapPath = pSvgParser->saveToTempFile( pSvgParser->parseSvgFile(pixmapName) ); } else { pixmapPath = pixmapName; } @@ -237,13 +237,14 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QByteArray SkinContext::getPixmapBundle(const QDomNode& pixmapNode) const { /**/ QString pixmapPath, pixmapName; + QByteArray out; const SvgParser* pSvgParser = new SvgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = pSvgParser->saveToTempFile( + out = pSvgParser->saveToQByteArray( pSvgParser->parseSvgTree(svgNode) ); } else { // filename @@ -251,7 +252,7 @@ QByteArray SkinContext::getPixmapBundle(const QDomNode& pixmapNode) const { if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = pSvgParser->parseAsQByteArray(pixmapName); + pixmapPath = pSvgParser->saveToQByteArray( pSvgParser->parseSvgFile(pixmapName) ); } else { pixmapPath = pixmapName; } @@ -260,8 +261,7 @@ QByteArray SkinContext::getPixmapBundle(const QDomNode& pixmapNode) const { } /**/ - QByteArray tmp; - return tmp; + return out; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 84d9548961c7..2cdf3c1c4e09 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -37,18 +37,19 @@ QDomDocument SvgParser::getDocument(const QDomNode& node) const { return document; } -QString SvgParser::parseSvgFile(const QString& svgFileName) const { +QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { QFile* file = new QFile(svgFileName); + QDomNode out; if (file->open(QIODevice::ReadWrite|QIODevice::Text)) { QDomDocument document; document.setContent(file); QDomNode svgNode = document.elementsByTagName("svg").item(0); - QString pixmapPath = parseSvgTree(svgNode); + out = parseSvgTree(svgNode); file->close(); - return pixmapPath; - } else { - return svgFileName; + return out; } + + return out; } QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index bfef437b876a..72ed1558d68e 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -38,9 +38,9 @@ class SvgParser { QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; - QString parseSvgFile(const QString& svgFileName) const; + QDomNode parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; - QByteArray parseToQByteArray(const QDomNode& svgNode) const; + QByteArray saveToQByteArray(const QDomNode& svgNode) const; void parseVariableElements(const QDomNode& svgNode) const; diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index b354773340dd..bf8a6764fc9c 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -68,6 +68,7 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) } } +/** / Paintable::Paintable(const QByteArray& pixmapData, DrawMode mode) : m_draw_mode(mode) { if (fileName.endsWith(".svg", Qt::CaseInsensitive)) { @@ -92,6 +93,7 @@ Paintable::Paintable(const QByteArray& pixmapData, DrawMode mode) m_pPixmap.reset(pPixmap); } } +/**/ bool Paintable::isNull() const { diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index bac14aef5fca..3c31a0cf590d 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -203,7 +203,8 @@ void WPushButton::setStates(int iStates) { } // void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { -template void WPushButton::setPixmap(int iState, bool bPressed, const pixmapBundle sPixmapBundle) { +template +void WPushButton::setPixmap(int iState, bool bPressed, const pixmapSource sPixmapSource) { QVector& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -211,13 +212,13 @@ template void WPushButton::setPixmap(int iState, bool bPr return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(sPixmapBundle, + PaintablePointer pPixmap = WPixmapStore::getPaintable(sPixmapSource, Paintable::STRETCH); if (pPixmap.isNull() || pPixmap->isNull()) { // Only log if it looks like the user tried to specify a pixmap. - if (!sPixmapBundle.isEmpty()) { - qDebug() << "WPushButton: Error loading pixmap:" << sPixmapBundle; + if (!sPixmapSource.isEmpty()) { + qDebug() << "WPushButton: Error loading pixmap:" << sPixmapSource; } } else { // Set size of widget equal to pixmap size diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index f318078f6936..4b327128a83f 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -79,6 +79,8 @@ class WPushButton : public WWidget { private: // Associates a pixmap of a given state of the button with the widget void setPixmap(int iState, bool bPressed, const QString &filename); + template + void setPixmap(int iState, bool bPressed, const pixmapSource sPixmapSource); // Associates a background pixmap with the widget. This is only needed if // the button pixmaps contains alpha channel values. From 1b0f43d027a868492ea0af60716e41fe1abf5133 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 12:06:25 +0200 Subject: [PATCH 31/90] first working solution --- src/skin/pixmapsource.cpp | 58 +++++++++++++++++++++++ src/skin/pixmapsource.h | 28 +++++++++++ src/skin/skincontext.cpp | 34 +++++++++----- src/skin/skincontext.h | 8 +++- src/widget/wpixmapstore.cpp | 92 +++++++++++++++++++++++++++++++++---- src/widget/wpixmapstore.h | 6 ++- src/widget/wpushbutton.cpp | 75 ++++++++++++++++++++++++------ src/widget/wpushbutton.h | 9 ++-- src/widget/wvumeter.cpp | 31 ++++++++++++- src/widget/wvumeter.h | 3 ++ 10 files changed, 300 insertions(+), 44 deletions(-) create mode 100644 src/skin/pixmapsource.cpp create mode 100644 src/skin/pixmapsource.h diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp new file mode 100644 index 000000000000..73355bb66c60 --- /dev/null +++ b/src/skin/pixmapsource.cpp @@ -0,0 +1,58 @@ +#include + +#include "skin/pixmapsource.h" + +PixmapSource::PixmapSource() { +} + +PixmapSource::~PixmapSource() { +} + +QByteArray PixmapSource::getData() const { + return data; +} + +QString PixmapSource::getType() const { + return type; +} + +QString PixmapSource::getPath() const { + return path; +} + +void PixmapSource::setPath( QString newPath ) { + path = newPath; +} + +bool PixmapSource::isEmpty() { + return path.isEmpty() && data.isEmpty() ; +} + +void PixmapSource::setSVG( QByteArray content ) { + data.truncate(0); + data += content; + type = "svg"; +} + +void PixmapSource::setSVG( QString filepath ) { + data.truncate(0); + path = filepath; + type = "svg"; +} + +void PixmapSource::setBitmap( QString filepath ) { + path = filepath; + type = "bitmap"; +} + +QString PixmapSource::getId() const { + quint16 checksum; + QString out; + if (data.isEmpty()) { + checksum = qChecksum( path.toAscii().constData(), path.length() ); + } else { + checksum = qChecksum( data.constData(), data.length() ); + } + return path + out.setNum(checksum); +} + diff --git a/src/skin/pixmapsource.h b/src/skin/pixmapsource.h new file mode 100644 index 000000000000..e005b04784a7 --- /dev/null +++ b/src/skin/pixmapsource.h @@ -0,0 +1,28 @@ +#ifndef PIXMAPSOURCE_H +#define PIXMAPSOURCE_H + +#include + +// A class representing an image source for a pixmap (file path, raw data, svg ) +class PixmapSource { + public: + PixmapSource(); + virtual ~PixmapSource(); + + bool isEmpty(); + void setSVG( QByteArray content ); + void setSVG( QString filepath ); + void setBitmap( QString filepath ); + void setPath( QString newPath ); + QString getPath() const; + QString getType() const; + QByteArray getData() const; + QString getId() const; + + private: + QString path; + QString type; + QByteArray data; +}; + +#endif /* PIXMAPSOURCE_H */ diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 37bebd6f1abe..7199dc8af5dc 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -207,6 +207,8 @@ QString SkinContext::nodeToString(const QDomNode& node) const { return result.join(""); } + + QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; const SvgParser* pSvgParser = new SvgParser(*this); @@ -215,14 +217,16 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = pSvgParser->saveToTempFile(pSvgParser->parseSvgTree(svgNode)); + pixmapPath = pSvgParser->saveToTempFile( + pSvgParser->parseSvgTree(svgNode) ); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = pSvgParser->saveToTempFile( pSvgParser->parseSvgFile(pixmapName) ); + pixmapPath = pSvgParser->saveToTempFile( + pSvgParser->parseSvgFile(pixmapName) ); } else { pixmapPath = pixmapName; } @@ -234,34 +238,40 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { } -QByteArray SkinContext::getPixmapBundle(const QDomNode& pixmapNode) const { - /**/ +// template +PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - QByteArray out; + PixmapSource* source = new PixmapSource(); + const SvgParser* pSvgParser = new SvgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - out = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgTree(svgNode) ); + const QByteArray rslt = pSvgParser->saveToQByteArray( + pSvgParser->parseSvgTree(svgNode) ); + source->setSVG( rslt ); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { - pixmapName = getSkinPath(pixmapName); + source->setPath( getSkinPath(pixmapName) ); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = pSvgParser->saveToQByteArray( pSvgParser->parseSvgFile(pixmapName) ); + const QByteArray rslt = pSvgParser->saveToQByteArray( + pSvgParser->parseSvgFile(source->getPath()) ); + source->setSVG( rslt ); } else { - pixmapPath = pixmapName; + source->setBitmap(getSkinPath(pixmapName)); } } } } - /**/ - return out; + qDebug() << "getPixmapSource out path" << source->getPath(); + + // return out; + return source; } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 0ef83dbb2ba7..64c7e0619011 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -8,6 +8,8 @@ #include #include +#include "skin/pixmapsource.h" + // A class for managing the current context/environment when processing a // skin. Used hierarchically by LegacySkinParser to create new contexts and // evaluate skin XML nodes while loading the skin. @@ -61,7 +63,11 @@ class SkinContext { QString defaultValue) const; QString nodeToString(const QDomNode& node) const; QString getPixmapPath(const QDomNode& pixmapNode) const; - QByteArray getPixmapBundle(const QDomNode& pixmapNode) const; + // QByteArray getPixmapSource(const QDomNode& pixmapNode) const; + + + // template + PixmapSource* getPixmapSource(const QDomNode& pixmapNode) const; private: QString variableNodeToText(const QDomElement& element) const; diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index bf8a6764fc9c..2cde156cd17b 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -19,6 +19,7 @@ #include #include +#include // static QHash WPixmapStore::m_paintableCache; @@ -68,28 +69,62 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) } } -/** / -Paintable::Paintable(const QByteArray& pixmapData, DrawMode mode) +/**/ +Paintable::Paintable(PixmapSource* source, DrawMode mode) : m_draw_mode(mode) { - if (fileName.endsWith(".svg", Qt::CaseInsensitive)) { + if (source->getType() == "svg") { if (mode == STRETCH) { - m_pSvg.reset(new QSvgRenderer(pixmapData)); + QSvgRenderer* pSvgRenderer; + if( source->getData().isEmpty() ){ + qWarning() << "Paintable stretch path" << source->getPath(); + pSvgRenderer = new QSvgRenderer(source->getPath()); + } else { + qWarning() << "Paintable stretch data" << source->getData(); + pSvgRenderer = new QSvgRenderer(source->getData()); + } + m_pSvg.reset(pSvgRenderer); } else if (mode == TILE) { + // qWarning() << "Paintable tile" << source->getPath(); // The SVG renderer doesn't directly support tiling, so we render // it to a pixmap which will then get tiled. - QSvgRenderer renderer(pixmap); - QImage copy_buffer(renderer.defaultSize(), QImage::Format_ARGB32); + // QSvgRenderer renderer(!source->getData().isEmpty() + // ? source->getData() : source->getPath()); + // QSvgRenderer renderer(); + + QSvgRenderer* pSvgRenderer; + if( source->getData().isEmpty() ){ + qWarning() << "Paintable tile path" << source->getPath(); + pSvgRenderer = new QSvgRenderer(source->getPath()); + // renderer.load(source->getPath()); + } else { + qWarning() << "Paintable tile data" << source->getData(); + // renderer.load(source->getData()); + pSvgRenderer = new QSvgRenderer(source->getData()); + } + // m_pSvg.reset(pSvgRenderer); + // QSvgRenderer renderer = (*pSvgRenderer); + + // QImage copy_buffer(renderer.defaultSize(), QImage::Format_ARGB32); + // copy_buffer.fill(0x00000000); // Transparent black. + // m_pPixmap.reset(new QPixmap(renderer.defaultSize())); + // QPainter painter(©_buffer); + // renderer.render(&painter); + QImage copy_buffer(pSvgRenderer->defaultSize(), QImage::Format_ARGB32); copy_buffer.fill(0x00000000); // Transparent black. - m_pPixmap.reset(new QPixmap(renderer.defaultSize())); + m_pPixmap.reset(new QPixmap(pSvgRenderer->defaultSize())); QPainter painter(©_buffer); - renderer.render(&painter); + pSvgRenderer->render(&painter); m_pPixmap->convertFromImage(copy_buffer); } else { qWarning() << "Error, unknown drawing mode!"; } } else { QPixmap * pPixmap = new QPixmap(); - pPixmap.loadFromData(pixmapData); + if (!source->getData().isEmpty()){ + pPixmap->loadFromData(source->getData()); + } else { + pPixmap->load(source->getPath()); + } m_pPixmap.reset(pPixmap); } } @@ -237,6 +272,45 @@ PaintablePointer WPixmapStore::getPaintable(const QString& fileName, return pPaintable; } +// static +PaintablePointer WPixmapStore::getPaintable(PixmapSource* source, + Paintable::DrawMode mode) { + // See if we have a cached value for the pixmap. + PaintablePointer pPaintable = m_paintableCache.value(source->getId(), PaintablePointer()); + if (pPaintable) { + return pPaintable; + } + + // Otherwise, construct it with the pixmap loader. + qDebug() << "WPixmapStore Loading pixmap from file" << source->getPath(); + + if (m_loader) { + qDebug() << "WPixmapStore::getPaintable loader" << source->getPath(); + QImage* pImage = m_loader->getImage(source->getPath()); + pPaintable = PaintablePointer(new Paintable(pImage, mode)); + } else { + qDebug() << "WPixmapStore::getPaintable no loader" << source->getPath(); + pPaintable = PaintablePointer(new Paintable(source, mode)); + } + + if (pPaintable.isNull() || pPaintable->isNull()) { + // Only log if it looks like the user tried to specify a + // pixmap. Otherwise we probably just have a widget that is calling + // getPaintable without checking that the skinner actually wanted one. + if (!source->isEmpty()) { + qDebug() << "WPixmapStore couldn't load:" << source->getPath() + << pPaintable.isNull(); + } + return PaintablePointer(); + } + + m_paintableCache[source->getId()] = pPaintable; + return pPaintable; +} + + + + // static QPixmap* WPixmapStore::getPixmapNoCache(const QString& fileName) { QPixmap* pPixmap = NULL; diff --git a/src/widget/wpixmapstore.h b/src/widget/wpixmapstore.h index 88d08c5b616d..0ec0b8deab63 100644 --- a/src/widget/wpixmapstore.h +++ b/src/widget/wpixmapstore.h @@ -28,6 +28,7 @@ #include #include "skin/imgsource.h" +#include "skin/skincontext.h" class QString; @@ -43,6 +44,7 @@ class Paintable { // Takes ownership of QImage. Paintable(QImage* pImage, DrawMode mode); Paintable(const QString& fileName, DrawMode mode); + Paintable(PixmapSource* source, DrawMode mode); QSize size() const; int width() const; @@ -73,8 +75,8 @@ class WPixmapStore { public: static PaintablePointer getPaintable(const QString& fileName, Paintable::DrawMode mode); - static PaintablePointer getPaintable(const QByteArray& fileName, - Paintable::DrawMode mode); + static PaintablePointer getPaintable(PixmapSource* source, + Paintable::DrawMode mode); static QPixmap* getPixmapNoCache(const QString& fileName); static void setLoader(QSharedPointer ld); diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 3c31a0cf590d..9de6f3c0c01e 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -59,9 +59,10 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - QString backPath = context.getPixmapPath(context.selectNode(node, "BackPath")); - if (!backPath.isEmpty()) { - setPixmapBackground(backPath, Paintable::DrawModeFromString(mode_str)); + // QString backPath = context.getPixmapPath(context.selectNode(node, "BackPath")); + PixmapSource* backgroundSource = context.getPixmapSource(context.selectNode(node, "BackPath")); + if (!backgroundSource->isEmpty()) { + setPixmapBackground(backgroundSource, Paintable::DrawModeFromString(mode_str)); } } @@ -76,15 +77,18 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { int iState = stateContext->selectInt(state, "Number"); if (iState < m_iNoStates) { QString pixmapPath; + PixmapSource* pixmapSource; - pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Unpressed")); - if (!pixmapPath.isEmpty()) { - setPixmap(iState, false, pixmapPath); + // pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Unpressed")); + pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Unpressed")); + if (!pixmapSource->isEmpty()) { + setPixmap(iState, false, pixmapSource); } - pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Pressed")); - if (!pixmapPath.isEmpty()) { - setPixmap(iState, true, pixmapPath); + // pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Pressed")); + pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Pressed")); + if (!pixmapSource->isEmpty()) { + setPixmap(iState, true, pixmapSource); } m_text.replace(iState, stateContext->selectString(state, "Text")); @@ -202,9 +206,10 @@ void WPushButton::setStates(int iStates) { m_align.resize(iStates); } -// void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { -template -void WPushButton::setPixmap(int iState, bool bPressed, const pixmapSource sPixmapSource) { + + + +void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { QVector& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -212,13 +217,13 @@ void WPushButton::setPixmap(int iState, bool bPressed, const pixmapSource sPixma return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(sPixmapSource, + PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, Paintable::STRETCH); if (pPixmap.isNull() || pPixmap->isNull()) { // Only log if it looks like the user tried to specify a pixmap. - if (!sPixmapSource.isEmpty()) { - qDebug() << "WPushButton: Error loading pixmap:" << sPixmapSource; + if (!filename.isEmpty()) { + qDebug() << "WPushButton: Error loading pixmap:" << filename; } } else { // Set size of widget equal to pixmap size @@ -227,6 +232,33 @@ void WPushButton::setPixmap(int iState, bool bPressed, const pixmapSource sPixma pixmaps.replace(iState, pPixmap); } + +void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource* source) { + QVector& pixmaps = bPressed ? + m_pressedPixmaps : m_unpressedPixmaps; + + if (iState < 0 || iState >= pixmaps.size()) { + return; + } + + PaintablePointer pPixmap = WPixmapStore::getPaintable(source, + Paintable::STRETCH); + + 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 { + // Set size of widget equal to pixmap size + setFixedSize(pPixmap->size()); + } + pixmaps.replace(iState, pPixmap); +} + + + + void WPushButton::setPixmapBackground(const QString &filename, Paintable::DrawMode mode) { // Load background pixmap @@ -238,6 +270,19 @@ void WPushButton::setPixmapBackground(const QString &filename, } } +void WPushButton::setPixmapBackground(PixmapSource* source, + Paintable::DrawMode mode) { + // Load background pixmap + m_pPixmapBack = WPixmapStore::getPaintable(source, mode); + if (!source->isEmpty() && + (m_pPixmapBack.isNull() || m_pPixmapBack->isNull())) { + // Only log if it looks like the user tried to specify a pixmap. + qDebug() << "WPushButton: Error loading background pixmap:" << source->getPath(); + } +} + + + void WPushButton::onConnectedControlChanged(double dParameter, double dValue) { Q_UNUSED(dParameter); // Enums are not currently represented using parameter space so it doesn't diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index 4b327128a83f..2d22bd46fbeb 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -78,13 +78,16 @@ class WPushButton : public WWidget { private: // Associates a pixmap of a given state of the button with the widget - void setPixmap(int iState, bool bPressed, const QString &filename); - template - void setPixmap(int iState, bool bPressed, const pixmapSource sPixmapSource); + // template + void setPixmap(int iState, bool bPressed, PixmapSource* source); + void setPixmap(int iState, bool bPressed, const QString& filename); + // void setPixmap(int iState, bool bPressed, const QString &filename); // Associates a background pixmap with the widget. This is only needed if // the button pixmaps contains alpha channel values. void setPixmapBackground(const QString &filename, Paintable::DrawMode mode); + void setPixmapBackground(PixmapSource* source, + Paintable::DrawMode mode); // True, if the button is currently pressed bool m_bPressed; diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index b88398752e6c..b3b21a2c4726 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -57,10 +57,10 @@ void WVuMeter::setup(QDomNode node, const SkinContext& context) { // Set background pixmap if available if (context.hasNode(node, "PathBack")) { - setPixmapBackground(context.getPixmapPath(context.selectNode(node, "PathBack"))); + setPixmapBackground(context.getPixmapSource(context.selectNode(node, "PathBack"))); } - setPixmaps(context.getPixmapPath(context.selectNode(node, "PathVu")), bHorizontal); + setPixmaps(context.getPixmapSource(context.selectNode(node, "PathVu")), bHorizontal); m_iPeakHoldSize = context.selectInt(node, "PeakHoldSize"); if (m_iPeakHoldSize < 0 || m_iPeakHoldSize > 100) @@ -95,6 +95,17 @@ void WVuMeter::setPixmapBackground(const QString& filename) { } } +void WVuMeter::setPixmapBackground(PixmapSource* source) { + m_pPixmapBack = WPixmapStore::getPaintable(source, + Paintable::TILE); + if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { + qDebug() << metaObject()->className() + << "Error loading background pixmap:" << source->getPath(); + } else { + setFixedSize(m_pPixmapBack->size()); + } +} + void WVuMeter::setPixmaps(const QString &vuFilename, bool bHorizontal) { m_pPixmapVu = WPixmapStore::getPaintable(vuFilename, @@ -111,6 +122,22 @@ void WVuMeter::setPixmaps(const QString &vuFilename, } } +void WVuMeter::setPixmaps(PixmapSource* vuSource, + bool bHorizontal) { + m_pPixmapVu = WPixmapStore::getPaintable(vuSource, + Paintable::STRETCH); + if (m_pPixmapVu.isNull() || m_pPixmapVu->isNull()) { + qDebug() << "WVuMeter: Error loading vu pixmap" << vuSource->getPath(); + } else { + m_bHorizontal = bHorizontal; + if (m_bHorizontal) { + m_iNoPos = m_pPixmapVu->width(); + } else { + m_iNoPos = m_pPixmapVu->height(); + } + } +} + void WVuMeter::onConnectedControlChanged(double dParameter, double dValue) { Q_UNUSED(dValue); m_iPos = static_cast(dParameter * m_iNoPos); diff --git a/src/widget/wvumeter.h b/src/widget/wvumeter.h index 4008054e8649..1bfa227c68f9 100644 --- a/src/widget/wvumeter.h +++ b/src/widget/wvumeter.h @@ -37,6 +37,9 @@ class WVuMeter : public WWidget { void setup(QDomNode node, const SkinContext& context); void setPixmapBackground(const QString& filename); + void setPixmapBackground(PixmapSource* source); + void setPixmaps(PixmapSource* vuSource, + bool bHorizontal=false); void setPixmaps(const QString &vuFilename, bool bHorizontal=false); void onConnectedControlChanged(double dParameter, double dValue); From 479ab4e1448e8d6b859ef1e90411e6b3aecfddb2 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 12:59:01 +0200 Subject: [PATCH 32/90] spreading getPixmapSource --- src/widget/wdisplay.cpp | 8 +++---- src/widget/wdisplay.h | 2 +- src/widget/wknobcomposed.cpp | 16 ++++++------- src/widget/wknobcomposed.h | 4 ++-- src/widget/wpixmapstore.cpp | 42 ++++++++-------------------------- src/widget/wpushbutton.cpp | 3 --- src/widget/wslidercomposed.cpp | 35 ++++++++++++++++++++++++---- src/widget/wslidercomposed.h | 2 ++ src/widget/wspinny.cpp | 12 +++++----- src/widget/wstatuslight.cpp | 36 ++++++++++++++++++++++++++--- src/widget/wstatuslight.h | 1 + src/widget/wwidgetgroup.cpp | 10 +++++++- src/widget/wwidgetgroup.h | 1 + 13 files changed, 107 insertions(+), 65 deletions(-) diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index 4958fe047bd4..ab9b72fec4e0 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -42,7 +42,7 @@ void WDisplay::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - setPixmapBackground(context.getPixmapPath(context.selectNode(node, "BackPath")), + setPixmapBackground(context.getPixmapSource(context.selectNode(node, "BackPath")), Paintable::DrawModeFromString(mode_str)); } @@ -86,12 +86,12 @@ void WDisplay::resetPositions() { m_disabledPixmaps.resize(0); } -void WDisplay::setPixmapBackground(const QString& filename, +void WDisplay::setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode) { - m_pPixmapBack = WPixmapStore::getPaintable(filename, mode); + m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() - << "Error loading background pixmap:" << filename; + << "Error loading background pixmap:" << pSource->getPath(); } } diff --git a/src/widget/wdisplay.h b/src/widget/wdisplay.h index cd4a172f0ea4..a5feb1575814 100644 --- a/src/widget/wdisplay.h +++ b/src/widget/wdisplay.h @@ -48,7 +48,7 @@ class WDisplay : public WWidget { void setPixmap(QVector* pPixmaps, int iPos, const QString& filename); - void setPixmapBackground(const QString& filename, Paintable::DrawMode mode); + void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); void setPositions(int iNoPos); diff --git a/src/widget/wknobcomposed.cpp b/src/widget/wknobcomposed.cpp index 75cb1decdb8a..74b990308a3a 100644 --- a/src/widget/wknobcomposed.cpp +++ b/src/widget/wknobcomposed.cpp @@ -20,13 +20,13 @@ void WKnobComposed::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - setPixmapBackground(context.getPixmapPath(context.selectNode(node, "BackPath")), + setPixmapBackground(context.getPixmapSource(context.selectNode(node, "BackPath")), Paintable::DrawModeFromString(mode_str)); } // Set background pixmap if available if (context.hasNode(node, "Knob")) { - setPixmapKnob(context.getPixmapPath(context.selectNode(node, "Knob"))); + setPixmapKnob(context.getPixmapSource(context.selectNode(node, "Knob"))); } if (context.hasNode(node, "MinAngle")) { @@ -43,20 +43,20 @@ void WKnobComposed::clear() { m_pKnob.clear(); } -void WKnobComposed::setPixmapBackground(const QString& filename, +void WKnobComposed::setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode) { - m_pPixmapBack = WPixmapStore::getPaintable(filename, mode); + m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() - << "Error loading background pixmap:" << filename; + << "Error loading background pixmap:" << pSource->getPath(); } } -void WKnobComposed::setPixmapKnob(const QString& filename) { - m_pKnob = WPixmapStore::getPaintable(filename, Paintable::STRETCH); +void WKnobComposed::setPixmapKnob(PixmapSource* pSource) { + m_pKnob = WPixmapStore::getPaintable(pSource, Paintable::STRETCH); if (m_pKnob.isNull() || m_pKnob->isNull()) { qDebug() << metaObject()->className() - << "Error loading knob pixmap:" << filename; + << "Error loading knob pixmap:" << pSource->getPath(); } } diff --git a/src/widget/wknobcomposed.h b/src/widget/wknobcomposed.h index 776120ad99a1..e40577ed9ab9 100644 --- a/src/widget/wknobcomposed.h +++ b/src/widget/wknobcomposed.h @@ -31,8 +31,8 @@ class WKnobComposed : public WWidget { private: void clear(); - void setPixmapBackground(const QString& filename, Paintable::DrawMode mode); - void setPixmapKnob(const QString& filename); + void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); + void setPixmapKnob(PixmapSource* pSource); double m_dCurrentAngle; PaintablePointer m_pKnob; diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 2cde156cd17b..6379761180d9 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -73,42 +73,20 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) Paintable::Paintable(PixmapSource* source, DrawMode mode) : m_draw_mode(mode) { if (source->getType() == "svg") { + QSvgRenderer* pSvgRenderer = new QSvgRenderer(); + if( source->getData().isEmpty() ){ + // qWarning() << "Paintable stretch path" << source->getPath(); + pSvgRenderer->load(source->getPath()); + } else { + // qWarning() << "Paintable stretch data" << source->getData(); + pSvgRenderer->load(source->getData()); + } + if (mode == STRETCH) { - QSvgRenderer* pSvgRenderer; - if( source->getData().isEmpty() ){ - qWarning() << "Paintable stretch path" << source->getPath(); - pSvgRenderer = new QSvgRenderer(source->getPath()); - } else { - qWarning() << "Paintable stretch data" << source->getData(); - pSvgRenderer = new QSvgRenderer(source->getData()); - } m_pSvg.reset(pSvgRenderer); } else if (mode == TILE) { - // qWarning() << "Paintable tile" << source->getPath(); // The SVG renderer doesn't directly support tiling, so we render // it to a pixmap which will then get tiled. - // QSvgRenderer renderer(!source->getData().isEmpty() - // ? source->getData() : source->getPath()); - // QSvgRenderer renderer(); - - QSvgRenderer* pSvgRenderer; - if( source->getData().isEmpty() ){ - qWarning() << "Paintable tile path" << source->getPath(); - pSvgRenderer = new QSvgRenderer(source->getPath()); - // renderer.load(source->getPath()); - } else { - qWarning() << "Paintable tile data" << source->getData(); - // renderer.load(source->getData()); - pSvgRenderer = new QSvgRenderer(source->getData()); - } - // m_pSvg.reset(pSvgRenderer); - // QSvgRenderer renderer = (*pSvgRenderer); - - // QImage copy_buffer(renderer.defaultSize(), QImage::Format_ARGB32); - // copy_buffer.fill(0x00000000); // Transparent black. - // m_pPixmap.reset(new QPixmap(renderer.defaultSize())); - // QPainter painter(©_buffer); - // renderer.render(&painter); QImage copy_buffer(pSvgRenderer->defaultSize(), QImage::Format_ARGB32); copy_buffer.fill(0x00000000); // Transparent black. m_pPixmap.reset(new QPixmap(pSvgRenderer->defaultSize())); @@ -285,11 +263,9 @@ PaintablePointer WPixmapStore::getPaintable(PixmapSource* source, qDebug() << "WPixmapStore Loading pixmap from file" << source->getPath(); if (m_loader) { - qDebug() << "WPixmapStore::getPaintable loader" << source->getPath(); QImage* pImage = m_loader->getImage(source->getPath()); pPaintable = PaintablePointer(new Paintable(pImage, mode)); } else { - qDebug() << "WPixmapStore::getPaintable no loader" << source->getPath(); pPaintable = PaintablePointer(new Paintable(source, mode)); } diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 9de6f3c0c01e..280820f5ad1c 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -59,7 +59,6 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - // QString backPath = context.getPixmapPath(context.selectNode(node, "BackPath")); PixmapSource* backgroundSource = context.getPixmapSource(context.selectNode(node, "BackPath")); if (!backgroundSource->isEmpty()) { setPixmapBackground(backgroundSource, Paintable::DrawModeFromString(mode_str)); @@ -79,13 +78,11 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { QString pixmapPath; PixmapSource* pixmapSource; - // pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Unpressed")); pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Unpressed")); if (!pixmapSource->isEmpty()) { setPixmap(iState, false, pixmapSource); } - // pixmapPath = stateContext->getPixmapPath(stateContext->selectNode(state, "Pressed")); pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Pressed")); if (!pixmapSource->isEmpty()) { setPixmap(iState, true, pixmapSource); diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index 29b0b0ade76a..f4164e2441bf 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -50,13 +50,13 @@ void WSliderComposed::setup(QDomNode node, const SkinContext& context) { unsetPixmaps(); if (context.hasNode(node, "Slider")) { - QString pathSlider = context.getPixmapPath(context.selectNode(node, "Slider")); - setSliderPixmap(pathSlider); + PixmapSource* pSourceSlider = context.getPixmapSource(context.selectNode(node, "Slider")); + setSliderPixmap(pSourceSlider); } - QString pathHandle = context.getPixmapPath(context.selectNode(node, "Handle")); + PixmapSource* pSourceHandle = context.getPixmapSource(context.selectNode(node, "Handle")); bool h = context.selectBool(node, "Horizontal", false); - setHandlePixmap(h, pathHandle); + setHandlePixmap(h, pSourceHandle); if (context.hasNode(node, "EventWhileDrag")) { if (context.selectString(node, "EventWhileDrag").contains("no")) { @@ -87,6 +87,17 @@ void WSliderComposed::setSliderPixmap(const QString& filenameSlider) { } } +void WSliderComposed::setSliderPixmap(PixmapSource* pSourceSlider) { + m_pSlider = WPixmapStore::getPaintable(pSourceSlider, + Paintable::STRETCH); + if (!m_pSlider) { + qDebug() << "WSliderComposed: Error loading slider pixmap:" << pSourceSlider->getPath(); + } else { + // Set size of widget, using size of slider pixmap + setFixedSize(m_pSlider->size()); + } +} + void WSliderComposed::setHandlePixmap(bool bHorizontal, const QString& filenameHandle) { m_bHorizontal = bHorizontal; m_pHandle = WPixmapStore::getPaintable(filenameHandle, @@ -103,6 +114,22 @@ void WSliderComposed::setHandlePixmap(bool bHorizontal, const QString& filenameH } } +void WSliderComposed::setHandlePixmap(bool bHorizontal, PixmapSource* pSourceHandle) { + m_bHorizontal = bHorizontal; + m_pHandle = WPixmapStore::getPaintable(pSourceHandle, + Paintable::STRETCH); + if (!m_pHandle) { + qDebug() << "WSliderComposed: Error loading handle pixmap:" << pSourceHandle->getPath(); + } else { + m_iHandleLength = m_bHorizontal ? + m_pHandle->width() : m_pHandle->height(); + + // Value is unused in WSliderComposed. + onConnectedControlChanged(getControlParameter(), 0); + update(); + } +} + void WSliderComposed::unsetPixmaps() { m_pSlider.clear(); m_pHandle.clear(); diff --git a/src/widget/wslidercomposed.h b/src/widget/wslidercomposed.h index cc17553b5c70..f8e3894a1436 100644 --- a/src/widget/wslidercomposed.h +++ b/src/widget/wslidercomposed.h @@ -45,6 +45,8 @@ class WSliderComposed : public WWidget { void setup(QDomNode node, const SkinContext& context); void setSliderPixmap(const QString& filenameSlider); void setHandlePixmap(bool bHorizontal, const QString& filenameHandle); + void setSliderPixmap(PixmapSource* pSourceSlider); + void setHandlePixmap(bool bHorizontal, PixmapSource* pSourceHandle); inline bool isHorizontal() const { return m_bHorizontal; }; public slots: diff --git a/src/widget/wspinny.cpp b/src/widget/wspinny.cpp index 1e42061f1000..fc834470c97c 100644 --- a/src/widget/wspinny.cpp +++ b/src/widget/wspinny.cpp @@ -123,12 +123,12 @@ void WSpinny::setup(QDomNode node, const SkinContext& context, QString group) { m_group = group; // Set images - m_pBgImage = WImageStore::getImage(context.getPixmapPath(context.selectNode(node, - "PathBackground"))); - m_pFgImage = WImageStore::getImage(context.getPixmapPath(context.selectNode(node, - "PathForeground"))); - m_pGhostImage = WImageStore::getImage(context.getPixmapPath(context.selectNode(node, - "PathGhost"))); + m_pBgImage = WImageStore::getImage(context.getPixmapPath( + context.selectNode(node, "PathBackground"))); + m_pFgImage = WImageStore::getImage(context.getPixmapPath( + context.selectNode(node,"PathForeground"))); + m_pGhostImage = WImageStore::getImage(context.getPixmapPath( + context.selectNode(node,"PathGhost"))); if (m_pBgImage && !m_pBgImage->isNull()) { setFixedSize(m_pBgImage->size()); } diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index 582f5fd72b7e..98ce7e56ab3a 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -68,17 +68,17 @@ void WStatusLight::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, nodeName)) { QString mode = context.selectAttributeString( context.selectElement(node, nodeName), "sizemode", "FIXED"); - setPixmap(i, context.getPixmapPath(context.selectNode(node, nodeName)), + setPixmap(i, context.getPixmapSource(context.selectNode(node, nodeName)), SizeModeFromString(mode)); } else if (i == 0 && context.hasNode(node, "PathBack")) { QString mode = context.selectAttributeString( context.selectElement(node, "PathBack"), "sizemode", "FIXED"); - setPixmap(i, context.getPixmapPath(context.selectNode(node, "PathBack")), + setPixmap(i, context.getPixmapSource(context.selectNode(node, "PathBack")), SizeModeFromString(mode)); } else if (i == 1 && context.hasNode(node, "PathStatusLight")) { QString mode = context.selectAttributeString( context.selectElement(node, "PathStatusLight"), "sizemode", "FIXED"); - setPixmap(i, context.getPixmapPath(context.selectNode(node, "PathStatusLight")), + setPixmap(i, context.getPixmapSource(context.selectNode(node, "PathStatusLight")), SizeModeFromString(mode)); } else { m_pixmaps[i].clear(); @@ -116,6 +116,36 @@ void WStatusLight::setPixmap(int iState, const QString& filename, SizeMode mode) } } +void WStatusLight::setPixmap(int iState, PixmapSource* source, SizeMode mode) { + if (iState < 0 || iState >= m_pixmaps.size()) { + return; + } + + PaintablePointer pPixmap = WPixmapStore::getPaintable(source, + Paintable::STRETCH); + + 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; + } + } else { + qDebug() << "WStatusLight: Error loading pixmap:" << source->getPath() << iState; + m_pixmaps[iState].clear(); + } +} + void WStatusLight::onConnectedControlChanged(double dParameter, double dValue) { // Enums are not currently represented using parameter space so it doesn't // make sense to use the parameter here yet. diff --git a/src/widget/wstatuslight.h b/src/widget/wstatuslight.h index 8faf6b80031e..c06240be93b9 100644 --- a/src/widget/wstatuslight.h +++ b/src/widget/wstatuslight.h @@ -53,6 +53,7 @@ class WStatusLight : public WWidget { private: void setPixmap(int iState, const QString &filename, SizeMode mode); + void setPixmap(int iState, PixmapSource* source, SizeMode mode); void setNoPos(int iNoPos); // Current position diff --git a/src/widget/wwidgetgroup.cpp b/src/widget/wwidgetgroup.cpp index 0335494c4710..fe48dea545c0 100644 --- a/src/widget/wwidgetgroup.cpp +++ b/src/widget/wwidgetgroup.cpp @@ -84,7 +84,7 @@ void WWidgetGroup::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - setPixmapBackground(context.getPixmapPath(context.selectNode(node, "BackPath")), + setPixmapBackground(context.getPixmapSource(context.selectNode(node, "BackPath")), Paintable::DrawModeFromString(mode_str)); } @@ -134,6 +134,14 @@ void WWidgetGroup::setPixmapBackground(const QString &filename, Paintable::DrawM } } +void WWidgetGroup::setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode) { + // Load background pixmap + m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); + if (!m_pPixmapBack) { + qDebug() << "WWidgetGroup: Error loading background pixmap:" << pSource->getPath(); + } +} + void WWidgetGroup::addWidget(QWidget* pChild) { QLayout* pLayout = layout(); if (pLayout && pChild) { diff --git a/src/widget/wwidgetgroup.h b/src/widget/wwidgetgroup.h index 1b20264d1903..6a42eede5d87 100644 --- a/src/widget/wwidgetgroup.h +++ b/src/widget/wwidgetgroup.h @@ -44,6 +44,7 @@ class WWidgetGroup : public QFrame, public WBaseWidget { void setup(QDomNode node, const SkinContext& context); void setPixmapBackground(const QString &filename, Paintable::DrawMode mode); + void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); void addWidget(QWidget* pChild); protected: From cb1a86c2a5b40f63bfe880386efd263aee99224a Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 13:00:43 +0200 Subject: [PATCH 33/90] new dependencies --- build/depends.py | 1 + 1 file changed, 1 insertion(+) diff --git a/build/depends.py b/build/depends.py index f30e95222ce2..b08c4071b023 100644 --- a/build/depends.py +++ b/build/depends.py @@ -880,6 +880,7 @@ def sources(self, build): "skin/tooltips.cpp", "skin/skincontext.cpp", "skin/svgparser.cpp", + "skin/pixmapsource.cpp", "sampleutil.cpp", "trackinfoobject.cpp", From 3641ff29c0d4e759fe795f57991e968849ff1e13 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 13:00:56 +0200 Subject: [PATCH 34/90] cleaning --- src/widget/wslidercomposed.cpp | 27 --------------------------- src/widget/wslidercomposed.h | 2 -- 2 files changed, 29 deletions(-) diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index f4164e2441bf..9657477df0c1 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -76,17 +76,6 @@ void WSliderComposed::setup(QDomNode node, const SkinContext& context) { } } -void WSliderComposed::setSliderPixmap(const QString& filenameSlider) { - m_pSlider = WPixmapStore::getPaintable(filenameSlider, - Paintable::STRETCH); - if (!m_pSlider) { - qDebug() << "WSliderComposed: Error loading slider pixmap:" << filenameSlider; - } else { - // Set size of widget, using size of slider pixmap - setFixedSize(m_pSlider->size()); - } -} - void WSliderComposed::setSliderPixmap(PixmapSource* pSourceSlider) { m_pSlider = WPixmapStore::getPaintable(pSourceSlider, Paintable::STRETCH); @@ -98,22 +87,6 @@ void WSliderComposed::setSliderPixmap(PixmapSource* pSourceSlider) { } } -void WSliderComposed::setHandlePixmap(bool bHorizontal, const QString& filenameHandle) { - m_bHorizontal = bHorizontal; - m_pHandle = WPixmapStore::getPaintable(filenameHandle, - Paintable::STRETCH); - if (!m_pHandle) { - qDebug() << "WSliderComposed: Error loading handle pixmap:" << filenameHandle; - } else { - m_iHandleLength = m_bHorizontal ? - m_pHandle->width() : m_pHandle->height(); - - // Value is unused in WSliderComposed. - onConnectedControlChanged(getControlParameter(), 0); - update(); - } -} - void WSliderComposed::setHandlePixmap(bool bHorizontal, PixmapSource* pSourceHandle) { m_bHorizontal = bHorizontal; m_pHandle = WPixmapStore::getPaintable(pSourceHandle, diff --git a/src/widget/wslidercomposed.h b/src/widget/wslidercomposed.h index f8e3894a1436..65d69cbaf3c9 100644 --- a/src/widget/wslidercomposed.h +++ b/src/widget/wslidercomposed.h @@ -43,8 +43,6 @@ class WSliderComposed : public WWidget { virtual ~WSliderComposed(); void setup(QDomNode node, const SkinContext& context); - void setSliderPixmap(const QString& filenameSlider); - void setHandlePixmap(bool bHorizontal, const QString& filenameHandle); void setSliderPixmap(PixmapSource* pSourceSlider); void setHandlePixmap(bool bHorizontal, PixmapSource* pSourceHandle); inline bool isHorizontal() const { return m_bHorizontal; }; From 004216e72c20ea3c0c090e1db43d39d86c524dab Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 13:02:40 +0200 Subject: [PATCH 35/90] cleaning --- src/widget/wpushbutton.cpp | 43 -------------------------------------- src/widget/wpushbutton.h | 4 ---- 2 files changed, 47 deletions(-) diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 280820f5ad1c..83df2d9bdb61 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -203,33 +203,6 @@ void WPushButton::setStates(int iStates) { m_align.resize(iStates); } - - - -void WPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { - QVector& pixmaps = bPressed ? - m_pressedPixmaps : m_unpressedPixmaps; - - if (iState < 0 || iState >= pixmaps.size()) { - return; - } - - PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, - Paintable::STRETCH); - - if (pPixmap.isNull() || pPixmap->isNull()) { - // Only log if it looks like the user tried to specify a pixmap. - if (!filename.isEmpty()) { - qDebug() << "WPushButton: Error loading pixmap:" << filename; - } - } else { - // Set size of widget equal to pixmap size - setFixedSize(pPixmap->size()); - } - pixmaps.replace(iState, pPixmap); -} - - void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource* source) { QVector& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -253,20 +226,6 @@ void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource* source) { pixmaps.replace(iState, pPixmap); } - - - -void WPushButton::setPixmapBackground(const QString &filename, - Paintable::DrawMode mode) { - // Load background pixmap - m_pPixmapBack = WPixmapStore::getPaintable(filename, mode); - if (!filename.isEmpty() && - (m_pPixmapBack.isNull() || m_pPixmapBack->isNull())) { - // Only log if it looks like the user tried to specify a pixmap. - qDebug() << "WPushButton: Error loading background pixmap:" << filename; - } -} - void WPushButton::setPixmapBackground(PixmapSource* source, Paintable::DrawMode mode) { // Load background pixmap @@ -278,8 +237,6 @@ void WPushButton::setPixmapBackground(PixmapSource* source, } } - - void WPushButton::onConnectedControlChanged(double dParameter, double dValue) { Q_UNUSED(dParameter); // Enums are not currently represented using parameter space so it doesn't diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index 2d22bd46fbeb..b37f037e31ca 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -78,14 +78,10 @@ class WPushButton : public WWidget { private: // Associates a pixmap of a given state of the button with the widget - // template void setPixmap(int iState, bool bPressed, PixmapSource* source); - void setPixmap(int iState, bool bPressed, const QString& filename); - // void setPixmap(int iState, bool bPressed, const QString &filename); // Associates a background pixmap with the widget. This is only needed if // the button pixmaps contains alpha channel values. - void setPixmapBackground(const QString &filename, Paintable::DrawMode mode); void setPixmapBackground(PixmapSource* source, Paintable::DrawMode mode); From 120446a72c35fc3167dd3b97d0f4547255b23784 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 13:04:10 +0200 Subject: [PATCH 36/90] cleaning --- src/widget/wstatuslight.cpp | 30 ------------------------------ src/widget/wstatuslight.h | 1 - 2 files changed, 31 deletions(-) diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index 98ce7e56ab3a..cbf8cde43c9d 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -86,36 +86,6 @@ void WStatusLight::setup(QDomNode node, const SkinContext& context) { } } -void WStatusLight::setPixmap(int iState, const QString& filename, SizeMode mode) { - if (iState < 0 || iState >= m_pixmaps.size()) { - return; - } - - PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, - Paintable::STRETCH); - - 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; - } - } else { - qDebug() << "WStatusLight: Error loading pixmap:" << filename << iState; - m_pixmaps[iState].clear(); - } -} - void WStatusLight::setPixmap(int iState, PixmapSource* source, SizeMode mode) { if (iState < 0 || iState >= m_pixmaps.size()) { return; diff --git a/src/widget/wstatuslight.h b/src/widget/wstatuslight.h index c06240be93b9..a4d5f15a44f9 100644 --- a/src/widget/wstatuslight.h +++ b/src/widget/wstatuslight.h @@ -52,7 +52,6 @@ class WStatusLight : public WWidget { void paintEvent(QPaintEvent *); private: - void setPixmap(int iState, const QString &filename, SizeMode mode); void setPixmap(int iState, PixmapSource* source, SizeMode mode); void setNoPos(int iNoPos); From 7ea5c44d38518a4566711dc36b68f8b2f463efbd Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 9 Sep 2014 13:18:58 +0200 Subject: [PATCH 37/90] cleaning --- src/widget/wvumeter.cpp | 27 --------------------------- src/widget/wvumeter.h | 3 --- src/widget/wwidgetgroup.cpp | 8 -------- src/widget/wwidgetgroup.h | 1 - 4 files changed, 39 deletions(-) diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index b3b21a2c4726..ff71d11c4fa6 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -84,17 +84,6 @@ void WVuMeter::resetPositions() { m_pPixmapVu.clear(); } -void WVuMeter::setPixmapBackground(const QString& filename) { - m_pPixmapBack = WPixmapStore::getPaintable(filename, - Paintable::TILE); - if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { - qDebug() << metaObject()->className() - << "Error loading background pixmap:" << filename; - } else { - setFixedSize(m_pPixmapBack->size()); - } -} - void WVuMeter::setPixmapBackground(PixmapSource* source) { m_pPixmapBack = WPixmapStore::getPaintable(source, Paintable::TILE); @@ -106,22 +95,6 @@ void WVuMeter::setPixmapBackground(PixmapSource* source) { } } -void WVuMeter::setPixmaps(const QString &vuFilename, - bool bHorizontal) { - m_pPixmapVu = WPixmapStore::getPaintable(vuFilename, - Paintable::STRETCH); - if (m_pPixmapVu.isNull() || m_pPixmapVu->isNull()) { - qDebug() << "WVuMeter: Error loading vu pixmap" << vuFilename; - } else { - m_bHorizontal = bHorizontal; - if (m_bHorizontal) { - m_iNoPos = m_pPixmapVu->width(); - } else { - m_iNoPos = m_pPixmapVu->height(); - } - } -} - void WVuMeter::setPixmaps(PixmapSource* vuSource, bool bHorizontal) { m_pPixmapVu = WPixmapStore::getPaintable(vuSource, diff --git a/src/widget/wvumeter.h b/src/widget/wvumeter.h index 1bfa227c68f9..585e425ef500 100644 --- a/src/widget/wvumeter.h +++ b/src/widget/wvumeter.h @@ -36,12 +36,9 @@ class WVuMeter : public WWidget { virtual ~WVuMeter(); void setup(QDomNode node, const SkinContext& context); - void setPixmapBackground(const QString& filename); void setPixmapBackground(PixmapSource* source); void setPixmaps(PixmapSource* vuSource, bool bHorizontal=false); - void setPixmaps(const QString &vuFilename, - bool bHorizontal=false); void onConnectedControlChanged(double dParameter, double dValue); protected slots: diff --git a/src/widget/wwidgetgroup.cpp b/src/widget/wwidgetgroup.cpp index fe48dea545c0..1d9c33eca7bd 100644 --- a/src/widget/wwidgetgroup.cpp +++ b/src/widget/wwidgetgroup.cpp @@ -126,14 +126,6 @@ void WWidgetGroup::setup(QDomNode node, const SkinContext& context) { } } -void WWidgetGroup::setPixmapBackground(const QString &filename, Paintable::DrawMode mode) { - // Load background pixmap - m_pPixmapBack = WPixmapStore::getPaintable(filename, mode); - if (!m_pPixmapBack) { - qDebug() << "WWidgetGroup: Error loading background pixmap:" << filename; - } -} - void WWidgetGroup::setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode) { // Load background pixmap m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); diff --git a/src/widget/wwidgetgroup.h b/src/widget/wwidgetgroup.h index 6a42eede5d87..23e67921787c 100644 --- a/src/widget/wwidgetgroup.h +++ b/src/widget/wwidgetgroup.h @@ -43,7 +43,6 @@ class WWidgetGroup : public QFrame, public WBaseWidget { void setLayoutAlignment(int alignment); void setup(QDomNode node, const SkinContext& context); - void setPixmapBackground(const QString &filename, Paintable::DrawMode mode); void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); void addWidget(QWidget* pChild); From 211fe98426740f911e15eadac3a4d2561c7e69b8 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Fri, 12 Sep 2014 14:11:29 +0200 Subject: [PATCH 38/90] scripts debug --- src/skin/pixmapsource.h | 5 ++--- src/skin/skincontext.cpp | 4 +--- src/skin/svgparser.cpp | 18 +++++++++++++----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/skin/pixmapsource.h b/src/skin/pixmapsource.h index e005b04784a7..c43be1f8054d 100644 --- a/src/skin/pixmapsource.h +++ b/src/skin/pixmapsource.h @@ -1,9 +1,8 @@ #ifndef PIXMAPSOURCE_H #define PIXMAPSOURCE_H -#include - -// A class representing an image source for a pixmap (file path, raw data, svg ) +// A class representing an image source for a pixmap +// A bundle of a file path, raw data or inline svg class PixmapSource { public: PixmapSource(); diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 7199dc8af5dc..fa653463bbd4 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -268,9 +268,7 @@ PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { } } - qDebug() << "getPixmapSource out path" << source->getPath(); - - // return out; + // qDebug() << "getPixmapSource out path" << source->getPath(); return source; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 2cdf3c1c4e09..e9fe9fe590a2 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -217,19 +217,27 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { QDomElement svgElement = svgSkinNode.toElement(); QDomNodeList scriptElements = svgElement.elementsByTagName("script"); int i = 0; - QString expression; + QString expression, scriptPath; QDomNode scriptNode; + QScriptValue result; while (!(scriptNode = scriptElements.item(i)).isNull() && ++i) { - if (scriptNode.toElement().hasAttribute("src")) { - QFile scriptFile(m_pContext->getSkinPath(scriptNode.toElement().attribute("src"))); + if (!(scriptPath = scriptNode.toElement().attribute("src")).isNull()) { + QFile scriptFile(m_pContext->getSkinPath(scriptPath)); scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); - m_scriptEngine.evaluate(in.readAll()); + result = m_scriptEngine.evaluate(in.readAll()); + if (m_scriptEngine.hasUncaughtException()) { + qDebug() << "SVG script exception : " << result.toString() + << "in" << scriptPath; + } } expression = m_pContext->nodeToString(scriptNode); - m_scriptEngine.evaluate(expression); + result = m_scriptEngine.evaluate(expression); + if (m_scriptEngine.hasUncaughtException()) { + qDebug() << "SVG script exception : " << result.toString(); + } } } From 375512ca71e1a33fbc16a4211e2bda0904a6a699 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 29 Sep 2014 22:02:45 +0200 Subject: [PATCH 39/90] removing code dup between svgparser and skincontext --- src/skin/skincontext.cpp | 20 ++++++++++++++++++++ src/skin/skincontext.h | 6 ++++++ src/skin/svgparser.cpp | 29 +++++++++++------------------ src/skin/svgparser.h | 20 +------------------- 4 files changed, 38 insertions(+), 37 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index fa653463bbd4..1ec55d6e05ad 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -272,5 +272,25 @@ PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { return source; } +QScriptValue SkinContext::evaluateScript(QString expression) { + return m_scriptEngine.evaluate(expression); +} + +// bool SkinContext::hasScriptUncaughtException() const { + // return m_scriptEngine.hasUncaughtException(); +// } +// +// QScriptValue SkinContext::getNullScriptValue() const { + // return m_scriptEngine.nullValue(); +// } +// +// QScriptValue SkinContext::getScriptGlobalObject() const { + // return m_scriptEngine.globalObject(); +// } + +QScriptEngine* SkinContext::getScriptEngine() const { + return &m_scriptEngine; +} + diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 64c7e0619011..5a76cc58a242 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -69,6 +69,12 @@ class SkinContext { // template PixmapSource* getPixmapSource(const QDomNode& pixmapNode) const; + QScriptValue evaluateScript(QString expression); + QScriptEngine* getScriptEngine() const; + // bool hasScriptUncaughtException() const; + // QScriptValue getNullScriptValue() const; + // QScriptValue getScriptGlobalObject() const; + private: QString variableNodeToText(const QDomElement& element) const; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index e9fe9fe590a2..43bd66254c32 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -8,15 +8,8 @@ SvgParser::SvgParser() { } -SvgParser::SvgParser(const SkinContext& parent) - : m_variables(parent.variables()) { - QScriptValue context = m_scriptEngine.currentContext()->activationObject(); - for (QHash::const_iterator it = m_variables.begin(); - it != m_variables.end(); ++it) { - context.setProperty(it.key(), it.value()); - } - - m_pContext = &parent; +SvgParser::SvgParser(const SkinContext& parent) { + m_pContext = new SkinContext(parent); } SvgParser::~SvgParser() { @@ -142,7 +135,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomAttr attribute; - QScriptValue global = m_scriptEngine.globalObject(); + QScriptValue global = m_pContext->getScriptEngine()->globalObject(); QScriptValue hookNames; QString hooksPattern; QRegExp hookRx, nameRx; @@ -226,16 +219,16 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { QFile scriptFile(m_pContext->getSkinPath(scriptPath)); scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); - result = m_scriptEngine.evaluate(in.readAll()); - if (m_scriptEngine.hasUncaughtException()) { + result = m_pContext->evaluateScript(in.readAll()); + if (m_pContext->getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString() << "in" << scriptPath; } } expression = m_pContext->nodeToString(scriptNode); - result = m_scriptEngine.evaluate(expression); - if (m_scriptEngine.hasUncaughtException()) { + result = m_pContext->evaluateScript(expression); + if (m_pContext->getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString(); } } @@ -243,14 +236,14 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { } QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { - QScriptValue out = m_scriptEngine.evaluate(expression); - if (m_scriptEngine.hasUncaughtException()) { + QScriptValue out = m_pContext->evaluateScript(expression); + if (m_pContext->getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() << "Empty string returned"; - // return an empty string as remplacement for the in-attribute expression - return m_scriptEngine.nullValue(); + // return an empty string as replacement for the in-attribute expression + return m_pContext->getScriptEngine()->nullValue(); } else { return out; } diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 72ed1558d68e..7bed88bae553 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -19,24 +19,9 @@ class SvgParser { virtual ~SvgParser(); - // Variable lookup and modification methods. - QString variable(const QString& name) const; - const QHash& variables() const { - return m_variables; - } - void setVariable(const QString& name, const QString& value); - - - // Updates the SkinContext with all the children of node. - void updateVariables(const QDomNode& node); - // Updates the SkinContext with 'element', a node. - void updateVariable(const QDomElement& element); - - // Methods for evaluating nodes given the context. QDomDocument getDocument(const QDomNode& node) const; void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; QDomNode parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; @@ -49,10 +34,7 @@ class SvgParser { void parseScriptElements(const QDomNode& svgNode) const; QScriptValue evaluateTemplateExpression(QString expression) const; - mutable QScriptEngine m_scriptEngine; - QHash m_variables; - QString m_skinBasePath; - const SkinContext * m_pContext; + mutable SkinContext * m_pContext; }; From a24904b4162844efaa1311f79a39efe173fcb4d5 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 29 Sep 2014 22:06:07 +0200 Subject: [PATCH 40/90] claening skincontext --- src/skin/skincontext.cpp | 33 ++++++++++----------------------- src/skin/skincontext.h | 7 ------- 2 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 1ec55d6e05ad..8e2984183184 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -218,15 +218,15 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { if (!svgNode.isNull()) { // inline svg pixmapPath = pSvgParser->saveToTempFile( - pSvgParser->parseSvgTree(svgNode) ); + pSvgParser->parseSvgTree(svgNode) ); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = pSvgParser->saveToTempFile( - pSvgParser->parseSvgFile(pixmapName) ); + pixmapPath = pSvgParser->saveToTempFile( + pSvgParser->parseSvgFile(pixmapName) ); } else { pixmapPath = pixmapName; } @@ -238,11 +238,10 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { } -// template PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - PixmapSource* source = new PixmapSource(); - + PixmapSource* source = new PixmapSource(); + const SvgParser* pSvgParser = new SvgParser(*this); if (!pixmapNode.isNull()) { @@ -250,17 +249,17 @@ PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { if (!svgNode.isNull()) { // inline svg const QByteArray rslt = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgTree(svgNode) ); - source->setSVG( rslt ); + pSvgParser->parseSvgTree(svgNode) ); + source->setSVG( rslt ); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { - source->setPath( getSkinPath(pixmapName) ); + source->setPath( getSkinPath(pixmapName) ); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { const QByteArray rslt = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgFile(source->getPath()) ); - source->setSVG( rslt ); + pSvgParser->parseSvgFile(source->getPath()) ); + source->setSVG( rslt ); } else { source->setBitmap(getSkinPath(pixmapName)); } @@ -276,18 +275,6 @@ QScriptValue SkinContext::evaluateScript(QString expression) { return m_scriptEngine.evaluate(expression); } -// bool SkinContext::hasScriptUncaughtException() const { - // return m_scriptEngine.hasUncaughtException(); -// } -// -// QScriptValue SkinContext::getNullScriptValue() const { - // return m_scriptEngine.nullValue(); -// } -// -// QScriptValue SkinContext::getScriptGlobalObject() const { - // return m_scriptEngine.globalObject(); -// } - QScriptEngine* SkinContext::getScriptEngine() const { return &m_scriptEngine; } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 5a76cc58a242..96e5d60838ee 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -63,17 +63,10 @@ class SkinContext { QString defaultValue) const; QString nodeToString(const QDomNode& node) const; QString getPixmapPath(const QDomNode& pixmapNode) const; - // QByteArray getPixmapSource(const QDomNode& pixmapNode) const; - - - // template PixmapSource* getPixmapSource(const QDomNode& pixmapNode) const; QScriptValue evaluateScript(QString expression); QScriptEngine* getScriptEngine() const; - // bool hasScriptUncaughtException() const; - // QScriptValue getNullScriptValue() const; - // QScriptValue getScriptGlobalObject() const; private: QString variableNodeToText(const QDomElement& element) const; From 83486ea57fda574efb71c8a3f3e32b6bb08c4107 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 29 Sep 2014 22:18:28 +0200 Subject: [PATCH 41/90] cleaning --- src/skin/svgparser.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 7bed88bae553..c041c908decb 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -5,8 +5,6 @@ #include #include #include -#include -#include #include "skin/skincontext.h" From 481bd054ae5f7ecbe6089f1947be067d4d1efe2c Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 30 Sep 2014 20:37:49 +0200 Subject: [PATCH 42/90] prettyprint --- src/skin/skincontext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 8e2984183184..09c11749deed 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -249,7 +249,7 @@ PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { if (!svgNode.isNull()) { // inline svg const QByteArray rslt = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgTree(svgNode) ); + pSvgParser->parseSvgTree(svgNode) ); source->setSVG( rslt ); } else { // filename From 18ca574973740fb66452f80f7a9ca93d5b347980 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 30 Sep 2014 21:33:34 +0200 Subject: [PATCH 43/90] Cleaning of PixmapSource --- src/skin/pixmapsource.cpp | 46 ++++++++++++++++++++----------------- src/skin/pixmapsource.h | 16 +++++++++---- src/widget/wpixmapstore.cpp | 2 +- 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp index 73355bb66c60..cd4fd52db501 100644 --- a/src/skin/pixmapsource.cpp +++ b/src/skin/pixmapsource.cpp @@ -9,50 +9,54 @@ PixmapSource::~PixmapSource() { } QByteArray PixmapSource::getData() const { - return data; -} - -QString PixmapSource::getType() const { - return type; + return m_baData; } QString PixmapSource::getPath() const { - return path; + return m_path; } void PixmapSource::setPath( QString newPath ) { - path = newPath; + m_path = newPath; +} + +bool PixmapSource::isEmpty() const { + return m_path.isEmpty() && m_baData.isEmpty() ; +} + +bool PixmapSource::isSVG() const { + return m_eType == SVG; } -bool PixmapSource::isEmpty() { - return path.isEmpty() && data.isEmpty() ; +bool PixmapSource::isBitmap() const { + return m_eType == BITMAP; } void PixmapSource::setSVG( QByteArray content ) { - data.truncate(0); - data += content; - type = "svg"; + m_baData.truncate(0); + m_baData += content; + m_eType = SVG; } void PixmapSource::setSVG( QString filepath ) { - data.truncate(0); - path = filepath; - type = "svg"; + m_baData.truncate(0); + m_path = filepath; + m_eType = SVG; } void PixmapSource::setBitmap( QString filepath ) { - path = filepath; - type = "bitmap"; + m_path = filepath; + m_eType = BITMAP; } QString PixmapSource::getId() const { quint16 checksum; QString out; - if (data.isEmpty()) { - checksum = qChecksum( path.toAscii().constData(), path.length() ); + if (m_baData.isEmpty()) { + checksum = qChecksum( m_path.toAscii().constData(), m_path.length() ); } else { - checksum = qChecksum( data.constData(), data.length() ); + checksum = qChecksum( m_baData.constData(), m_baData.length() ); } - return path + out.setNum(checksum); + return m_path + out.setNum(checksum); } diff --git a/src/skin/pixmapsource.h b/src/skin/pixmapsource.h index c43be1f8054d..842e0a0185ea 100644 --- a/src/skin/pixmapsource.h +++ b/src/skin/pixmapsource.h @@ -8,20 +8,26 @@ class PixmapSource { PixmapSource(); virtual ~PixmapSource(); - bool isEmpty(); + bool isEmpty() const; + bool isSVG() const; + bool isBitmap() const; void setSVG( QByteArray content ); void setSVG( QString filepath ); void setBitmap( QString filepath ); void setPath( QString newPath ); QString getPath() const; - QString getType() const; QByteArray getData() const; QString getId() const; private: - QString path; - QString type; - QByteArray data; + enum Type { + SVG, + BITMAP + }; + + QString m_path; + QByteArray m_baData; + enum Type m_eType; }; #endif /* PIXMAPSOURCE_H */ diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 6379761180d9..a6e08014230a 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -72,7 +72,7 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) /**/ Paintable::Paintable(PixmapSource* source, DrawMode mode) : m_draw_mode(mode) { - if (source->getType() == "svg") { + if (source->isSVG()) { QSvgRenderer* pSvgRenderer = new QSvgRenderer(); if( source->getData().isEmpty() ){ // qWarning() << "Paintable stretch path" << source->getPath(); From 38aa040cbecbd2d029ad27eb30a095c8c426fcf1 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 30 Sep 2014 21:58:51 +0200 Subject: [PATCH 44/90] context deletion --- src/skin/svgparser.cpp | 26 +++++++++++++------------- src/skin/svgparser.h | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 43bd66254c32..8d8e95755b27 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -8,8 +8,8 @@ SvgParser::SvgParser() { } -SvgParser::SvgParser(const SkinContext& parent) { - m_pContext = new SkinContext(parent); +SvgParser::SvgParser(const SkinContext& parent) + : m_context(parent) { } SvgParser::~SvgParser() { @@ -107,7 +107,7 @@ void SvgParser::parseVariableElements(const QDomNode& svgNode) const { // retrieve value varElement = varNode.toElement(); varName = varElement.attribute("name"); - varValue = m_pContext->variable(varName); + varValue = m_context.variable(varName); // replace node by its value varParentNode = varNode.parentNode(); @@ -135,7 +135,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomAttr attribute; - QScriptValue global = m_pContext->getScriptEngine()->globalObject(); + QScriptValue global = m_context.getScriptEngine()->globalObject(); QScriptValue hookNames; QString hooksPattern; QRegExp hookRx, nameRx; @@ -216,19 +216,19 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { while (!(scriptNode = scriptElements.item(i)).isNull() && ++i) { if (!(scriptPath = scriptNode.toElement().attribute("src")).isNull()) { - QFile scriptFile(m_pContext->getSkinPath(scriptPath)); + QFile scriptFile(m_context.getSkinPath(scriptPath)); scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); - result = m_pContext->evaluateScript(in.readAll()); - if (m_pContext->getScriptEngine()->hasUncaughtException()) { + result = m_context.evaluateScript(in.readAll()); + if (m_context.getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString() << "in" << scriptPath; } } - expression = m_pContext->nodeToString(scriptNode); - result = m_pContext->evaluateScript(expression); - if (m_pContext->getScriptEngine()->hasUncaughtException()) { + expression = m_context.nodeToString(scriptNode); + result = m_context.evaluateScript(expression); + if (m_context.getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString(); } } @@ -236,14 +236,14 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { } QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { - QScriptValue out = m_pContext->evaluateScript(expression); - if (m_pContext->getScriptEngine()->hasUncaughtException()) { + QScriptValue out = m_context.evaluateScript(expression); + if (m_context.getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() << "Empty string returned"; // return an empty string as replacement for the in-attribute expression - return m_pContext->getScriptEngine()->nullValue(); + return m_context.getScriptEngine()->nullValue(); } else { return out; } diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index c041c908decb..7b670d879030 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -32,7 +32,7 @@ class SvgParser { void parseScriptElements(const QDomNode& svgNode) const; QScriptValue evaluateTemplateExpression(QString expression) const; - mutable SkinContext * m_pContext; + mutable SkinContext m_context; }; From a108ebc846282126337a65c651928b1fa8566d26 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 30 Sep 2014 22:42:55 +0200 Subject: [PATCH 45/90] PixmapSource passed by value --- src/skin/skincontext.cpp | 14 +++++++------- src/skin/skincontext.h | 2 +- src/widget/wdisplay.cpp | 6 +++--- src/widget/wdisplay.h | 2 +- src/widget/wknobcomposed.cpp | 12 ++++++------ src/widget/wknobcomposed.h | 4 ++-- src/widget/wpixmapstore.cpp | 32 +++++++++++++++----------------- src/widget/wpixmapstore.h | 4 ++-- src/widget/wpushbutton.cpp | 22 +++++++++++----------- src/widget/wpushbutton.h | 4 ++-- src/widget/wslidercomposed.cpp | 20 ++++++++++---------- src/widget/wslidercomposed.h | 4 ++-- src/widget/wstatuslight.cpp | 4 ++-- src/widget/wstatuslight.h | 2 +- src/widget/wvumeter.cpp | 10 +++++----- src/widget/wvumeter.h | 4 ++-- src/widget/wwidgetgroup.cpp | 6 +++--- src/widget/wwidgetgroup.h | 2 +- 18 files changed, 76 insertions(+), 78 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 09c11749deed..7d2b88aa9a4f 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -238,9 +238,9 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { } -PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { +PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - PixmapSource* source = new PixmapSource(); + PixmapSource source; const SvgParser* pSvgParser = new SvgParser(*this); @@ -250,18 +250,18 @@ PixmapSource* SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { // inline svg const QByteArray rslt = pSvgParser->saveToQByteArray( pSvgParser->parseSvgTree(svgNode) ); - source->setSVG( rslt ); + source.setSVG( rslt ); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { - source->setPath( getSkinPath(pixmapName) ); + source.setPath( getSkinPath(pixmapName) ); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { const QByteArray rslt = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgFile(source->getPath()) ); - source->setSVG( rslt ); + pSvgParser->parseSvgFile(source.getPath()) ); + source.setSVG( rslt ); } else { - source->setBitmap(getSkinPath(pixmapName)); + source.setBitmap(getSkinPath(pixmapName)); } } } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 96e5d60838ee..da5775568e09 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -63,7 +63,7 @@ class SkinContext { QString defaultValue) const; QString nodeToString(const QDomNode& node) const; QString getPixmapPath(const QDomNode& pixmapNode) const; - PixmapSource* getPixmapSource(const QDomNode& pixmapNode) const; + PixmapSource getPixmapSource(const QDomNode& pixmapNode) const; QScriptValue evaluateScript(QString expression); QScriptEngine* getScriptEngine() const; diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index ab9b72fec4e0..cd86e4859007 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -86,12 +86,12 @@ void WDisplay::resetPositions() { m_disabledPixmaps.resize(0); } -void WDisplay::setPixmapBackground(PixmapSource* pSource, +void WDisplay::setPixmapBackground(PixmapSource source, Paintable::DrawMode mode) { - m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); + m_pPixmapBack = WPixmapStore::getPaintable(source, mode); if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() - << "Error loading background pixmap:" << pSource->getPath(); + << "Error loading background pixmap:" << source.getPath(); } } diff --git a/src/widget/wdisplay.h b/src/widget/wdisplay.h index a5feb1575814..26433ee85d39 100644 --- a/src/widget/wdisplay.h +++ b/src/widget/wdisplay.h @@ -48,7 +48,7 @@ class WDisplay : public WWidget { void setPixmap(QVector* pPixmaps, int iPos, const QString& filename); - void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); + void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); void setPositions(int iNoPos); diff --git a/src/widget/wknobcomposed.cpp b/src/widget/wknobcomposed.cpp index 74b990308a3a..79337cafe63e 100644 --- a/src/widget/wknobcomposed.cpp +++ b/src/widget/wknobcomposed.cpp @@ -43,20 +43,20 @@ void WKnobComposed::clear() { m_pKnob.clear(); } -void WKnobComposed::setPixmapBackground(PixmapSource* pSource, +void WKnobComposed::setPixmapBackground(PixmapSource source, Paintable::DrawMode mode) { - m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); + m_pPixmapBack = WPixmapStore::getPaintable(source, mode); if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() - << "Error loading background pixmap:" << pSource->getPath(); + << "Error loading background pixmap:" << source.getPath(); } } -void WKnobComposed::setPixmapKnob(PixmapSource* pSource) { - m_pKnob = WPixmapStore::getPaintable(pSource, Paintable::STRETCH); +void WKnobComposed::setPixmapKnob(PixmapSource source) { + m_pKnob = WPixmapStore::getPaintable(source, Paintable::STRETCH); if (m_pKnob.isNull() || m_pKnob->isNull()) { qDebug() << metaObject()->className() - << "Error loading knob pixmap:" << pSource->getPath(); + << "Error loading knob pixmap:" << source.getPath(); } } diff --git a/src/widget/wknobcomposed.h b/src/widget/wknobcomposed.h index e40577ed9ab9..decb5d2bbd61 100644 --- a/src/widget/wknobcomposed.h +++ b/src/widget/wknobcomposed.h @@ -31,8 +31,8 @@ class WKnobComposed : public WWidget { private: void clear(); - void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); - void setPixmapKnob(PixmapSource* pSource); + void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); + void setPixmapKnob(PixmapSource source); double m_dCurrentAngle; PaintablePointer m_pKnob; diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index a6e08014230a..31f24363cc8b 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -70,16 +70,14 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) } /**/ -Paintable::Paintable(PixmapSource* source, DrawMode mode) +Paintable::Paintable(PixmapSource source, DrawMode mode) : m_draw_mode(mode) { - if (source->isSVG()) { + if (source.isSVG()) { QSvgRenderer* pSvgRenderer = new QSvgRenderer(); - if( source->getData().isEmpty() ){ - // qWarning() << "Paintable stretch path" << source->getPath(); - pSvgRenderer->load(source->getPath()); + if( source.getData().isEmpty() ){ + pSvgRenderer->load(source.getPath()); } else { - // qWarning() << "Paintable stretch data" << source->getData(); - pSvgRenderer->load(source->getData()); + pSvgRenderer->load(source.getData()); } if (mode == STRETCH) { @@ -98,10 +96,10 @@ Paintable::Paintable(PixmapSource* source, DrawMode mode) } } else { QPixmap * pPixmap = new QPixmap(); - if (!source->getData().isEmpty()){ - pPixmap->loadFromData(source->getData()); + if (!source.getData().isEmpty()){ + pPixmap->loadFromData(source.getData()); } else { - pPixmap->load(source->getPath()); + pPixmap->load(source.getPath()); } m_pPixmap.reset(pPixmap); } @@ -251,19 +249,19 @@ PaintablePointer WPixmapStore::getPaintable(const QString& fileName, } // static -PaintablePointer WPixmapStore::getPaintable(PixmapSource* source, +PaintablePointer WPixmapStore::getPaintable(PixmapSource source, Paintable::DrawMode mode) { // See if we have a cached value for the pixmap. - PaintablePointer pPaintable = m_paintableCache.value(source->getId(), PaintablePointer()); + PaintablePointer pPaintable = m_paintableCache.value(source.getId(), PaintablePointer()); if (pPaintable) { return pPaintable; } // Otherwise, construct it with the pixmap loader. - qDebug() << "WPixmapStore Loading pixmap from file" << source->getPath(); + qDebug() << "WPixmapStore Loading pixmap from file" << source.getPath(); if (m_loader) { - QImage* pImage = m_loader->getImage(source->getPath()); + QImage* pImage = m_loader->getImage(source.getPath()); pPaintable = PaintablePointer(new Paintable(pImage, mode)); } else { pPaintable = PaintablePointer(new Paintable(source, mode)); @@ -273,14 +271,14 @@ PaintablePointer WPixmapStore::getPaintable(PixmapSource* source, // Only log if it looks like the user tried to specify a // pixmap. Otherwise we probably just have a widget that is calling // getPaintable without checking that the skinner actually wanted one. - if (!source->isEmpty()) { - qDebug() << "WPixmapStore couldn't load:" << source->getPath() + if (!source.isEmpty()) { + qDebug() << "WPixmapStore couldn't load:" << source.getPath() << pPaintable.isNull(); } return PaintablePointer(); } - m_paintableCache[source->getId()] = pPaintable; + m_paintableCache[source.getId()] = pPaintable; return pPaintable; } diff --git a/src/widget/wpixmapstore.h b/src/widget/wpixmapstore.h index 0ec0b8deab63..26f7a1727c92 100644 --- a/src/widget/wpixmapstore.h +++ b/src/widget/wpixmapstore.h @@ -44,7 +44,7 @@ class Paintable { // Takes ownership of QImage. Paintable(QImage* pImage, DrawMode mode); Paintable(const QString& fileName, DrawMode mode); - Paintable(PixmapSource* source, DrawMode mode); + Paintable(PixmapSource source, DrawMode mode); QSize size() const; int width() const; @@ -75,7 +75,7 @@ class WPixmapStore { public: static PaintablePointer getPaintable(const QString& fileName, Paintable::DrawMode mode); - static PaintablePointer getPaintable(PixmapSource* source, + static PaintablePointer getPaintable(PixmapSource source, Paintable::DrawMode mode); static QPixmap* getPixmapNoCache(const QString& fileName); static void setLoader(QSharedPointer ld); diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 65ddbe1800d8..52678c4677e7 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -59,8 +59,8 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - PixmapSource* backgroundSource = context.getPixmapSource(context.selectNode(node, "BackPath")); - if (!backgroundSource->isEmpty()) { + PixmapSource backgroundSource = context.getPixmapSource(context.selectNode(node, "BackPath")); + if (!backgroundSource.isEmpty()) { setPixmapBackground(backgroundSource, Paintable::DrawModeFromString(mode_str)); } } @@ -76,15 +76,15 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { int iState = stateContext->selectInt(state, "Number"); if (iState < m_iNoStates) { QString pixmapPath; - PixmapSource* pixmapSource; + PixmapSource pixmapSource; pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Unpressed")); - if (!pixmapSource->isEmpty()) { + if (!pixmapSource.isEmpty()) { setPixmap(iState, false, pixmapSource); } pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Pressed")); - if (!pixmapSource->isEmpty()) { + if (!pixmapSource.isEmpty()) { setPixmap(iState, true, pixmapSource); } @@ -203,7 +203,7 @@ 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) { QVector& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -216,8 +216,8 @@ void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource* source) { 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(); + if (!source.isEmpty()) { + qDebug() << "WPushButton: Error loading pixmap:" << source.getPath(); } } else { // Set size of widget equal to pixmap size @@ -226,14 +226,14 @@ void WPushButton::setPixmap(int iState, bool bPressed, PixmapSource* source) { pixmaps.replace(iState, pPixmap); } -void WPushButton::setPixmapBackground(PixmapSource* source, +void WPushButton::setPixmapBackground(PixmapSource source, Paintable::DrawMode mode) { // Load background pixmap m_pPixmapBack = WPixmapStore::getPaintable(source, mode); - if (!source->isEmpty() && + if (!source.isEmpty() && (m_pPixmapBack.isNull() || m_pPixmapBack->isNull())) { // Only log if it looks like the user tried to specify a pixmap. - qDebug() << "WPushButton: Error loading background pixmap:" << source->getPath(); + qDebug() << "WPushButton: Error loading background pixmap:" << source.getPath(); } } diff --git a/src/widget/wpushbutton.h b/src/widget/wpushbutton.h index b37f037e31ca..6937bf9d2191 100644 --- a/src/widget/wpushbutton.h +++ b/src/widget/wpushbutton.h @@ -78,11 +78,11 @@ class WPushButton : public WWidget { private: // 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); // Associates a background pixmap with the widget. This is only needed if // the button pixmaps contains alpha channel values. - void setPixmapBackground(PixmapSource* source, + void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); // True, if the button is currently pressed diff --git a/src/widget/wslidercomposed.cpp b/src/widget/wslidercomposed.cpp index 9657477df0c1..53958047595a 100644 --- a/src/widget/wslidercomposed.cpp +++ b/src/widget/wslidercomposed.cpp @@ -50,13 +50,13 @@ void WSliderComposed::setup(QDomNode node, const SkinContext& context) { unsetPixmaps(); if (context.hasNode(node, "Slider")) { - PixmapSource* pSourceSlider = context.getPixmapSource(context.selectNode(node, "Slider")); - setSliderPixmap(pSourceSlider); + PixmapSource sourceSlider = context.getPixmapSource(context.selectNode(node, "Slider")); + setSliderPixmap(sourceSlider); } - PixmapSource* pSourceHandle = context.getPixmapSource(context.selectNode(node, "Handle")); + PixmapSource sourceHandle = context.getPixmapSource(context.selectNode(node, "Handle")); bool h = context.selectBool(node, "Horizontal", false); - setHandlePixmap(h, pSourceHandle); + setHandlePixmap(h, sourceHandle); if (context.hasNode(node, "EventWhileDrag")) { if (context.selectString(node, "EventWhileDrag").contains("no")) { @@ -76,23 +76,23 @@ void WSliderComposed::setup(QDomNode node, const SkinContext& context) { } } -void WSliderComposed::setSliderPixmap(PixmapSource* pSourceSlider) { - m_pSlider = WPixmapStore::getPaintable(pSourceSlider, +void WSliderComposed::setSliderPixmap(PixmapSource sourceSlider) { + m_pSlider = WPixmapStore::getPaintable(sourceSlider, Paintable::STRETCH); if (!m_pSlider) { - qDebug() << "WSliderComposed: Error loading slider pixmap:" << pSourceSlider->getPath(); + qDebug() << "WSliderComposed: Error loading slider pixmap:" << sourceSlider.getPath(); } else { // Set size of widget, using size of slider pixmap setFixedSize(m_pSlider->size()); } } -void WSliderComposed::setHandlePixmap(bool bHorizontal, PixmapSource* pSourceHandle) { +void WSliderComposed::setHandlePixmap(bool bHorizontal, PixmapSource sourceHandle) { m_bHorizontal = bHorizontal; - m_pHandle = WPixmapStore::getPaintable(pSourceHandle, + m_pHandle = WPixmapStore::getPaintable(sourceHandle, Paintable::STRETCH); if (!m_pHandle) { - qDebug() << "WSliderComposed: Error loading handle pixmap:" << pSourceHandle->getPath(); + qDebug() << "WSliderComposed: Error loading handle pixmap:" << sourceHandle.getPath(); } else { m_iHandleLength = m_bHorizontal ? m_pHandle->width() : m_pHandle->height(); diff --git a/src/widget/wslidercomposed.h b/src/widget/wslidercomposed.h index 65d69cbaf3c9..1c2acbe51ab1 100644 --- a/src/widget/wslidercomposed.h +++ b/src/widget/wslidercomposed.h @@ -43,8 +43,8 @@ class WSliderComposed : public WWidget { virtual ~WSliderComposed(); void setup(QDomNode node, const SkinContext& context); - void setSliderPixmap(PixmapSource* pSourceSlider); - void setHandlePixmap(bool bHorizontal, PixmapSource* pSourceHandle); + void setSliderPixmap(PixmapSource sourceSlider); + void setHandlePixmap(bool bHorizontal, PixmapSource sourceHandle); inline bool isHorizontal() const { return m_bHorizontal; }; public slots: diff --git a/src/widget/wstatuslight.cpp b/src/widget/wstatuslight.cpp index cbf8cde43c9d..f33553c9087a 100644 --- a/src/widget/wstatuslight.cpp +++ b/src/widget/wstatuslight.cpp @@ -86,7 +86,7 @@ void WStatusLight::setup(QDomNode node, const SkinContext& context) { } } -void WStatusLight::setPixmap(int iState, PixmapSource* source, SizeMode mode) { +void WStatusLight::setPixmap(int iState, PixmapSource source, SizeMode mode) { if (iState < 0 || iState >= m_pixmaps.size()) { return; } @@ -111,7 +111,7 @@ void WStatusLight::setPixmap(int iState, PixmapSource* source, SizeMode mode) { break; } } else { - qDebug() << "WStatusLight: Error loading pixmap:" << source->getPath() << iState; + qDebug() << "WStatusLight: Error loading pixmap:" << source.getPath() << iState; m_pixmaps[iState].clear(); } } diff --git a/src/widget/wstatuslight.h b/src/widget/wstatuslight.h index a4d5f15a44f9..4c241cd48fc3 100644 --- a/src/widget/wstatuslight.h +++ b/src/widget/wstatuslight.h @@ -52,7 +52,7 @@ class WStatusLight : public WWidget { void paintEvent(QPaintEvent *); private: - void setPixmap(int iState, PixmapSource* source, SizeMode mode); + void setPixmap(int iState, PixmapSource source, SizeMode mode); void setNoPos(int iNoPos); // Current position diff --git a/src/widget/wvumeter.cpp b/src/widget/wvumeter.cpp index ff71d11c4fa6..c4e2afcbbf01 100644 --- a/src/widget/wvumeter.cpp +++ b/src/widget/wvumeter.cpp @@ -84,23 +84,23 @@ void WVuMeter::resetPositions() { m_pPixmapVu.clear(); } -void WVuMeter::setPixmapBackground(PixmapSource* source) { +void WVuMeter::setPixmapBackground(PixmapSource source) { m_pPixmapBack = WPixmapStore::getPaintable(source, Paintable::TILE); if (m_pPixmapBack.isNull() || m_pPixmapBack->isNull()) { qDebug() << metaObject()->className() - << "Error loading background pixmap:" << source->getPath(); + << "Error loading background pixmap:" << source.getPath(); } else { setFixedSize(m_pPixmapBack->size()); } } -void WVuMeter::setPixmaps(PixmapSource* vuSource, +void WVuMeter::setPixmaps(PixmapSource source, bool bHorizontal) { - m_pPixmapVu = WPixmapStore::getPaintable(vuSource, + m_pPixmapVu = WPixmapStore::getPaintable(source, Paintable::STRETCH); if (m_pPixmapVu.isNull() || m_pPixmapVu->isNull()) { - qDebug() << "WVuMeter: Error loading vu pixmap" << vuSource->getPath(); + qDebug() << "WVuMeter: Error loading vu pixmap" << source.getPath(); } else { m_bHorizontal = bHorizontal; if (m_bHorizontal) { diff --git a/src/widget/wvumeter.h b/src/widget/wvumeter.h index 585e425ef500..3ea70647f744 100644 --- a/src/widget/wvumeter.h +++ b/src/widget/wvumeter.h @@ -36,8 +36,8 @@ class WVuMeter : public WWidget { virtual ~WVuMeter(); void setup(QDomNode node, const SkinContext& context); - void setPixmapBackground(PixmapSource* source); - void setPixmaps(PixmapSource* vuSource, + void setPixmapBackground(PixmapSource source); + void setPixmaps(PixmapSource source, bool bHorizontal=false); void onConnectedControlChanged(double dParameter, double dValue); diff --git a/src/widget/wwidgetgroup.cpp b/src/widget/wwidgetgroup.cpp index fe34add5aa7f..3de66f80d9c0 100644 --- a/src/widget/wwidgetgroup.cpp +++ b/src/widget/wwidgetgroup.cpp @@ -132,11 +132,11 @@ void WWidgetGroup::setup(QDomNode node, const SkinContext& context) { } } -void WWidgetGroup::setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode) { +void WWidgetGroup::setPixmapBackground(PixmapSource source, Paintable::DrawMode mode) { // Load background pixmap - m_pPixmapBack = WPixmapStore::getPaintable(pSource, mode); + m_pPixmapBack = WPixmapStore::getPaintable(source, mode); if (!m_pPixmapBack) { - qDebug() << "WWidgetGroup: Error loading background pixmap:" << pSource->getPath(); + qDebug() << "WWidgetGroup: Error loading background pixmap:" << source.getPath(); } } diff --git a/src/widget/wwidgetgroup.h b/src/widget/wwidgetgroup.h index 23e67921787c..815ecfb3f565 100644 --- a/src/widget/wwidgetgroup.h +++ b/src/widget/wwidgetgroup.h @@ -43,7 +43,7 @@ class WWidgetGroup : public QFrame, public WBaseWidget { void setLayoutAlignment(int alignment); void setup(QDomNode node, const SkinContext& context); - void setPixmapBackground(PixmapSource* pSource, Paintable::DrawMode mode); + void setPixmapBackground(PixmapSource source, Paintable::DrawMode mode); void addWidget(QWidget* pChild); protected: From 75e4b953dc64556b51bcf696738559a6b023a2d7 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 30 Sep 2014 22:48:24 +0200 Subject: [PATCH 46/90] cleaning --- src/widget/wpixmapstore.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 31f24363cc8b..9ea8f87e8b4f 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -19,7 +19,6 @@ #include #include -#include // static QHash WPixmapStore::m_paintableCache; From 675fe4b93ac8a547208e4f223496db5085481a2a Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 1 Oct 2014 00:49:44 +0200 Subject: [PATCH 47/90] cleanings --- src/skin/pixmapsource.cpp | 3 +-- src/skin/skincontext.cpp | 4 ++-- src/skin/svgparser.cpp | 10 +++++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp index cd4fd52db501..4d68cd35960b 100644 --- a/src/skin/pixmapsource.cpp +++ b/src/skin/pixmapsource.cpp @@ -51,12 +51,11 @@ void PixmapSource::setBitmap( QString filepath ) { QString PixmapSource::getId() const { quint16 checksum; - QString out; if (m_baData.isEmpty()) { checksum = qChecksum( m_path.toAscii().constData(), m_path.length() ); } else { checksum = qChecksum( m_baData.constData(), m_baData.length() ); } - return m_path + out.setNum(checksum); + return m_path + QString::number(checksum); } diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 7d2b88aa9a4f..b15db46aa5e9 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -275,8 +275,8 @@ QScriptValue SkinContext::evaluateScript(QString expression) { return m_scriptEngine.evaluate(expression); } -QScriptEngine* SkinContext::getScriptEngine() const { - return &m_scriptEngine; +const QScriptEngine SkinContext::getScriptEngine() const { + return m_scriptEngine; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 8d8e95755b27..b91b72542eb3 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -135,7 +135,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomAttr attribute; - QScriptValue global = m_context.getScriptEngine()->globalObject(); + QScriptValue global = m_context.getScriptEngine().globalObject(); QScriptValue hookNames; QString hooksPattern; QRegExp hookRx, nameRx; @@ -220,7 +220,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); result = m_context.evaluateScript(in.readAll()); - if (m_context.getScriptEngine()->hasUncaughtException()) { + if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString() << "in" << scriptPath; } @@ -228,7 +228,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { expression = m_context.nodeToString(scriptNode); result = m_context.evaluateScript(expression); - if (m_context.getScriptEngine()->hasUncaughtException()) { + if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString(); } } @@ -237,13 +237,13 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { QScriptValue out = m_context.evaluateScript(expression); - if (m_context.getScriptEngine()->hasUncaughtException()) { + if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() << "Empty string returned"; // return an empty string as replacement for the in-attribute expression - return m_context.getScriptEngine()->nullValue(); + return m_context.getScriptEngine().nullValue(); } else { return out; } From 1d8b63b0993b609aebaa19576fa1ecc68a727a17 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 1 Oct 2014 20:48:09 +0200 Subject: [PATCH 48/90] svgParser allocated on the stack --- src/skin/skincontext.cpp | 14 +++++++------- src/skin/svgparser.cpp | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index b15db46aa5e9..35caf3b87dc3 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -211,22 +211,22 @@ QString SkinContext::nodeToString(const QDomNode& node) const { QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - const SvgParser* pSvgParser = new SvgParser(*this); + const SvgParser svgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - pixmapPath = pSvgParser->saveToTempFile( - pSvgParser->parseSvgTree(svgNode) ); + pixmapPath = svgParser.saveToTempFile( + svgParser.parseSvgTree(svgNode) ); } else { // filename pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { pixmapName = getSkinPath(pixmapName); if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = pSvgParser->saveToTempFile( - pSvgParser->parseSvgFile(pixmapName) ); + pixmapPath = svgParser.saveToTempFile( + svgParser.parseSvgFile(pixmapName) ); } else { pixmapPath = pixmapName; } @@ -275,8 +275,8 @@ QScriptValue SkinContext::evaluateScript(QString expression) { return m_scriptEngine.evaluate(expression); } -const QScriptEngine SkinContext::getScriptEngine() const { - return m_scriptEngine; +QScriptEngine* SkinContext::getScriptEngine() const { + return &m_scriptEngine; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b91b72542eb3..8d8e95755b27 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -135,7 +135,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomAttr attribute; - QScriptValue global = m_context.getScriptEngine().globalObject(); + QScriptValue global = m_context.getScriptEngine()->globalObject(); QScriptValue hookNames; QString hooksPattern; QRegExp hookRx, nameRx; @@ -220,7 +220,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); result = m_context.evaluateScript(in.readAll()); - if (m_context.getScriptEngine().hasUncaughtException()) { + if (m_context.getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString() << "in" << scriptPath; } @@ -228,7 +228,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { expression = m_context.nodeToString(scriptNode); result = m_context.evaluateScript(expression); - if (m_context.getScriptEngine().hasUncaughtException()) { + if (m_context.getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString(); } } @@ -237,13 +237,13 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { QScriptValue out = m_context.evaluateScript(expression); - if (m_context.getScriptEngine().hasUncaughtException()) { + if (m_context.getScriptEngine()->hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() << "Empty string returned"; // return an empty string as replacement for the in-attribute expression - return m_context.getScriptEngine().nullValue(); + return m_context.getScriptEngine()->nullValue(); } else { return out; } From 88c9cf8768daa5b1884c2c73b8e981e30b3dd551 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 1 Oct 2014 21:40:15 +0200 Subject: [PATCH 49/90] removing filename support for paintables + simplifying PixmapSource --- src/skin/pixmapsource.cpp | 21 ++++++++++----------- src/skin/pixmapsource.h | 3 +-- src/skin/skincontext.cpp | 4 +--- src/widget/wdisplay.cpp | 5 +++-- src/widget/wpixmapstore.cpp | 35 ----------------------------------- src/widget/wpixmapstore.h | 2 -- 6 files changed, 15 insertions(+), 55 deletions(-) diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp index 4d68cd35960b..0215ae3bb8c3 100644 --- a/src/skin/pixmapsource.cpp +++ b/src/skin/pixmapsource.cpp @@ -5,6 +5,10 @@ PixmapSource::PixmapSource() { } +PixmapSource::PixmapSource( QString filepath ) { + setPath(filepath); +} + PixmapSource::~PixmapSource() { } @@ -17,7 +21,13 @@ QString PixmapSource::getPath() const { } void PixmapSource::setPath( QString newPath ) { + m_baData.truncate(0); m_path = newPath; + if (m_path.endsWith(".svg", Qt::CaseInsensitive)) { + m_eType = SVG; + } else { + m_eType = BITMAP; + } } bool PixmapSource::isEmpty() const { @@ -38,17 +48,6 @@ void PixmapSource::setSVG( QByteArray content ) { m_eType = SVG; } -void PixmapSource::setSVG( QString filepath ) { - m_baData.truncate(0); - m_path = filepath; - m_eType = SVG; -} - -void PixmapSource::setBitmap( QString filepath ) { - m_path = filepath; - m_eType = BITMAP; -} - QString PixmapSource::getId() const { quint16 checksum; if (m_baData.isEmpty()) { diff --git a/src/skin/pixmapsource.h b/src/skin/pixmapsource.h index 842e0a0185ea..5dff39eef8a5 100644 --- a/src/skin/pixmapsource.h +++ b/src/skin/pixmapsource.h @@ -6,14 +6,13 @@ class PixmapSource { public: PixmapSource(); + PixmapSource( QString filepath ); virtual ~PixmapSource(); bool isEmpty() const; bool isSVG() const; bool isBitmap() const; void setSVG( QByteArray content ); - void setSVG( QString filepath ); - void setBitmap( QString filepath ); void setPath( QString newPath ); QString getPath() const; QByteArray getData() const; diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 35caf3b87dc3..82a9ca53402d 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -256,12 +256,10 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { source.setPath( getSkinPath(pixmapName) ); - if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { + if (source.isSVG()) { const QByteArray rslt = pSvgParser->saveToQByteArray( pSvgParser->parseSvgFile(source.getPath()) ); source.setSVG( rslt ); - } else { - source.setBitmap(getSkinPath(pixmapName)); } } } diff --git a/src/widget/wdisplay.cpp b/src/widget/wdisplay.cpp index cd86e4859007..21e6f9723966 100644 --- a/src/widget/wdisplay.cpp +++ b/src/widget/wdisplay.cpp @@ -100,8 +100,9 @@ void WDisplay::setPixmap(QVector* pPixmaps, int iPos, if (iPos < 0 || iPos >= pPixmaps->size()) { return; } - - PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, + + PixmapSource source(filename); + PaintablePointer pPixmap = WPixmapStore::getPaintable( source, Paintable::TILE); if (pPixmap.isNull() || pPixmap->isNull()) { diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 9ea8f87e8b4f..5cbe0084e5db 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -68,7 +68,6 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) } } -/**/ Paintable::Paintable(PixmapSource source, DrawMode mode) : m_draw_mode(mode) { if (source.isSVG()) { @@ -103,7 +102,6 @@ Paintable::Paintable(PixmapSource source, DrawMode mode) m_pPixmap.reset(pPixmap); } } -/**/ bool Paintable::isNull() const { @@ -214,39 +212,6 @@ void Paintable::resizeSvgPixmap(const QRectF& targetRect, } } -// static -PaintablePointer WPixmapStore::getPaintable(const QString& fileName, - Paintable::DrawMode mode) { - // See if we have a cached value for the pixmap. - PaintablePointer pPaintable = m_paintableCache.value(fileName, PaintablePointer()); - if (pPaintable) { - return pPaintable; - } - - // Otherwise, construct it with the pixmap loader. - //qDebug() << "WPixmapStore Loading pixmap from file" << fileName; - - if (m_loader) { - QImage* pImage = m_loader->getImage(fileName); - pPaintable = PaintablePointer(new Paintable(pImage, mode)); - } else { - pPaintable = PaintablePointer(new Paintable(fileName, mode)); - } - - if (pPaintable.isNull() || pPaintable->isNull()) { - // Only log if it looks like the user tried to specify a - // pixmap. Otherwise we probably just have a widget that is calling - // getPaintable without checking that the skinner actually wanted one. - if (!fileName.isEmpty()) { - qDebug() << "WPixmapStore couldn't load:" << fileName - << pPaintable.isNull(); - } - return PaintablePointer(); - } - m_paintableCache[fileName] = pPaintable; - return pPaintable; -} - // static PaintablePointer WPixmapStore::getPaintable(PixmapSource source, Paintable::DrawMode mode) { diff --git a/src/widget/wpixmapstore.h b/src/widget/wpixmapstore.h index 26f7a1727c92..d4452842732d 100644 --- a/src/widget/wpixmapstore.h +++ b/src/widget/wpixmapstore.h @@ -73,8 +73,6 @@ typedef QWeakPointer WeakPaintablePointer; class WPixmapStore { public: - static PaintablePointer getPaintable(const QString& fileName, - Paintable::DrawMode mode); static PaintablePointer getPaintable(PixmapSource source, Paintable::DrawMode mode); static QPixmap* getPixmapNoCache(const QString& fileName); From 13ebd33df74d7c69440d02df1511897cb589a854 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 1 Oct 2014 22:07:31 +0200 Subject: [PATCH 50/90] removing leaked context from wpushbutton --- src/widget/wpushbutton.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index 52678c4677e7..2d927a41cf12 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -70,26 +70,26 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { while (!state.isNull()) { if (state.isElement() && state.nodeName() == "State") { // support for variables in State elements - SkinContext* stateContext = new SkinContext(context); - stateContext->updateVariables(state); + SkinContext stateContext(context); + stateContext.updateVariables(state); - int iState = stateContext->selectInt(state, "Number"); + int iState = stateContext.selectInt(state, "Number"); if (iState < m_iNoStates) { QString pixmapPath; PixmapSource pixmapSource; - pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Unpressed")); + pixmapSource = stateContext.getPixmapSource(stateContext.selectNode(state, "Unpressed")); if (!pixmapSource.isEmpty()) { setPixmap(iState, false, pixmapSource); } - pixmapSource = stateContext->getPixmapSource(stateContext->selectNode(state, "Pressed")); + pixmapSource = stateContext.getPixmapSource(stateContext.selectNode(state, "Pressed")); if (!pixmapSource.isEmpty()) { setPixmap(iState, true, pixmapSource); } - m_text.replace(iState, stateContext->selectString(state, "Text")); - QString alignment = stateContext->selectString(state, "Alignment"); + m_text.replace(iState, stateContext.selectString(state, "Text")); + QString alignment = stateContext.selectString(state, "Alignment"); if (alignment == "left") { m_align.replace(iState, Qt::AlignLeft); } else if (alignment == "right") { From 6c81877ea06afb53d2a299800bd5b05835a81db1 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Wed, 1 Oct 2014 22:15:05 +0200 Subject: [PATCH 51/90] remove a few c-ism --- src/skin/svgparser.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 8d8e95755b27..7de1900a73b1 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -135,15 +135,13 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomAttr attribute; - QScriptValue global = m_context.getScriptEngine()->globalObject(); - QScriptValue hookNames; - QString hooksPattern; QRegExp hookRx, nameRx; - hookNames = global.property("hookNames").call(global); + QScriptValue global = m_context.getScriptEngine()->globalObject(); + QScriptValue hookNames = global.property("hookNames").call(global); if (hookNames.toString().length()) { - hooksPattern = hookNames.property("toPattern") + QString hooksPattern = hookNames.property("toPattern") .call(hookNames).toString(); // hook_name( arg1 [, arg2]... ) From f6d59e584773acf6733b4873e16ddd1df858a15f Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 2 Oct 2014 00:38:54 +0200 Subject: [PATCH 52/90] getScriptEngine a const reference --- src/skin/skincontext.cpp | 4 ++-- src/skin/skincontext.h | 2 +- src/skin/svgparser.cpp | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 82a9ca53402d..546cd6562ddf 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -273,8 +273,8 @@ QScriptValue SkinContext::evaluateScript(QString expression) { return m_scriptEngine.evaluate(expression); } -QScriptEngine* SkinContext::getScriptEngine() const { - return &m_scriptEngine; +const QScriptEngine& SkinContext::getScriptEngine() const { + return m_scriptEngine; } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index da5775568e09..85a953a51d8e 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -66,7 +66,7 @@ class SkinContext { PixmapSource getPixmapSource(const QDomNode& pixmapNode) const; QScriptValue evaluateScript(QString expression); - QScriptEngine* getScriptEngine() const; + const QScriptEngine& getScriptEngine() const; private: QString variableNodeToText(const QDomElement& element) const; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 7de1900a73b1..c9ca0e1945cb 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -137,7 +137,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QRegExp hookRx, nameRx; - QScriptValue global = m_context.getScriptEngine()->globalObject(); + QScriptValue global = m_context.getScriptEngine().globalObject(); QScriptValue hookNames = global.property("hookNames").call(global); if (hookNames.toString().length()) { @@ -218,7 +218,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); result = m_context.evaluateScript(in.readAll()); - if (m_context.getScriptEngine()->hasUncaughtException()) { + if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString() << "in" << scriptPath; } @@ -226,7 +226,7 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { expression = m_context.nodeToString(scriptNode); result = m_context.evaluateScript(expression); - if (m_context.getScriptEngine()->hasUncaughtException()) { + if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString(); } } @@ -235,13 +235,14 @@ void SvgParser::parseScriptElements(const QDomNode& svgSkinNode) const { QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { QScriptValue out = m_context.evaluateScript(expression); - if (m_context.getScriptEngine()->hasUncaughtException()) { + if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() << "Empty string returned"; // return an empty string as replacement for the in-attribute expression - return m_context.getScriptEngine()->nullValue(); + QScriptValue nullValue; + return nullValue; } else { return out; } From f36b8a4f0fde80393164264ff7d923b3bfcfbee8 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 4 Oct 2014 02:01:43 +0200 Subject: [PATCH 53/90] refacto : all parses in scanTree --- src/skin/svgparser.cpp | 185 +++++++++++++++++++---------------------- src/skin/svgparser.h | 4 +- 2 files changed, 87 insertions(+), 102 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index c9ca0e1945cb..8c234c22670e 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -16,19 +16,6 @@ SvgParser::~SvgParser() { } // look for the document of a node -QDomDocument SvgParser::getDocument(const QDomNode& node) const { - - QDomDocument document; - QDomNode parentNode = node; - while (!parentNode.isNull()) { - if (parentNode.isDocument()) { - document = parentNode.toDocument(); - } - parentNode = parentNode.parentNode(); - } - - return document; -} QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { QFile* file = new QFile(svgFileName); @@ -49,82 +36,76 @@ QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); + m_document = getDocument(svgNode); - parseVariableElements(svgNode); - parseScriptElements(svgNode); - scanTree(svgNode, &SvgParser::parseAttributes); + scanTree(svgNode, &SvgParser::parseElement); - // return saveToTempFile(svgNode); return svgNode; } -QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { - - // Save the new svg in a temp file to use it with setPixmap - QTemporaryFile svgFile; - svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); +void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { - // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove(false); + (this->*callback)(node); + QDomNodeList children = node.childNodes(); + QDomNode child; + uint i; - QString svgTempFileName; - if (svgFile.open()) { - // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; - QTextStream out(&svgFile); - svgNode.save(out, 2); - svgFile.close(); - svgTempFileName = svgFile.fileName(); - } else { - qDebug() << "Unable to open temp file for inline svg \n"; + for (i=0; i= 0 && (varNode = variablesElements.item(i)).isNull() == false) { + if (element.tagName() == "Variable"){ // retrieve value - varElement = varNode.toElement(); - varName = varElement.attribute("name"); - varValue = m_context.variable(varName); + QString varName = element.attribute("name"); + QString varValue = m_context.variable(varName); // replace node by its value - varParentNode = varNode.parentNode(); - varValueNode = document.createTextNode(varValue); - oldChild = varParentNode.replaceChild(varValueNode, varNode); + QDomNode varParentNode = node.parentNode(); + QDomNode varValueNode = document.createTextNode(varValue); + QDomNode oldChild = varParentNode.replaceChild(varValueNode, node); if (oldChild.isNull()) { // replaceChild has a really weird behaviour so I add this check qDebug() << "SVG : unable to replace dom node changed. \n"; } - --i; + } else if (element.tagName() == "script"){ + + QString scriptPath = node.toElement().attribute("src"); + if (!scriptPath.isNull()) { + QFile scriptFile(m_context.getSkinPath(scriptPath)); + scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); + QTextStream in(&scriptFile); + QScriptValue result = m_context.evaluateScript(in.readAll()); + if (m_context.getScriptEngine().hasUncaughtException()) { + qDebug() << "SVG script exception : " << result.toString() + << "in" << scriptPath; + } + } + + QString expression = m_context.nodeToString(node); + QScriptValue result = m_context.evaluateScript(expression); + if (m_context.getScriptEngine().hasUncaughtException()) { + qDebug() << "SVG script exception : " << result.toString(); + } } + } - void SvgParser::parseAttributes(const QDomNode& node) const { + QDomNamedNodeMap attributes = node.attributes(); QDomElement element = node.toElement(); uint i; @@ -187,50 +168,35 @@ void SvgParser::parseAttributes(const QDomNode& node) const { } -void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { + +QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { - (this->*callback)(node); - QDomNodeList children = node.childNodes(); - QDomNode child; - uint i; + // Save the new svg in a temp file to use it with setPixmap + QTemporaryFile svgFile; + svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); - for (i=0; i Date: Sat, 4 Oct 2014 02:29:19 +0200 Subject: [PATCH 54/90] dbg --- src/skin/svgparser.cpp | 4 ++-- src/skin/svgparser.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 8c234c22670e..8bf6d9c5bfd3 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -36,7 +36,6 @@ QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); - m_document = getDocument(svgNode); scanTree(svgNode, &SvgParser::parseElement); @@ -61,6 +60,7 @@ void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const // replaces Variables nodes in an svg dom tree void SvgParser::parseElement(const QDomNode& node) const { + QDomDocument document = getDocument(node); QDomElement element = node.toElement(); parseAttributes(node); @@ -217,7 +217,7 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { /** * Retrieves the document of a node. * This method is required to replace a node by another : the document element - * is th only one able to do createTextNode). + * is th only one able to do createTextNode ). */ QDomDocument SvgParser::getDocument(const QDomNode& node) const { diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 110d7a71c12f..d9abd9bc61d6 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -20,6 +20,7 @@ class SvgParser { QDomDocument getDocument(const QDomNode& node) const; void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; + // QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; QDomNode parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; From b41f4f97c0cdb5a553d54fefcd5ca551603b16d9 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 4 Oct 2014 15:52:12 +0200 Subject: [PATCH 55/90] svg parser scripts in extension + removing cisms + cleaning --- script/console/__init__.js | 12 +++++++ script/svg/__init__.js | 59 ++++++++++++++++++++++++++++++++ src/skin/skincontext.cpp | 8 +++++ src/skin/skincontext.h | 1 + src/skin/svgparser.cpp | 69 +++++++++++++------------------------- src/skin/svgparser.h | 1 - 6 files changed, 104 insertions(+), 46 deletions(-) create mode 100644 script/console/__init__.js create mode 100644 script/svg/__init__.js diff --git a/script/console/__init__.js b/script/console/__init__.js new file mode 100644 index 000000000000..a1d833b9a938 --- /dev/null +++ b/script/console/__init__.js @@ -0,0 +1,12 @@ +__setupPackage__(__extension__); + +console = { + log : function(){ + var out = [], + i = 0; + for( ; i|:\\' + (delimiter || '') + '-]', + 'g' + ), + '\\$&' + ); +} + +svg.hookNames = function(){ + var hookNames = ['variable'], + that = this; + for( var i in this.templateHooks ) + hookNames.push(i); + + hookNames.toPattern = function(){ + for( var i in this ) + this[i] = that.regexpQuote(this[i]); + return this.join('|'); + } + + return hookNames; +} + +global = this; +svg.templateHooks.variable = variable = function( varName ){ + // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + // console.log(global[varName]); + if( varName in global ){ + return global[varName]; + } + return ''; +} + +svg.templateHooks.prop = prop = function( propName, varName ){ + var out = ''; + + if( (varName in global) ){ + var value = global[varName]; + + if( isNumber(value) ){ + out = propName + ':' + value + ';'; + } else if( value.length ) { + out = propName + ':' + value + ';'; + } + + } else { + // print( 'Unable to find ' + varName + ' for prop hook.' ); + } + + // print( varName + ' => ' out + ' | ' + (varName in global) ); + return out; +} + diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 546cd6562ddf..71461658dc18 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -273,6 +273,14 @@ QScriptValue SkinContext::evaluateScript(QString expression) { return m_scriptEngine.evaluate(expression); } +QScriptValue SkinContext::importScriptExtension(QString extensionName) { + QScriptValue out = m_scriptEngine.importExtension(extensionName); + if (m_scriptEngine.hasUncaughtException()) { + qDebug() << out.toString(); + } + return out; +} + const QScriptEngine& SkinContext::getScriptEngine() const { return m_scriptEngine; } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 85a953a51d8e..85cdd55b6de1 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -66,6 +66,7 @@ class SkinContext { PixmapSource getPixmapSource(const QDomNode& pixmapNode) const; QScriptValue evaluateScript(QString expression); + QScriptValue importScriptExtension(QString extensionName); const QScriptEngine& getScriptEngine() const; private: diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 8bf6d9c5bfd3..e05fee3090ad 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -10,13 +10,13 @@ SvgParser::SvgParser() { SvgParser::SvgParser(const SkinContext& parent) : m_context(parent) { + m_context.importScriptExtension("console"); + m_context.importScriptExtension("svg"); } SvgParser::~SvgParser() { } -// look for the document of a node - QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { QFile* file = new QFile(svgFileName); QDomNode out; @@ -26,19 +26,14 @@ QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { QDomNode svgNode = document.elementsByTagName("svg").item(0); out = parseSvgTree(svgNode); file->close(); - return out; } - return out; } QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { - // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); - scanTree(svgNode, &SvgParser::parseElement); - return svgNode; } @@ -46,11 +41,9 @@ void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const (this->*callback)(node); QDomNodeList children = node.childNodes(); - QDomNode child; - uint i; - for (i=0; i Date: Sat, 4 Oct 2014 15:53:18 +0200 Subject: [PATCH 56/90] removing tabs --- script/svg/__init__.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/script/svg/__init__.js b/script/svg/__init__.js index c7a0c39334b7..16811a2b0678 100644 --- a/script/svg/__init__.js +++ b/script/svg/__init__.js @@ -29,8 +29,8 @@ svg.hookNames = function(){ global = this; svg.templateHooks.variable = variable = function( varName ){ - // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); - // console.log(global[varName]); + // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + // console.log(global[varName]); if( varName in global ){ return global[varName]; } From 33612cdcc1ab5f3e73e7647a8e62ecbab1495432 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 5 Oct 2014 17:39:48 +0200 Subject: [PATCH 57/90] moving hook pattern definition to script extension --- script/svg/__init__.js | 23 ++++++++++++----------- src/skin/svgparser.cpp | 31 ++++++++++++++++--------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/script/svg/__init__.js b/script/svg/__init__.js index 16811a2b0678..6c244c902550 100644 --- a/script/svg/__init__.js +++ b/script/svg/__init__.js @@ -12,23 +12,24 @@ svg.regexpQuote = function (str, delimiter) { ); } -svg.hookNames = function(){ - var hookNames = ['variable'], +svg.getHooksPattern = function(){ + var hookNames = [], that = this; for( var i in this.templateHooks ) hookNames.push(i); - hookNames.toPattern = function(){ - for( var i in this ) - this[i] = that.regexpQuote(this[i]); - return this.join('|'); + // hook_name( arg1 [, arg2]... ) + if( hookNames.length ){ + var pattern = "("+hookNames.join('|')+")\\(([^\\(\\)]+)\\)\\s*;?"; + + // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); + // console.log(pattern); + return pattern; } - - return hookNames; } global = this; -svg.templateHooks.variable = variable = function( varName ){ +svg.templateHooks.variable = function( varName ){ // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); // console.log(global[varName]); if( varName in global ){ @@ -37,7 +38,7 @@ svg.templateHooks.variable = variable = function( varName ){ return ''; } -svg.templateHooks.prop = prop = function( propName, varName ){ +svg.templateHooks.prop = function( propName, varName ){ var out = ''; if( (varName in global) ){ @@ -50,7 +51,7 @@ svg.templateHooks.prop = prop = function( propName, varName ){ } } else { - // print( 'Unable to find ' + varName + ' for prop hook.' ); + print( 'Unable to find ' + varName + ' for prop hook.' ); } // print( varName + ' => ' out + ' | ' + (varName in global) ); diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index e05fee3090ad..2efcc9023a74 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -84,14 +84,18 @@ void SvgParser::parseElement(const QDomNode& node) const { QScriptValue result = m_context.evaluateScript(in.readAll()); if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << result.toString() - << "in" << scriptPath; + << "in" << scriptPath + << "line" << m_context.getScriptEngine() + .uncaughtExceptionLineNumber(); } } // Evaluates the content of the script element QString expression = m_context.nodeToString(node); QScriptValue result = m_context.evaluateScript(expression); if (m_context.getScriptEngine().hasUncaughtException()) { - qDebug() << "SVG script exception : " << result.toString(); + qDebug() << "SVG script exception : " << result.toString() << "\n" + << "line" << m_context.getScriptEngine() + .uncaughtExceptionLineNumber(); } } @@ -102,19 +106,14 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomNamedNodeMap attributes = node.attributes(); QDomElement element = node.toElement(); - QScriptValue global = m_context.getScriptEngine().globalObject(); - QScriptValue hookNames = global.property("svg").property("hookNames") - .call(global.property("svg")); // Preparing the pattern of hooks + QScriptValue global = m_context.getScriptEngine().globalObject(); + QScriptValue hooksPattern = global.property("svg") + .property("getHooksPattern").call(global.property("svg")); QRegExp hookRx; - if (hookNames.toString().length()) { - QString hooksPattern = hookNames.property("toPattern") - .call(hookNames).toString(); - // hook_name( arg1 [, arg2]... ) - hookRx.setPattern("("+hooksPattern+")\\(([^\\(\\)]+)\\)\\s*;?"); - // qDebug() << "hooksPattern : " << hooksPattern << "\n"; - } + if (!hooksPattern.isNull()) + hookRx.setPattern(hooksPattern.toString()); // expr-attribute_name="var_name"; QRegExp nameRx("^expr-([^=\\s]+)$"); @@ -185,7 +184,9 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { if (m_context.getScriptEngine().hasUncaughtException()) { qDebug() << "SVG script exception : " << out.toString() - << "Empty string returned"; + << "Empty string returned\n" + << "In file ... line " << m_context.getScriptEngine() + .uncaughtExceptionLineNumber(); // return an empty string as replacement for the in-attribute expression QScriptValue nullValue; @@ -197,8 +198,8 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { /** * Retrieves the document of a node. - * This method is required to replace a node by another : the document element - * is th only one able to do createTextNode. + * This method is required to replace a variable element by its value as the + * document element is the only one able to do createTextNode. */ QDomDocument SvgParser::getDocument(const QDomNode& node) const { QDomNode parentNode = node; From ec05305be1ce3b210a471dafc146886d04ada6c2 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 5 Oct 2014 18:02:58 +0200 Subject: [PATCH 58/90] cleaning --- script/svg/__init__.js | 6 +----- src/skin/svgparser.cpp | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/script/svg/__init__.js b/script/svg/__init__.js index 6c244c902550..775265dd1eba 100644 --- a/script/svg/__init__.js +++ b/script/svg/__init__.js @@ -21,9 +21,6 @@ svg.getHooksPattern = function(){ // hook_name( arg1 [, arg2]... ) if( hookNames.length ){ var pattern = "("+hookNames.join('|')+")\\(([^\\(\\)]+)\\)\\s*;?"; - - // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); - // console.log(pattern); return pattern; } } @@ -51,10 +48,9 @@ svg.templateHooks.prop = function( propName, varName ){ } } else { - print( 'Unable to find ' + varName + ' for prop hook.' ); + console.log( 'Unable to find ' + varName + ' for prop hook.' ); } - // print( varName + ' => ' out + ' | ' + (varName in global) ); return out; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 2efcc9023a74..b00905667f84 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -106,8 +106,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QDomNamedNodeMap attributes = node.attributes(); QDomElement element = node.toElement(); - - // Preparing the pattern of hooks + // Retrieving hooks pattern from script extension QScriptValue global = m_context.getScriptEngine().globalObject(); QScriptValue hooksPattern = global.property("svg") .property("getHooksPattern").call(global.property("svg")); From 437fe8e81845105df1b57492160960c4a1952cec Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 5 Oct 2014 18:18:23 +0200 Subject: [PATCH 59/90] removing useless method --- src/skin/svgparser.cpp | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b00905667f84..ede7775d1df8 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -53,7 +53,6 @@ void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const // replaces Variables nodes in an svg dom tree void SvgParser::parseElement(const QDomNode& node) const { - QDomDocument document = getDocument(node); QDomElement element = node.toElement(); parseAttributes(node); @@ -66,7 +65,7 @@ void SvgParser::parseElement(const QDomNode& node) const { // replace node by its value QDomNode varParentNode = node.parentNode(); - QDomNode varValueNode = document.createTextNode(varValue); + QDomNode varValueNode = node.ownerDocument().createTextNode(varValue); QDomNode oldChild = varParentNode.replaceChild(varValueNode, node); if (oldChild.isNull()) { @@ -194,20 +193,3 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { return out; } } - -/** - * Retrieves the document of a node. - * This method is required to replace a variable element by its value as the - * document element is the only one able to do createTextNode. - */ -QDomDocument SvgParser::getDocument(const QDomNode& node) const { - QDomNode parentNode = node; - QDomDocument document; - while (!parentNode.isNull()) { - if (parentNode.isDocument()) { - document = parentNode.toDocument(); - } - parentNode = parentNode.parentNode(); - } - return document; -} From d097552f9797e3c1113fb7cedea251e9553c1a10 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 6 Oct 2014 00:22:23 +0200 Subject: [PATCH 60/90] investigating error logging --- build/depends.py | 2 +- script/svg/__init__.js | 1 + src/skin/skincontext.cpp | 33 ++++++++++++++++----- src/skin/skincontext.h | 4 +++ src/skin/svgparser.cpp | 62 ++++++++++++++++++++++------------------ src/skin/svgparser.h | 9 ++++-- 6 files changed, 72 insertions(+), 39 deletions(-) diff --git a/build/depends.py b/build/depends.py index 7b7efe0121a0..d69c64f655c9 100644 --- a/build/depends.py +++ b/build/depends.py @@ -194,7 +194,7 @@ def enabled_modules(build): qt_modules = [ 'QtCore', 'QtGui', 'QtOpenGL', 'QtXml', 'QtSvg', 'QtSql', 'QtScript', 'QtXmlPatterns', 'QtNetwork', - 'QtTest' + 'QtTest', 'QtScriptTools' ] if qt5: qt_modules.extend(['QtWidgets', 'QtConcurrent']) diff --git a/script/svg/__init__.js b/script/svg/__init__.js index 775265dd1eba..f96744baab45 100644 --- a/script/svg/__init__.js +++ b/script/svg/__init__.js @@ -27,6 +27,7 @@ svg.getHooksPattern = function(){ global = this; svg.templateHooks.variable = function( varName ){ + // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); // console.log(global[varName]); if( varName in global ){ diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 71461658dc18..f0e73dd4caea 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -1,9 +1,11 @@ #include #include #include +#include #include "skin/skincontext.h" #include "skin/svgparser.h" +#include "util/cmdlineargs.h" SkinContext::SkinContext() { } @@ -16,6 +18,12 @@ SkinContext::SkinContext(const SkinContext& parent) it != m_variables.end(); ++it) { context.setProperty(it.key(), it.value()); } + + if (CmdlineArgs::Instance().getDeveloper()) { + // Enable script debugger + m_debugger.attachTo(&m_scriptEngine); + m_debugger.action(QScriptEngineDebugger::InterruptAction); + } } SkinContext::~SkinContext() { @@ -211,7 +219,8 @@ QString SkinContext::nodeToString(const QDomNode& node) const { QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - const SvgParser svgParser(*this); + // const SvgParser svgParser(*this); + SvgParser svgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); @@ -242,14 +251,15 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; PixmapSource source; - const SvgParser* pSvgParser = new SvgParser(*this); + // const SvgParser svgParser(*this); + SvgParser svgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); if (!svgNode.isNull()) { // inline svg - const QByteArray rslt = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgTree(svgNode) ); + const QByteArray rslt = svgParser.saveToQByteArray( + svgParser.parseSvgTree(svgNode) ); source.setSVG( rslt ); } else { // filename @@ -257,8 +267,8 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { if (!pixmapName.isEmpty()) { source.setPath( getSkinPath(pixmapName) ); if (source.isSVG()) { - const QByteArray rslt = pSvgParser->saveToQByteArray( - pSvgParser->parseSvgFile(source.getPath()) ); + const QByteArray rslt = svgParser.saveToQByteArray( + svgParser.parseSvgFile(source.getPath()) ); source.setSVG( rslt ); } } @@ -269,8 +279,17 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { return source; } +QScriptValue SkinContext::evaluateScript(QString expression, QString filename, int lineNumber) { + return m_scriptEngine.evaluate(expression, filename, lineNumber); +} + +QScriptValue SkinContext::evaluateScript(QString expression, QString filename) { + return m_scriptEngine.evaluate(expression, filename); +} + QScriptValue SkinContext::evaluateScript(QString expression) { - return m_scriptEngine.evaluate(expression); + QString unknownFilename; + return evaluateScript(expression,unknownFilename); } QScriptValue SkinContext::importScriptExtension(QString extensionName) { diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 85cdd55b6de1..e5fbebff3405 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "skin/pixmapsource.h" @@ -65,6 +66,8 @@ class SkinContext { QString getPixmapPath(const QDomNode& pixmapNode) const; PixmapSource getPixmapSource(const QDomNode& pixmapNode) const; + QScriptValue evaluateScript(QString expression, QString filename, int lineNumber); + QScriptValue evaluateScript(QString expression, QString filename); QScriptValue evaluateScript(QString expression); QScriptValue importScriptExtension(QString extensionName); const QScriptEngine& getScriptEngine() const; @@ -73,6 +76,7 @@ class SkinContext { QString variableNodeToText(const QDomElement& element) const; mutable QScriptEngine m_scriptEngine; + QScriptEngineDebugger m_debugger; QHash m_variables; QString m_skinBasePath; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index ede7775d1df8..038253cd6922 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -17,20 +17,22 @@ SvgParser::SvgParser(const SkinContext& parent) SvgParser::~SvgParser() { } -QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { +QDomNode SvgParser::parseSvgFile(const QString& svgFileName) { + m_currentFile = svgFileName; QFile* file = new QFile(svgFileName); - QDomNode out; + QDomNode svgNode; if (file->open(QIODevice::ReadWrite|QIODevice::Text)) { QDomDocument document; document.setContent(file); - QDomNode svgNode = document.elementsByTagName("svg").item(0); - out = parseSvgTree(svgNode); + svgNode = document.elementsByTagName("svg").item(0); + scanTree(svgNode, &SvgParser::parseElement); file->close(); } - return out; + return svgNode; } -QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { +QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) { + m_currentFile = "inline svg"; // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); scanTree(svgNode, &SvgParser::parseElement); @@ -80,22 +82,23 @@ void SvgParser::parseElement(const QDomNode& node) const { QFile scriptFile(m_context.getSkinPath(scriptPath)); scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); - QScriptValue result = m_context.evaluateScript(in.readAll()); - if (m_context.getScriptEngine().hasUncaughtException()) { - qDebug() << "SVG script exception : " << result.toString() - << "in" << scriptPath - << "line" << m_context.getScriptEngine() - .uncaughtExceptionLineNumber(); - } + QScriptValue result = m_context.evaluateScript(in.readAll(), scriptPath); + // if (m_context.getScriptEngine().hasUncaughtException()) { + // qDebug() << "SVG script exception : " << result.toString() + // << "in" << scriptPath + // << "line" << m_context.getScriptEngine() + // .uncaughtExceptionLineNumber(); + // } } // Evaluates the content of the script element QString expression = m_context.nodeToString(node); - QScriptValue result = m_context.evaluateScript(expression); - if (m_context.getScriptEngine().hasUncaughtException()) { - qDebug() << "SVG script exception : " << result.toString() << "\n" - << "line" << m_context.getScriptEngine() - .uncaughtExceptionLineNumber(); - } + QScriptValue result = m_context.evaluateScript(expression, m_currentFile, + node.lineNumber()); + // if (m_context.getScriptEngine().hasUncaughtException()) { + // qDebug() << "SVG script exception : " << result.toString() << "\n" + // << "line" << m_context.getScriptEngine() + // .uncaughtExceptionLineNumber(); + // } } } @@ -124,7 +127,8 @@ void SvgParser::parseAttributes(const QDomNode& node) const { // searching variable attributes : // expr-attribute_name="variable_name|expression" if (nameRx.indexIn(attributeName) != -1) { - QString varValue = evaluateTemplateExpression(attributeValue).toString(); + QString varValue = evaluateTemplateExpression(attributeValue, + node.lineNumber()).toString(); if (varValue.length()) { element.setAttribute(nameRx.cap(1), varValue); } @@ -139,7 +143,8 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QString match = hookRx.cap(0); QString tmp = "svg.templateHooks." + match; // qDebug() << "expression : " << tmp << "\n"; - QString replacement = evaluateTemplateExpression(tmp).toString(); + QString replacement = evaluateTemplateExpression(tmp, + node.lineNumber()).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); } @@ -177,14 +182,15 @@ QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { return out; } -QScriptValue SvgParser::evaluateTemplateExpression(QString expression) const { - QScriptValue out = m_context.evaluateScript(expression); +QScriptValue SvgParser::evaluateTemplateExpression(QString expression, int lineNumber) const { + QScriptValue out = m_context.evaluateScript(expression, m_currentFile, + lineNumber); if (m_context.getScriptEngine().hasUncaughtException()) { - qDebug() - << "SVG script exception : " << out.toString() - << "Empty string returned\n" - << "In file ... line " << m_context.getScriptEngine() - .uncaughtExceptionLineNumber(); + // qDebug() + // << "SVG script exception : " << out.toString() + // << "Empty string returned\n" + // << "In file " << m_currentFile << " line " << m_context.getScriptEngine() + // .uncaughtExceptionLineNumber(); // return an empty string as replacement for the in-attribute expression QScriptValue nullValue; diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 110d7a71c12f..6dade349f496 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -20,8 +20,10 @@ class SvgParser { QDomDocument getDocument(const QDomNode& node) const; void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; - QDomNode parseSvgFile(const QString& svgFileName) const; + // QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; + QDomNode parseSvgTree(const QDomNode& svgSkinNode); + // QDomNode parseSvgFile(const QString& svgFileName) const; + QDomNode parseSvgFile(const QString& svgFileName); QString saveToTempFile(const QDomNode& svgNode) const; QByteArray saveToQByteArray(const QDomNode& svgNode) const; void parseElement(const QDomNode& svgNode) const; @@ -29,10 +31,11 @@ class SvgParser { private: void parseAttributes(const QDomNode& node) const; - QScriptValue evaluateTemplateExpression(QString expression) const; + QScriptValue evaluateTemplateExpression(QString expression, int lineNumber) const; mutable SkinContext m_context; QDomDocument m_document; + QString m_currentFile; }; From a25d55dc4c3307fbed289bd1433ddeabfa42c1bc Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 6 Oct 2014 00:55:34 +0200 Subject: [PATCH 61/90] little cleaning --- src/skin/skincontext.cpp | 4 ---- src/skin/svgparser.cpp | 4 ++++ src/skin/svgparser.h | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index f0e73dd4caea..76d490b31f9c 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -22,7 +22,6 @@ SkinContext::SkinContext(const SkinContext& parent) if (CmdlineArgs::Instance().getDeveloper()) { // Enable script debugger m_debugger.attachTo(&m_scriptEngine); - m_debugger.action(QScriptEngineDebugger::InterruptAction); } } @@ -219,7 +218,6 @@ QString SkinContext::nodeToString(const QDomNode& node) const { QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - // const SvgParser svgParser(*this); SvgParser svgParser(*this); if (!pixmapNode.isNull()) { @@ -251,7 +249,6 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; PixmapSource source; - // const SvgParser svgParser(*this); SvgParser svgParser(*this); if (!pixmapNode.isNull()) { @@ -275,7 +272,6 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { } } - // qDebug() << "getPixmapSource out path" << source->getPath(); return source; } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 038253cd6922..eb2f4ff07e6d 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -186,6 +186,10 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression, int lineN QScriptValue out = m_context.evaluateScript(expression, m_currentFile, lineNumber); if (m_context.getScriptEngine().hasUncaughtException()) { + QScriptValue global = m_context.getScriptEngine().globalObject(); + QScriptValue hooksPattern = global.property("print").call( + global, + "Empty string returned"); // qDebug() // << "SVG script exception : " << out.toString() // << "Empty string returned\n" diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 6dade349f496..79c1b5aa5b0d 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -20,9 +20,7 @@ class SvgParser { QDomDocument getDocument(const QDomNode& node) const; void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - // QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; QDomNode parseSvgTree(const QDomNode& svgSkinNode); - // QDomNode parseSvgFile(const QString& svgFileName) const; QDomNode parseSvgFile(const QString& svgFileName); QString saveToTempFile(const QDomNode& svgNode) const; QByteArray saveToQByteArray(const QDomNode& svgNode) const; From 6f2b8e38947a4ee02e8713195a142e039de6e7e4 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 6 Oct 2014 00:55:53 +0200 Subject: [PATCH 62/90] little cleaning --- src/skin/svgparser.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index eb2f4ff07e6d..038253cd6922 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -186,10 +186,6 @@ QScriptValue SvgParser::evaluateTemplateExpression(QString expression, int lineN QScriptValue out = m_context.evaluateScript(expression, m_currentFile, lineNumber); if (m_context.getScriptEngine().hasUncaughtException()) { - QScriptValue global = m_context.getScriptEngine().globalObject(); - QScriptValue hooksPattern = global.property("print").call( - global, - "Empty string returned"); // qDebug() // << "SVG script exception : " << out.toString() // << "Empty string returned\n" From 696464f3648ec23f58f396c6cde65c6350e2dba2 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 6 Oct 2014 01:08:43 +0200 Subject: [PATCH 63/90] currentFile as mutable to keep svgParser const --- src/skin/skincontext.cpp | 4 ++-- src/skin/svgparser.cpp | 4 ++-- src/skin/svgparser.h | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 76d490b31f9c..dd316eb283d6 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -218,7 +218,7 @@ QString SkinContext::nodeToString(const QDomNode& node) const { QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; - SvgParser svgParser(*this); + const SvgParser svgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); @@ -249,7 +249,7 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; PixmapSource source; - SvgParser svgParser(*this); + const SvgParser svgParser(*this); if (!pixmapNode.isNull()) { QDomNode svgNode = selectNode(pixmapNode, "svg"); diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 038253cd6922..7a57ba1e49d5 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -17,7 +17,7 @@ SvgParser::SvgParser(const SkinContext& parent) SvgParser::~SvgParser() { } -QDomNode SvgParser::parseSvgFile(const QString& svgFileName) { +QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { m_currentFile = svgFileName; QFile* file = new QFile(svgFileName); QDomNode svgNode; @@ -31,7 +31,7 @@ QDomNode SvgParser::parseSvgFile(const QString& svgFileName) { return svgNode; } -QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) { +QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { m_currentFile = "inline svg"; // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 79c1b5aa5b0d..2f8bc0580654 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -20,8 +20,8 @@ class SvgParser { QDomDocument getDocument(const QDomNode& node) const; void scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const; - QDomNode parseSvgTree(const QDomNode& svgSkinNode); - QDomNode parseSvgFile(const QString& svgFileName); + QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; + QDomNode parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; QByteArray saveToQByteArray(const QDomNode& svgNode) const; void parseElement(const QDomNode& svgNode) const; @@ -33,7 +33,7 @@ class SvgParser { mutable SkinContext m_context; QDomDocument m_document; - QString m_currentFile; + mutable QString m_currentFile; }; From 9e2e711c9df198dae0e22a506d0def1c9319d484 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 6 Oct 2014 21:23:41 +0200 Subject: [PATCH 64/90] simplification + tidying --- src/skin/svgparser.cpp | 12 +++++------- src/skin/svgparser.h | 8 ++------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 7a57ba1e49d5..b443e5dbd8ca 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -25,7 +25,7 @@ QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { QDomDocument document; document.setContent(file); svgNode = document.elementsByTagName("svg").item(0); - scanTree(svgNode, &SvgParser::parseElement); + scanTree(svgNode); file->close(); } return svgNode; @@ -35,19 +35,17 @@ QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { m_currentFile = "inline svg"; // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); - scanTree(svgNode, &SvgParser::parseElement); + scanTree(svgNode); return svgNode; } -void SvgParser::scanTree(const QDomNode& node, void (SvgParser::*callback)(const QDomNode& node)const) const { - - (this->*callback)(node); +void SvgParser::scanTree(const QDomNode& node) const { + parseElement(node); QDomNodeList children = node.childNodes(); - for (uint i=0; i Date: Mon, 6 Oct 2014 21:50:09 +0200 Subject: [PATCH 65/90] cleaning + indent --- src/skin/svgparser.cpp | 44 ++++++++++++------------------------------ 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b443e5dbd8ca..11e72ed35a65 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -80,25 +80,14 @@ void SvgParser::parseElement(const QDomNode& node) const { QFile scriptFile(m_context.getSkinPath(scriptPath)); scriptFile.open(QIODevice::ReadOnly|QIODevice::Text); QTextStream in(&scriptFile); - QScriptValue result = m_context.evaluateScript(in.readAll(), scriptPath); - // if (m_context.getScriptEngine().hasUncaughtException()) { - // qDebug() << "SVG script exception : " << result.toString() - // << "in" << scriptPath - // << "line" << m_context.getScriptEngine() - // .uncaughtExceptionLineNumber(); - // } + QScriptValue result = m_context.evaluateScript(in.readAll(), + scriptPath); } // Evaluates the content of the script element QString expression = m_context.nodeToString(node); - QScriptValue result = m_context.evaluateScript(expression, m_currentFile, - node.lineNumber()); - // if (m_context.getScriptEngine().hasUncaughtException()) { - // qDebug() << "SVG script exception : " << result.toString() << "\n" - // << "line" << m_context.getScriptEngine() - // .uncaughtExceptionLineNumber(); - // } + QScriptValue result = m_context.evaluateScript( + expression, m_currentFile, node.lineNumber()); } - } void SvgParser::parseAttributes(const QDomNode& node) const { @@ -125,8 +114,8 @@ void SvgParser::parseAttributes(const QDomNode& node) const { // searching variable attributes : // expr-attribute_name="variable_name|expression" if (nameRx.indexIn(attributeName) != -1) { - QString varValue = evaluateTemplateExpression(attributeValue, - node.lineNumber()).toString(); + QString varValue = evaluateTemplateExpression( + attributeValue, node.lineNumber()).toString(); if (varValue.length()) { element.setAttribute(nameRx.cap(1), varValue); } @@ -140,9 +129,8 @@ void SvgParser::parseAttributes(const QDomNode& node) const { QStringList captured = hookRx.capturedTexts(); QString match = hookRx.cap(0); QString tmp = "svg.templateHooks." + match; - // qDebug() << "expression : " << tmp << "\n"; - QString replacement = evaluateTemplateExpression(tmp, - node.lineNumber()).toString(); + QString replacement = evaluateTemplateExpression( + tmp, node.lineNumber()).toString(); attributeValue.replace(pos, match.length(), replacement); pos += replacement.length(); } @@ -150,10 +138,8 @@ void SvgParser::parseAttributes(const QDomNode& node) const { attribute.setValue(attributeValue); } - } - QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { // Save the new svg in a temp file to use it with setPixmap QTemporaryFile svgFile; @@ -162,7 +148,6 @@ QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { svgFile.setAutoRemove(false); if (svgFile.open()) { - // qWarning() << "SVG : Temp filename" << svgFile.fileName() << " \n"; QTextStream out(&svgFile); svgNode.save(out, 2); svgFile.close(); @@ -180,16 +165,11 @@ QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { return out; } -QScriptValue SvgParser::evaluateTemplateExpression(QString expression, int lineNumber) const { - QScriptValue out = m_context.evaluateScript(expression, m_currentFile, - lineNumber); +QScriptValue SvgParser::evaluateTemplateExpression(QString expression, + int lineNumber) const { + QScriptValue out = m_context.evaluateScript( + expression, m_currentFile, lineNumber); if (m_context.getScriptEngine().hasUncaughtException()) { - // qDebug() - // << "SVG script exception : " << out.toString() - // << "Empty string returned\n" - // << "In file " << m_currentFile << " line " << m_context.getScriptEngine() - // .uncaughtExceptionLineNumber(); - // return an empty string as replacement for the in-attribute expression QScriptValue nullValue; return nullValue; From 3a10b16b4f1838a7c51f179d0aeb6d9219b71318 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 6 Oct 2014 23:33:13 +0200 Subject: [PATCH 66/90] TODOs ad questions --- script/console/__init__.js | 9 +++++++++ script/svg/__init__.js | 8 ++++---- src/skin/skincontext.cpp | 7 +++++++ src/skin/svgparser.cpp | 7 ++++++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/script/console/__init__.js b/script/console/__init__.js index a1d833b9a938..d18a0697f95d 100644 --- a/script/console/__init__.js +++ b/script/console/__init__.js @@ -1,4 +1,13 @@ __setupPackage__(__extension__); +/** + * This is a fake Firebug console api. To debug scripts a few more like in + * javascript. + * + * More info : + * http://blog.qt.digia.com/blog/2012/03/01/debugging-qt-quick-2-console-api/ + * + */ + console = { log : function(){ diff --git a/script/svg/__init__.js b/script/svg/__init__.js index f96744baab45..3da56904f0f0 100644 --- a/script/svg/__init__.js +++ b/script/svg/__init__.js @@ -1,5 +1,8 @@ __setupPackage__(__extension__); - +/** + * This extension provides the api to add hooks into attributes in + * the SVG parser. + */ svg.templateHooks = {}; svg.regexpQuote = function (str, delimiter) { @@ -27,9 +30,6 @@ svg.getHooksPattern = function(){ global = this; svg.templateHooks.variable = function( varName ){ - - // console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'); - // console.log(global[varName]); if( varName in global ){ return global[varName]; } diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index dd316eb283d6..670f29eb75f0 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -21,6 +21,9 @@ SkinContext::SkinContext(const SkinContext& parent) if (CmdlineArgs::Instance().getDeveloper()) { // Enable script debugger + // I used it to test the location of script errors in SVG + // TODO (jclaveau) : implement error location in variables + // of the normal skin. m_debugger.attachTo(&m_scriptEngine); } } @@ -275,6 +278,10 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { return source; } +/** + * All the methods below exist to access some of the scriptEngine features + * from the svgParser. + */ QScriptValue SkinContext::evaluateScript(QString expression, QString filename, int lineNumber) { return m_scriptEngine.evaluate(expression, filename, lineNumber); } diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 11e72ed35a65..1bc224cd9fff 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -58,7 +58,7 @@ void SvgParser::parseElement(const QDomNode& node) const { parseAttributes(node); if (element.tagName() == "Variable"){ - + // TODO (jclaveau) : support "expression" attribute // retrieve value QString varName = element.attribute("name"); QString varValue = m_context.variable(varName); @@ -105,6 +105,7 @@ void SvgParser::parseAttributes(const QDomNode& node) const { // expr-attribute_name="var_name"; QRegExp nameRx("^expr-([^=\\s]+)$"); + // TODO (jclaveau) : move this pattern definition to the script extension? for (uint i=0; i < attributes.length(); i++) { QDomAttr attribute = attributes.item(i).toAttr(); @@ -141,6 +142,9 @@ void SvgParser::parseAttributes(const QDomNode& node) const { } QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { + // TODO (jclaveau) : this method could be removed if the Spinny widget + // didn't require it. + // Save the new svg in a temp file to use it with setPixmap QTemporaryFile svgFile; svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); @@ -159,6 +163,7 @@ QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { } QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { + // TODO (jclaveau) : a way to look the svg after the parsing would be nice! QByteArray out; QTextStream textStream(&out); svgNode.save(textStream, 2); From 8e42939480609f3447df64a63a2f5a40525ce2c6 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 7 Oct 2014 21:13:49 +0200 Subject: [PATCH 67/90] adding support for value attribute on text elements --- src/skin/svgparser.cpp | 27 +++++++++++++++++++++++---- src/skin/svgparser.h | 6 +++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 1bc224cd9fff..be015ca5bf30 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -39,7 +39,7 @@ QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { return svgNode; } -void SvgParser::scanTree(const QDomNode& node) const { +void SvgParser::scanTree(QDomNode& node) const { parseElement(node); QDomNodeList children = node.childNodes(); for (uint i=0; i Date: Tue, 7 Oct 2014 22:34:30 +0200 Subject: [PATCH 68/90] support for expression attribute on Variable element --- src/skin/svgparser.cpp | 31 ++++++++++++++++++++----------- src/skin/svgparser.h | 3 ++- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index be015ca5bf30..5a240438a014 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -77,19 +77,27 @@ void SvgParser::parseElement(QDomNode& node) const { } } else if (element.tagName() == "Variable"){ - // TODO (jclaveau) : support "expression" attribute - // retrieve value - QString varName = element.attribute("name"); - QString varValue = m_context.variable(varName); - // replace node by its value - QDomNode varParentNode = node.parentNode(); - QDomNode varValueNode = node.ownerDocument().createTextNode(varValue); - QDomNode oldChild = varParentNode.replaceChild(varValueNode, node); + QString value; - if (oldChild.isNull()) { - // replaceChild has a really weird behaviour so I add this check - qDebug() << "SVG : unable to replace dom node changed. \n"; + if (element.hasAttribute("expression")){ + QString expression = element.attribute("expression"); + value = evaluateTemplateExpression( + expression, node.lineNumber() ).toString().trimmed(); + } else if (element.hasAttribute("name")){ + value = m_context.variable(element.attribute("name")); + } + + if (!value.isNull()){ + // replace node by its value + QDomNode varParentNode = node.parentNode(); + QDomNode varValueNode = node.ownerDocument().createTextNode(value); + QDomNode oldChild = varParentNode.replaceChild(varValueNode, node); + + if (oldChild.isNull()) { + // replaceChild has a really weird behaviour so I add this check + qDebug() << "SVG : unable to replace dom node changed. \n"; + } } } else if (element.tagName() == "script"){ @@ -109,6 +117,7 @@ void SvgParser::parseElement(QDomNode& node) const { } } + void SvgParser::parseAttributes(QDomNode& node) const { QDomNamedNodeMap attributes = node.attributes(); diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index dac8856be4b2..9bbfbb1b9b77 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -25,7 +25,8 @@ class SvgParser { void scanTree(QDomNode& node) const; void parseElement(QDomNode& svgNode) const; void parseAttributes(QDomNode& node) const; - QScriptValue evaluateTemplateExpression(QString expression, int lineNumber) const; + QScriptValue evaluateTemplateExpression(QString expression, + int lineNumber) const; mutable SkinContext m_context; QDomDocument m_document; From b0ed540fb9080a4e1ab37baf37a373b32c8226ba Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Tue, 7 Oct 2014 22:38:59 +0200 Subject: [PATCH 69/90] exception logic --- src/skin/svgparser.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 5a240438a014..b1ac839624d4 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -69,17 +69,16 @@ void SvgParser::parseElement(QDomNode& node) const { for (uint i=0; i Date: Tue, 7 Oct 2014 22:59:12 +0200 Subject: [PATCH 70/90] exception logic --- src/skin/svgparser.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b1ac839624d4..610036ae6a8f 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -61,18 +61,16 @@ void SvgParser::parseElement(QDomNode& node) const { if (element.hasAttribute("value")){ QString expression = element.attribute("value"); QString result = evaluateTemplateExpression( - expression, node.lineNumber() ).toString().trimmed(); + expression, node.lineNumber() ).toString(); - if (result.length()){ - if (!m_context.getScriptEngine().hasUncaughtException()) { - QDomNodeList children = node.childNodes(); - for (uint i=0; i Date: Thu, 9 Oct 2014 23:44:26 +0200 Subject: [PATCH 71/90] cleaning useless overload --- src/dlgautodj.cpp | 4 ++-- src/skin/skincontext.cpp | 13 +++---------- src/skin/skincontext.h | 6 +++--- src/skin/svgparser.cpp | 1 - 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/dlgautodj.cpp b/src/dlgautodj.cpp index 4c819d806931..289d7d2bbef3 100644 --- a/src/dlgautodj.cpp +++ b/src/dlgautodj.cpp @@ -291,7 +291,7 @@ void DlgAutoDJ::toggleAutoDJButton(bool enable) { qDebug() << "Queue is empty now"; pushButtonAutoDJ->setChecked(false); if (m_pCOTEnabledAutoDJ->get() != 0.0) { - m_pCOTEnabledAutoDJ->slot(0.0); + m_pCOTEnabledAutoDJ->set(0.0); } return; } @@ -339,7 +339,7 @@ void DlgAutoDJ::toggleAutoDJButton(bool enable) { pushButtonAutoDJ->setToolTip(tr("Enable Auto DJ")); pushButtonAutoDJ->setText(tr("Enable Auto DJ")); if (m_pCOTEnabledAutoDJ->get() != 0.0) { - m_pCOTEnabledAutoDJ->slot(0.0); + m_pCOTEnabledAutoDJ->set(0.0); } qDebug() << "Auto DJ disabled"; m_eState = ADJ_DISABLED; diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 670f29eb75f0..6d81aeeed071 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -282,19 +282,12 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { * All the methods below exist to access some of the scriptEngine features * from the svgParser. */ -QScriptValue SkinContext::evaluateScript(QString expression, QString filename, int lineNumber) { +QScriptValue SkinContext::evaluateScript(const QString& expression, + const QString& filename/*=QString()*/, + int lineNumber/*=1*/) { return m_scriptEngine.evaluate(expression, filename, lineNumber); } -QScriptValue SkinContext::evaluateScript(QString expression, QString filename) { - return m_scriptEngine.evaluate(expression, filename); -} - -QScriptValue SkinContext::evaluateScript(QString expression) { - QString unknownFilename; - return evaluateScript(expression,unknownFilename); -} - QScriptValue SkinContext::importScriptExtension(QString extensionName) { QScriptValue out = m_scriptEngine.importExtension(extensionName); if (m_scriptEngine.hasUncaughtException()) { diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index e5fbebff3405..41802c973c93 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -66,9 +66,9 @@ class SkinContext { QString getPixmapPath(const QDomNode& pixmapNode) const; PixmapSource getPixmapSource(const QDomNode& pixmapNode) const; - QScriptValue evaluateScript(QString expression, QString filename, int lineNumber); - QScriptValue evaluateScript(QString expression, QString filename); - QScriptValue evaluateScript(QString expression); + QScriptValue evaluateScript(const QString& expression, + const QString& filename=QString(), + int lineNumber=1); QScriptValue importScriptExtension(QString extensionName); const QScriptEngine& getScriptEngine() const; diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 610036ae6a8f..c0fb7cb9afa5 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -52,7 +52,6 @@ void SvgParser::scanTree(QDomNode& node) const { // replaces Variables nodes in an svg dom tree void SvgParser::parseElement(QDomNode& node) const { - QDomElement element = node.toElement(); parseAttributes(node); From b573548e9e0215e76fcc17fb7d0e41a0e0561f1e Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Thu, 9 Oct 2014 23:49:27 +0200 Subject: [PATCH 72/90] somme consts --- src/skin/skincontext.cpp | 2 +- src/skin/skincontext.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 6d81aeeed071..c7be7aee1f60 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -288,7 +288,7 @@ QScriptValue SkinContext::evaluateScript(const QString& expression, return m_scriptEngine.evaluate(expression, filename, lineNumber); } -QScriptValue SkinContext::importScriptExtension(QString extensionName) { +QScriptValue SkinContext::importScriptExtension(const QString& extensionName) { QScriptValue out = m_scriptEngine.importExtension(extensionName); if (m_scriptEngine.hasUncaughtException()) { qDebug() << out.toString(); diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 41802c973c93..e7e29b19fa5b 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -69,7 +69,7 @@ class SkinContext { QScriptValue evaluateScript(const QString& expression, const QString& filename=QString(), int lineNumber=1); - QScriptValue importScriptExtension(QString extensionName); + QScriptValue importScriptExtension(const QString& extensionName); const QScriptEngine& getScriptEngine() const; private: From 3030d03ad175bd309bbf363ea9c7ec41e3623224 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Fri, 10 Oct 2014 09:46:53 +0200 Subject: [PATCH 73/90] cleaning + consts --- src/skin/svgparser.cpp | 5 +---- src/skin/svgparser.h | 5 ++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index c0fb7cb9afa5..cd9510690df4 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -5,9 +5,6 @@ #include "skin/svgparser.h" -SvgParser::SvgParser() { -} - SvgParser::SvgParser(const SkinContext& parent) : m_context(parent) { m_context.importScriptExtension("console"); @@ -194,7 +191,7 @@ QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { return out; } -QScriptValue SvgParser::evaluateTemplateExpression(QString expression, +QScriptValue SvgParser::evaluateTemplateExpression(const QString expression, int lineNumber) const { QScriptValue out = m_context.evaluateScript( expression, m_currentFile, lineNumber); diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 9bbfbb1b9b77..ee9bb4b798b0 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -12,7 +12,6 @@ // A class for managing the svg files class SvgParser { public: - SvgParser(); SvgParser(const SkinContext& parent); virtual ~SvgParser(); @@ -25,12 +24,12 @@ class SvgParser { void scanTree(QDomNode& node) const; void parseElement(QDomNode& svgNode) const; void parseAttributes(QDomNode& node) const; - QScriptValue evaluateTemplateExpression(QString expression, + QScriptValue evaluateTemplateExpression(const QString expression, int lineNumber) const; mutable SkinContext m_context; - QDomDocument m_document; mutable QString m_currentFile; + QDomDocument m_document; }; From 5e4e9f0ed03c900a142afc04334e8dff5d5492f5 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Fri, 10 Oct 2014 21:24:15 +0200 Subject: [PATCH 74/90] disabling the debugger to work on the skin --- src/skin/skincontext.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index c7be7aee1f60..7986c6eed269 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -24,7 +24,7 @@ SkinContext::SkinContext(const SkinContext& parent) // I used it to test the location of script errors in SVG // TODO (jclaveau) : implement error location in variables // of the normal skin. - m_debugger.attachTo(&m_scriptEngine); + // m_debugger.attachTo(&m_scriptEngine); } } From 32b56763d0bd361c794fa3e91fae13bcce47b85b Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 11 Oct 2014 17:06:20 +0200 Subject: [PATCH 75/90] Menu to disable/enable script debugger --- src/mixxx.cpp | 26 +++++++++++++++++++++++++- src/mixxx.h | 5 ++++- src/skin/legacyskinparser.cpp | 2 +- src/skin/skincontext.cpp | 12 +++++++++--- src/skin/skincontext.h | 4 ++++ 5 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/mixxx.cpp b/src/mixxx.cpp index 568296abf6d7..2cd0a41d0e52 100644 --- a/src/mixxx.cpp +++ b/src/mixxx.cpp @@ -1297,13 +1297,31 @@ void MixxxMainWindow::initActions() m_pDeveloperTools->setShortcut( QKeySequence(m_pKbdConfig->getValueString(ConfigKey("[KeyboardShortcuts]", "OptionsMenu_DeveloperTools"), - tr("Ctrl+Shift+D")))); + tr("Ctrl+Shift+T")))); m_pDeveloperTools->setShortcutContext(Qt::ApplicationShortcut); m_pDeveloperTools->setStatusTip(developerToolsText); m_pDeveloperTools->setWhatsThis(buildWhatsThis(developerToolsTitle, developerToolsText)); connect(m_pDeveloperTools, SIGNAL(triggered()), this, SLOT(slotDeveloperTools())); + QString scriptDebuggerTitle = tr("Debugger Enabled"); + QString scriptDebuggerText = tr("Enables the debugger during skin parsing"); + bool scriptDebuggerEnabled = m_pConfig->getValueString( + ConfigKey("[ScriptDebugger]", "Enabled")) == "1"; + m_pDeveloperDebugger = new QAction(scriptDebuggerTitle, this); + + m_pDeveloperDebugger->setShortcut( + QKeySequence(m_pKbdConfig->getValueString(ConfigKey("[KeyboardShortcuts]", + "DeveloperMenu_EnableDebugger"), + tr("Ctrl+Shift+D")))); + m_pDeveloperDebugger->setShortcutContext(Qt::ApplicationShortcut); + m_pDeveloperDebugger->setWhatsThis(buildWhatsThis(keyboardShortcutTitle, keyboardShortcutText)); + m_pDeveloperDebugger->setCheckable(true); + m_pDeveloperDebugger->setStatusTip(scriptDebuggerText); + m_pDeveloperDebugger->setChecked(scriptDebuggerEnabled); + connect(m_pDeveloperDebugger, SIGNAL(toggled(bool)), + this, SLOT(slotDeveloperDebugger(bool))); + // TODO: This code should live in a separate class. m_TalkoverMapper = new QSignalMapper(this); connect(m_TalkoverMapper, SIGNAL(mapped(int)), @@ -1378,6 +1396,7 @@ void MixxxMainWindow::initMenuBar() // Developer Menu m_pDeveloperMenu->addAction(m_pDeveloperReloadSkin); m_pDeveloperMenu->addAction(m_pDeveloperTools); + m_pDeveloperMenu->addAction(m_pDeveloperDebugger); // menuBar entry helpMenu m_pHelpMenu->addAction(m_pHelpSupport); @@ -1484,6 +1503,11 @@ void MixxxMainWindow::slotDeveloperTools() { m_pDeveloperToolsDlg->activateWindow(); } +void MixxxMainWindow::slotDeveloperDebugger(bool toggle) { + m_pConfig->set(ConfigKey("[ScriptDebugger]","Enabled"), + ConfigValue(toggle ? 1 : 0)); +} + void MixxxMainWindow::slotDeveloperToolsClosed() { m_pDeveloperToolsDlg = NULL; } diff --git a/src/mixxx.h b/src/mixxx.h index 62c84480aba6..428948d7882f 100644 --- a/src/mixxx.h +++ b/src/mixxx.h @@ -123,6 +123,8 @@ class MixxxMainWindow : public QMainWindow { // Open the developer tools dialog. void slotDeveloperTools(); void slotDeveloperToolsClosed(); + // toogle the script debugger + void slotDeveloperDebugger(bool toggle); void slotToCenterOfPrimaryScreen(); @@ -240,7 +242,8 @@ class MixxxMainWindow : public QMainWindow { QAction* m_pDeveloperReloadSkin; QAction* m_pDeveloperTools; DlgDeveloperTools* m_pDeveloperToolsDlg; - + QAction* m_pDeveloperDebugger; + int m_iNoPlaylists; /** Pointer to preference dialog */ diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 35966d2f5d51..5bd2e39e28da 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -321,7 +321,7 @@ QWidget* LegacySkinParser::parseSkin(QString skinPath, QWidget* pParent) { // created parent so MixxxMainWindow can use it for nefarious purposes ( // fullscreen mostly) --bkgood m_pParent = pParent; - m_pContext = new SkinContext(); + m_pContext = new SkinContext(m_pConfig); m_pContext->setSkinBasePath(skinPath.append("/")); QList widgets = parseNode(skinDocument); diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 7986c6eed269..7549af714451 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -10,21 +10,27 @@ SkinContext::SkinContext() { } +SkinContext::SkinContext(ConfigObject* pConfig) + : m_pConfig(pConfig) { +} + SkinContext::SkinContext(const SkinContext& parent) : m_variables(parent.variables()), - m_skinBasePath(parent.m_skinBasePath) { + m_skinBasePath(parent.m_skinBasePath), + m_pConfig(parent.m_pConfig) { QScriptValue context = m_scriptEngine.currentContext()->activationObject(); for (QHash::const_iterator it = m_variables.begin(); it != m_variables.end(); ++it) { context.setProperty(it.key(), it.value()); } - if (CmdlineArgs::Instance().getDeveloper()) { + if (CmdlineArgs::Instance().getDeveloper() && m_pConfig->getValueString( + ConfigKey("[ScriptDebugger]", "Enabled")) == "1") { // Enable script debugger // I used it to test the location of script errors in SVG // TODO (jclaveau) : implement error location in variables // of the normal skin. - // m_debugger.attachTo(&m_scriptEngine); + m_debugger.attachTo(&m_scriptEngine); } } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index e7e29b19fa5b..46cabd37222c 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -9,14 +9,17 @@ #include #include +#include "configobject.h" #include "skin/pixmapsource.h" + // A class for managing the current context/environment when processing a // skin. Used hierarchically by LegacySkinParser to create new contexts and // evaluate skin XML nodes while loading the skin. class SkinContext { public: SkinContext(); + SkinContext(ConfigObject* pConfig); SkinContext(const SkinContext& parent); virtual ~SkinContext(); @@ -79,6 +82,7 @@ class SkinContext { QScriptEngineDebugger m_debugger; QHash m_variables; QString m_skinBasePath; + ConfigObject* m_pConfig; }; From 5816bf54460d1c9cc5553e4e9bfe66f6cdace241 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 11 Oct 2014 19:02:49 +0200 Subject: [PATCH 76/90] debug location for Variable 'expression' attribute --- src/skin/legacyskinparser.cpp | 5 +++-- src/skin/skincontext.cpp | 19 +++++++++++++++---- src/skin/skincontext.h | 5 +++-- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 5bd2e39e28da..02890f59051e 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -321,7 +321,7 @@ QWidget* LegacySkinParser::parseSkin(QString skinPath, QWidget* pParent) { // created parent so MixxxMainWindow can use it for nefarious purposes ( // fullscreen mostly) --bkgood m_pParent = pParent; - m_pContext = new SkinContext(m_pConfig); + m_pContext = new SkinContext(m_pConfig, skinPath.append("/skin.xml")); m_pContext->setSkinBasePath(skinPath.append("/")); QList widgets = parseNode(skinDocument); @@ -1215,7 +1215,8 @@ QList LegacySkinParser::parseTemplate(QDomElement node) { // Take any elements from this node and update the context // with them. m_pContext->updateVariables(node); - + m_pContext->setXmlPath(path); + QList widgets; QDomNode child = templateNode.firstChild(); diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 7549af714451..fd9e94b5bad9 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -10,14 +10,16 @@ SkinContext::SkinContext() { } -SkinContext::SkinContext(ConfigObject* pConfig) - : m_pConfig(pConfig) { +SkinContext::SkinContext(ConfigObject* pConfig, QString xmlPath) + : m_pConfig(pConfig), + m_xmlPath(xmlPath) { } SkinContext::SkinContext(const SkinContext& parent) : m_variables(parent.variables()), m_skinBasePath(parent.m_skinBasePath), - m_pConfig(parent.m_pConfig) { + m_pConfig(parent.m_pConfig), + m_xmlPath(parent.m_xmlPath) { QScriptValue context = m_scriptEngine.currentContext()->activationObject(); for (QHash::const_iterator it = m_variables.begin(); it != m_variables.end(); ++it) { @@ -57,6 +59,10 @@ void SkinContext::setVariable(const QString& name, const QString& value) { context.setProperty(name, value); } +void SkinContext::setXmlPath(const QString& xmlPath) { + m_xmlPath = xmlPath; +} + void SkinContext::updateVariables(const QDomNode& node) { QDomNode child = node.firstChild(); while (!child.isNull()) { @@ -184,8 +190,13 @@ QString SkinContext::selectAttributeString(const QDomElement& element, QString SkinContext::variableNodeToText(const QDomElement& variableNode) const { if (variableNode.hasAttribute("expression")) { + // QDomAttr attributeNode = variableNode.cloneNode().toElement() + // .attributeNode("expression"); + // QScriptValue result = m_scriptEngine.evaluate( + // attributeNode.value(), m_xmlPath, attributeNode.lineNumber()); QScriptValue result = m_scriptEngine.evaluate( - variableNode.attribute("expression")); + variableNode.attribute("expression"), m_xmlPath, + variableNode.lineNumber()); return result.toString(); } else if (variableNode.hasAttribute("name")) { QString variableName = variableNode.attribute("name"); diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 46cabd37222c..83d30c4d68ef 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -19,7 +19,7 @@ class SkinContext { public: SkinContext(); - SkinContext(ConfigObject* pConfig); + SkinContext(ConfigObject* pConfig, QString xmlPath); SkinContext(const SkinContext& parent); virtual ~SkinContext(); @@ -41,7 +41,7 @@ class SkinContext { return m_variables; } void setVariable(const QString& name, const QString& value); - + void setXmlPath(const QString& xmlPath); // Updates the SkinContext with all the children of node. void updateVariables(const QDomNode& node); @@ -83,6 +83,7 @@ class SkinContext { QHash m_variables; QString m_skinBasePath; ConfigObject* m_pConfig; + QString m_xmlPath; }; From 624c8aebfee5cad33a3e36461bceda4e353f69fa Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 11 Oct 2014 19:09:12 +0200 Subject: [PATCH 77/90] little dbg --- src/skin/legacyskinparser.cpp | 2 +- src/skin/skincontext.cpp | 2 +- src/skin/skincontext.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/skin/legacyskinparser.cpp b/src/skin/legacyskinparser.cpp index 02890f59051e..49cd72c49ee9 100644 --- a/src/skin/legacyskinparser.cpp +++ b/src/skin/legacyskinparser.cpp @@ -321,7 +321,7 @@ QWidget* LegacySkinParser::parseSkin(QString skinPath, QWidget* pParent) { // created parent so MixxxMainWindow can use it for nefarious purposes ( // fullscreen mostly) --bkgood m_pParent = pParent; - m_pContext = new SkinContext(m_pConfig, skinPath.append("/skin.xml")); + m_pContext = new SkinContext(m_pConfig, skinPath + "/skin.xml"); m_pContext->setSkinBasePath(skinPath.append("/")); QList widgets = parseNode(skinDocument); diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index fd9e94b5bad9..8a09e9fca682 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -59,7 +59,7 @@ void SkinContext::setVariable(const QString& name, const QString& value) { context.setProperty(name, value); } -void SkinContext::setXmlPath(const QString& xmlPath) { +void SkinContext::setXmlPath(const QString xmlPath) { m_xmlPath = xmlPath; } diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 83d30c4d68ef..4dbc5be0e8ab 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -41,7 +41,7 @@ class SkinContext { return m_variables; } void setVariable(const QString& name, const QString& value); - void setXmlPath(const QString& xmlPath); + void setXmlPath(const QString xmlPath); // Updates the SkinContext with all the children of node. void updateVariables(const QDomNode& node); From 563563c5f6e1fbc0b553cb999de7b921ed091bbe Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sat, 11 Oct 2014 22:54:34 +0200 Subject: [PATCH 78/90] cleaning + litlle things --- src/skin/skincontext.cpp | 12 ++---------- src/skin/svgparser.cpp | 13 +++++++++---- src/skin/svgparser.h | 3 ++- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 8a09e9fca682..2cc91245ab8f 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -29,9 +29,6 @@ SkinContext::SkinContext(const SkinContext& parent) if (CmdlineArgs::Instance().getDeveloper() && m_pConfig->getValueString( ConfigKey("[ScriptDebugger]", "Enabled")) == "1") { // Enable script debugger - // I used it to test the location of script errors in SVG - // TODO (jclaveau) : implement error location in variables - // of the normal skin. m_debugger.attachTo(&m_scriptEngine); } } @@ -190,10 +187,6 @@ QString SkinContext::selectAttributeString(const QDomElement& element, QString SkinContext::variableNodeToText(const QDomElement& variableNode) const { if (variableNode.hasAttribute("expression")) { - // QDomAttr attributeNode = variableNode.cloneNode().toElement() - // .attributeNode("expression"); - // QScriptValue result = m_scriptEngine.evaluate( - // attributeNode.value(), m_xmlPath, attributeNode.lineNumber()); QScriptValue result = m_scriptEngine.evaluate( variableNode.attribute("expression"), m_xmlPath, variableNode.lineNumber()); @@ -245,7 +238,7 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { if (!svgNode.isNull()) { // inline svg pixmapPath = svgParser.saveToTempFile( - svgParser.parseSvgTree(svgNode) ); + svgParser.parseSvgTree(svgNode, m_xmlPath) ); } else { // filename pixmapName = nodeToString(pixmapNode); @@ -264,7 +257,6 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { return pixmapPath; } - PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { QString pixmapPath, pixmapName; PixmapSource source; @@ -276,7 +268,7 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { if (!svgNode.isNull()) { // inline svg const QByteArray rslt = svgParser.saveToQByteArray( - svgParser.parseSvgTree(svgNode) ); + svgParser.parseSvgTree(svgNode, m_xmlPath) ); source.setSVG( rslt ); } else { // filename diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index cd9510690df4..60a69840f148 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -18,7 +18,7 @@ QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { m_currentFile = svgFileName; QFile* file = new QFile(svgFileName); QDomNode svgNode; - if (file->open(QIODevice::ReadWrite|QIODevice::Text)) { + if (file->open(QIODevice::ReadOnly|QIODevice::Text)) { QDomDocument document; document.setContent(file); svgNode = document.elementsByTagName("svg").item(0); @@ -28,8 +28,9 @@ QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { return svgNode; } -QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode) const { - m_currentFile = "inline svg"; +QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode, + const QString sourcePath) const { + m_currentFile = sourcePath; // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); scanTree(svgNode); @@ -71,13 +72,17 @@ void SvgParser::parseElement(QDomNode& node) const { } } else if (element.tagName() == "Variable"){ - QString value; if (element.hasAttribute("expression")){ QString expression = element.attribute("expression"); value = evaluateTemplateExpression( expression, node.lineNumber() ).toString(); } else if (element.hasAttribute("name")){ + /* TODO (jclaveau) : Getting the variable fro the context or the + * script engine have the same result here (in the skin context two) + * Isn't it useless? + * m_context.variable(name) <=> m_scriptEngine.evaluate(name) + */ value = m_context.variable(element.attribute("name")); } diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index ee9bb4b798b0..dee15168cf7d 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -15,7 +15,8 @@ class SvgParser { SvgParser(const SkinContext& parent); virtual ~SvgParser(); - QDomNode parseSvgTree(const QDomNode& svgSkinNode) const; + QDomNode parseSvgTree(const QDomNode& svgSkinNode, + const QString sourcePath) const; QDomNode parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; QByteArray saveToQByteArray(const QDomNode& svgNode) const; From fc6dff9a2b6baa2d73fcc34e2df312fbd033e3b0 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Mon, 13 Oct 2014 22:12:21 +0200 Subject: [PATCH 79/90] comment to notice segfault --- src/skin/svgparser.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 60a69840f148..05145059ca25 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -192,7 +192,10 @@ QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { // TODO (jclaveau) : a way to look the svg after the parsing would be nice! QByteArray out; QTextStream textStream(&out); + // TODO (jclaveau) : saving crashes if there are comments before + // the svg root node. Need help :D svgNode.save(textStream, 2); + return out; } From 49f0e2f49a557767354d9858420d88b428f3b7c8 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 01:29:35 +0100 Subject: [PATCH 80/90] consts + cleaning --- src/skin/pixmapsource.cpp | 6 +++--- src/skin/pixmapsource.h | 6 +++--- src/widget/wpushbutton.cpp | 1 - 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp index 0215ae3bb8c3..c7b8132a0b02 100644 --- a/src/skin/pixmapsource.cpp +++ b/src/skin/pixmapsource.cpp @@ -5,7 +5,7 @@ PixmapSource::PixmapSource() { } -PixmapSource::PixmapSource( QString filepath ) { +PixmapSource::PixmapSource(const QString filepath) { setPath(filepath); } @@ -20,7 +20,7 @@ QString PixmapSource::getPath() const { return m_path; } -void PixmapSource::setPath( QString newPath ) { +void PixmapSource::setPath(const QString newPath) { m_baData.truncate(0); m_path = newPath; if (m_path.endsWith(".svg", Qt::CaseInsensitive)) { @@ -42,7 +42,7 @@ bool PixmapSource::isBitmap() const { return m_eType == BITMAP; } -void PixmapSource::setSVG( QByteArray content ) { +void PixmapSource::setSVG(const QByteArray content) { m_baData.truncate(0); m_baData += content; m_eType = SVG; diff --git a/src/skin/pixmapsource.h b/src/skin/pixmapsource.h index 5dff39eef8a5..53f438547568 100644 --- a/src/skin/pixmapsource.h +++ b/src/skin/pixmapsource.h @@ -6,14 +6,14 @@ class PixmapSource { public: PixmapSource(); - PixmapSource( QString filepath ); + PixmapSource(const QString filepath); virtual ~PixmapSource(); bool isEmpty() const; bool isSVG() const; bool isBitmap() const; - void setSVG( QByteArray content ); - void setPath( QString newPath ); + void setSVG(const QByteArray content); + void setPath(const QString newPath); QString getPath() const; QByteArray getData() const; QString getId() const; diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp index ef06ebc8a091..6578ff5e1234 100644 --- a/src/widget/wpushbutton.cpp +++ b/src/widget/wpushbutton.cpp @@ -75,7 +75,6 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) { int iState = stateContext.selectInt(state, "Number"); if (iState < m_iNoStates) { - QString pixmapPath; PixmapSource pixmapSource; pixmapSource = stateContext.getPixmapSource(stateContext.selectNode(state, "Unpressed")); From e35b475c9e49ef75fa356872811a3ee35cd7121e Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 01:37:33 +0100 Subject: [PATCH 81/90] review corrections progress --- src/skin/pixmapsource.cpp | 3 +-- src/skin/skincontext.cpp | 3 +-- src/skin/svgparser.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp index c7b8132a0b02..7639bae4651f 100644 --- a/src/skin/pixmapsource.cpp +++ b/src/skin/pixmapsource.cpp @@ -43,8 +43,7 @@ bool PixmapSource::isBitmap() const { } void PixmapSource::setSVG(const QByteArray content) { - m_baData.truncate(0); - m_baData += content; + m_baData = content; m_eType = SVG; } diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index 2cc91245ab8f..e8497caac84c 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -258,7 +258,6 @@ QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { } PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { - QString pixmapPath, pixmapName; PixmapSource source; const SvgParser svgParser(*this); @@ -272,7 +271,7 @@ PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { source.setSVG( rslt ); } else { // filename - pixmapName = nodeToString(pixmapNode); + QString pixmapName = nodeToString(pixmapNode); if (!pixmapName.isEmpty()) { source.setPath( getSkinPath(pixmapName) ); if (source.isSVG()) { diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 05145059ca25..b6ad838db543 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -16,14 +16,14 @@ SvgParser::~SvgParser() { QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { m_currentFile = svgFileName; - QFile* file = new QFile(svgFileName); + QFile file(svgFileName); QDomNode svgNode; - if (file->open(QIODevice::ReadOnly|QIODevice::Text)) { + if (file.open(QIODevice::ReadOnly|QIODevice::Text)) { QDomDocument document; - document.setContent(file); + document.setContent(&file); svgNode = document.elementsByTagName("svg").item(0); scanTree(svgNode); - file->close(); + file.close(); } return svgNode; } From 9ec4a4e2e71abc019ae53a655862b7143741f1f8 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 02:00:19 +0100 Subject: [PATCH 82/90] review corrections progress --- src/widget/wpixmapstore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widget/wpixmapstore.cpp b/src/widget/wpixmapstore.cpp index 5cbe0084e5db..006390e780c2 100644 --- a/src/widget/wpixmapstore.cpp +++ b/src/widget/wpixmapstore.cpp @@ -71,7 +71,7 @@ Paintable::Paintable(const QString& fileName, DrawMode mode) Paintable::Paintable(PixmapSource source, DrawMode mode) : m_draw_mode(mode) { if (source.isSVG()) { - QSvgRenderer* pSvgRenderer = new QSvgRenderer(); + QScopedPointer pSvgRenderer(new QSvgRenderer()); if( source.getData().isEmpty() ){ pSvgRenderer->load(source.getPath()); } else { @@ -79,7 +79,7 @@ Paintable::Paintable(PixmapSource source, DrawMode mode) } if (mode == STRETCH) { - m_pSvg.reset(pSvgRenderer); + m_pSvg.reset(pSvgRenderer.take()); } else if (mode == TILE) { // The SVG renderer doesn't directly support tiling, so we render // it to a pixmap which will then get tiled. From a7cdc23fd5c489f9f1906d01aa42a69358be4920 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 03:03:23 +0100 Subject: [PATCH 83/90] forgotten references --- src/skin/pixmapsource.cpp | 6 +++--- src/skin/pixmapsource.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/skin/pixmapsource.cpp b/src/skin/pixmapsource.cpp index 7639bae4651f..62a2973f78ce 100644 --- a/src/skin/pixmapsource.cpp +++ b/src/skin/pixmapsource.cpp @@ -5,7 +5,7 @@ PixmapSource::PixmapSource() { } -PixmapSource::PixmapSource(const QString filepath) { +PixmapSource::PixmapSource(const QString &filepath) { setPath(filepath); } @@ -20,7 +20,7 @@ QString PixmapSource::getPath() const { return m_path; } -void PixmapSource::setPath(const QString newPath) { +void PixmapSource::setPath(const QString &newPath) { m_baData.truncate(0); m_path = newPath; if (m_path.endsWith(".svg", Qt::CaseInsensitive)) { @@ -42,7 +42,7 @@ bool PixmapSource::isBitmap() const { return m_eType == BITMAP; } -void PixmapSource::setSVG(const QByteArray content) { +void PixmapSource::setSVG(const QByteArray &content) { m_baData = content; m_eType = SVG; } diff --git a/src/skin/pixmapsource.h b/src/skin/pixmapsource.h index 53f438547568..1c1756e6d81c 100644 --- a/src/skin/pixmapsource.h +++ b/src/skin/pixmapsource.h @@ -6,14 +6,14 @@ class PixmapSource { public: PixmapSource(); - PixmapSource(const QString filepath); + PixmapSource(const QString &filepath); virtual ~PixmapSource(); bool isEmpty() const; bool isSVG() const; bool isBitmap() const; - void setSVG(const QByteArray content); - void setPath(const QString newPath); + void setSVG(const QByteArray &content); + void setPath(const QString &newPath); QString getPath() const; QByteArray getData() const; QString getId() const; From 707d7693426fab405d44a488bba296cb0cdea250 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 06:02:49 +0100 Subject: [PATCH 84/90] svg for wspinny --- src/widget/wimagestore.cpp | 47 ++++++++++++++++++++++++++++++-------- src/widget/wimagestore.h | 3 +++ src/widget/wspinny.cpp | 11 +++++---- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/widget/wimagestore.cpp b/src/widget/wimagestore.cpp index 50ecc605bb41..2273aa437853 100644 --- a/src/widget/wimagestore.cpp +++ b/src/widget/wimagestore.cpp @@ -1,28 +1,40 @@ #include "widget/wimagestore.h" #include +#include +#include // static QHash WImageStore::m_dictionary; QSharedPointer WImageStore::m_loader = QSharedPointer(); +// static +QImage * WImageStore::getImageNoCache(const QString& fileName) { + return getImageNoCache(PixmapSource(fileName)); +} + // static QImage * WImageStore::getImage(const QString &fileName) { + return getImage(PixmapSource(fileName)); +} + +// static +QImage * WImageStore::getImage(const PixmapSource source) { // Search for Image in list ImageInfoType* info = NULL; - QHash::iterator it = m_dictionary.find(fileName); + QHash::iterator it = m_dictionary.find(source.getId()); if (it != m_dictionary.end()) { info = it.value(); info->instCount++; - //qDebug() << "WImageStore returning cached Image for:" << fileName; + //qDebug() << "WImageStore returning cached Image for:" << source.getPath(); return info->image; } // Image wasn't found, construct it - //qDebug() << "WImageStore Loading Image from file" << fileName; + //qDebug() << "WImageStore Loading Image from file" << source.getPath(); - QImage* loadedImage = getImageNoCache(fileName); + QImage* loadedImage = getImageNoCache(source.getPath()); if (loadedImage == NULL) { return NULL; @@ -30,7 +42,7 @@ QImage * WImageStore::getImage(const QString &fileName) { if (loadedImage->isNull()) { - qDebug() << "WImageStore couldn't load:" << fileName << (loadedImage == NULL); + qDebug() << "WImageStore couldn't load:" << source.getPath() << (loadedImage == NULL); delete loadedImage; return NULL; } @@ -38,17 +50,32 @@ QImage * WImageStore::getImage(const QString &fileName) { info = new ImageInfoType; info->image = loadedImage; info->instCount = 1; - m_dictionary.insert(fileName, info); + m_dictionary.insert(source.getId(), info); return info->image; } +/**/ // static -QImage * WImageStore::getImageNoCache(const QString& fileName) { +QImage * WImageStore::getImageNoCache(const PixmapSource source) { QImage* pImage; - if (m_loader) { - pImage = m_loader->getImage(fileName); + if (source.isSVG()) { + QScopedPointer pSvgRenderer(new QSvgRenderer()); + if( source.getData().isEmpty() ){ + pSvgRenderer->load(source.getPath()); + } else { + pSvgRenderer->load(source.getData()); + } + + pImage = new QImage(pSvgRenderer->defaultSize(), QImage::Format_ARGB32); + pImage->fill(0x00000000); // Transparent black. + QPainter painter(pImage); + pSvgRenderer->render(&painter); } else { - pImage = new QImage(fileName); + if (m_loader) { + pImage = m_loader->getImage(source.getPath()); + } else { + pImage = new QImage(source.getPath()); + } } return pImage; } diff --git a/src/widget/wimagestore.h b/src/widget/wimagestore.h index 55c9ab6f93a1..376579a2b9ca 100644 --- a/src/widget/wimagestore.h +++ b/src/widget/wimagestore.h @@ -6,6 +6,7 @@ #include #include "skin/imgsource.h" +#include "skin/pixmapsource.h" class QImage; @@ -13,6 +14,8 @@ class WImageStore { public: static QImage* getImage(const QString &fileName); static QImage* getImageNoCache(const QString &fileName); + static QImage* getImage(const PixmapSource source); + static QImage* getImageNoCache(const PixmapSource source); static void deleteImage(QImage* p); static void setLoader(QSharedPointer ld); // For external owned images like software generated ones. diff --git a/src/widget/wspinny.cpp b/src/widget/wspinny.cpp index 56cbb3566821..dd62f041ae07 100644 --- a/src/widget/wspinny.cpp +++ b/src/widget/wspinny.cpp @@ -121,13 +121,16 @@ void WSpinny::onVinylSignalQualityUpdate(const VinylSignalQualityReport& report) void WSpinny::setup(QDomNode node, const SkinContext& context, QString group) { m_group = group; - + + + // todo (jclaveau) : parse svg with svgParser here + // Set images - m_pBgImage = WImageStore::getImage(context.getPixmapPath( + m_pBgImage = WImageStore::getImage(context.getPixmapSource( context.selectNode(node, "PathBackground"))); - m_pFgImage = WImageStore::getImage(context.getPixmapPath( + m_pFgImage = WImageStore::getImage(context.getPixmapSource( context.selectNode(node,"PathForeground"))); - m_pGhostImage = WImageStore::getImage(context.getPixmapPath( + m_pGhostImage = WImageStore::getImage(context.getPixmapSource( context.selectNode(node,"PathGhost"))); if (m_pBgImage && !m_pBgImage->isNull()) { setFixedSize(m_pBgImage->size()); From 2eba3d6f34dc61bbc727fe467e74e96a07438939 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 14:39:43 +0100 Subject: [PATCH 85/90] no more use of getPixmapPath --- src/widget/weffectpushbutton.cpp | 41 +++++++++++++++++--------------- src/widget/weffectpushbutton.h | 4 ++-- src/widget/wspinny.cpp | 3 --- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/widget/weffectpushbutton.cpp b/src/widget/weffectpushbutton.cpp index f61bf01966cb..576921a84008 100644 --- a/src/widget/weffectpushbutton.cpp +++ b/src/widget/weffectpushbutton.cpp @@ -43,9 +43,9 @@ void WEffectPushButton::setup(QDomNode node, const SkinContext& context) { if (context.hasNode(node, "BackPath")) { QString mode_str = context.selectAttributeString( context.selectElement(node, "BackPath"), "scalemode", "TILE"); - QString backPath = context.getPixmapPath(context.selectNode(node, "BackPath")); - if (!backPath.isEmpty()) { - setPixmapBackground(backPath, Paintable::DrawModeFromString(mode_str)); + PixmapSource backSource = context.getPixmapSource(context.selectNode(node, "BackPath")); + if (!backSource.isEmpty()) { + setPixmapBackground(backSource, Paintable::DrawModeFromString(mode_str)); } } @@ -55,16 +55,16 @@ void WEffectPushButton::setup(QDomNode node, const SkinContext& context) { if (state.isElement() && state.nodeName() == "State") { int iState = context.selectInt(state, "Number"); if (iState < m_iNoStates) { - QString pixmapPath; + PixmapSource pixmapSource; - pixmapPath = context.getPixmapPath(context.selectNode(state, "Unpressed")); - if (!pixmapPath.isEmpty()) { - setPixmap(iState, false, pixmapPath); + pixmapSource = context.getPixmapSource(context.selectNode(state, "Unpressed")); + if (!pixmapSource.isEmpty()) { + setPixmap(iState, false, pixmapSource); } - pixmapPath = context.getPixmapPath(context.selectNode(state, "Pressed")); - if (!pixmapPath.isEmpty()) { - setPixmap(iState, true, pixmapPath); + pixmapSource = context.getPixmapSource(context.selectNode(state, "Pressed")); + if (!pixmapSource.isEmpty()) { + setPixmap(iState, true, pixmapSource); } m_text.replace(iState, context.selectString(state, "Text")); @@ -237,7 +237,8 @@ void WEffectPushButton::setStates(int iStates) { m_align.resize(iStates); } -void WEffectPushButton::setPixmap(int iState, bool bPressed, const QString& filename) { +void WEffectPushButton::setPixmap(int iState, bool bPressed, + const PixmapSource& source) { QVector& pixmaps = bPressed ? m_pressedPixmaps : m_unpressedPixmaps; @@ -245,13 +246,14 @@ void WEffectPushButton::setPixmap(int iState, bool bPressed, const QString& file return; } - PaintablePointer pPixmap = WPixmapStore::getPaintable(filename, + PaintablePointer pPixmap = WPixmapStore::getPaintable(source, Paintable::STRETCH); if (pPixmap.isNull() || pPixmap->isNull()) { // Only log if it looks like the user tried to specify a pixmap. - if (!filename.isEmpty()) { - qDebug() << "WEffectPushButton: Error loading pixmap:" << filename; + if (!source.isEmpty()) { + qDebug() << "WEffectPushButton: Error loading pixmap:" + << source.getPath(); } } else { // Set size of widget equal to pixmap size @@ -260,14 +262,15 @@ void WEffectPushButton::setPixmap(int iState, bool bPressed, const QString& file pixmaps.replace(iState, pPixmap); } -void WEffectPushButton::setPixmapBackground(const QString &filename, - Paintable::DrawMode mode) { +void WEffectPushButton::setPixmapBackground(const PixmapSource &source, + Paintable::DrawMode mode) { // Load background pixmap - m_pPixmapBack = WPixmapStore::getPaintable(filename, mode); - if (!filename.isEmpty() && + m_pPixmapBack = WPixmapStore::getPaintable(source, mode); + if (!source.isEmpty() && (m_pPixmapBack.isNull() || m_pPixmapBack->isNull())) { // Only log if it looks like the user tried to specify a pixmap. - qDebug() << "WEffectPushButton: Error loading background pixmap:" << filename; + qDebug() << "WEffectPushButton: Error loading background pixmap:" + << source.getPath(); } } diff --git a/src/widget/weffectpushbutton.h b/src/widget/weffectpushbutton.h index 1a51d6839e31..7ccb17dab460 100644 --- a/src/widget/weffectpushbutton.h +++ b/src/widget/weffectpushbutton.h @@ -67,11 +67,11 @@ class WEffectPushButton : public WWidget { private: // Associates a pixmap of a given state of the button with the widget - void setPixmap(int iState, bool bPressed, const QString &filename); + void setPixmap(int iState, bool bPressed, const PixmapSource &source); // Associates a background pixmap with the widget. This is only needed if // the button pixmaps contains alpha channel values. - void setPixmapBackground(const QString &filename, Paintable::DrawMode mode); + void setPixmapBackground(const PixmapSource &source, Paintable::DrawMode mode); // True, if the button is currently pressed bool m_bPressed; diff --git a/src/widget/wspinny.cpp b/src/widget/wspinny.cpp index dd62f041ae07..a39c65d1063a 100644 --- a/src/widget/wspinny.cpp +++ b/src/widget/wspinny.cpp @@ -122,9 +122,6 @@ void WSpinny::onVinylSignalQualityUpdate(const VinylSignalQualityReport& report) void WSpinny::setup(QDomNode node, const SkinContext& context, QString group) { m_group = group; - - // todo (jclaveau) : parse svg with svgParser here - // Set images m_pBgImage = WImageStore::getImage(context.getPixmapSource( context.selectNode(node, "PathBackground"))); From af513c0b7f8bc2cd789b3d2ceae1de038ee506a8 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 17:37:27 +0100 Subject: [PATCH 86/90] refs --- src/skin/svgparser.cpp | 4 ++-- src/skin/svgparser.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b6ad838db543..105cbf1768f8 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -29,7 +29,7 @@ QDomNode SvgParser::parseSvgFile(const QString& svgFileName) const { } QDomNode SvgParser::parseSvgTree(const QDomNode& svgSkinNode, - const QString sourcePath) const { + const QString& sourcePath) const { m_currentFile = sourcePath; // clone svg to don't alter xml input QDomNode svgNode = svgSkinNode.cloneNode(true); @@ -199,7 +199,7 @@ QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { return out; } -QScriptValue SvgParser::evaluateTemplateExpression(const QString expression, +QScriptValue SvgParser::evaluateTemplateExpression(const QString& expression, int lineNumber) const { QScriptValue out = m_context.evaluateScript( expression, m_currentFile, lineNumber); diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index dee15168cf7d..69b083d4d6d9 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -16,7 +16,7 @@ class SvgParser { virtual ~SvgParser(); QDomNode parseSvgTree(const QDomNode& svgSkinNode, - const QString sourcePath) const; + const QString& sourcePath) const; QDomNode parseSvgFile(const QString& svgFileName) const; QString saveToTempFile(const QDomNode& svgNode) const; QByteArray saveToQByteArray(const QDomNode& svgNode) const; @@ -25,7 +25,7 @@ class SvgParser { void scanTree(QDomNode& node) const; void parseElement(QDomNode& svgNode) const; void parseAttributes(QDomNode& node) const; - QScriptValue evaluateTemplateExpression(const QString expression, + QScriptValue evaluateTemplateExpression(const QString& expression, int lineNumber) const; mutable SkinContext m_context; From 16045cbfdb110e3f822a183b9bd2f7f61536ae37 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 17:43:28 +0100 Subject: [PATCH 87/90] getPixmapPath removal --- src/skin/skincontext.cpp | 30 ------------------------------ src/skin/skincontext.h | 1 - 2 files changed, 31 deletions(-) diff --git a/src/skin/skincontext.cpp b/src/skin/skincontext.cpp index e8497caac84c..568c1f781454 100644 --- a/src/skin/skincontext.cpp +++ b/src/skin/skincontext.cpp @@ -227,36 +227,6 @@ QString SkinContext::nodeToString(const QDomNode& node) const { return result.join(""); } - - -QString SkinContext::getPixmapPath(const QDomNode& pixmapNode) const { - QString pixmapPath, pixmapName; - const SvgParser svgParser(*this); - - if (!pixmapNode.isNull()) { - QDomNode svgNode = selectNode(pixmapNode, "svg"); - if (!svgNode.isNull()) { - // inline svg - pixmapPath = svgParser.saveToTempFile( - svgParser.parseSvgTree(svgNode, m_xmlPath) ); - } else { - // filename - pixmapName = nodeToString(pixmapNode); - if (!pixmapName.isEmpty()) { - pixmapName = getSkinPath(pixmapName); - if (pixmapName.endsWith(".svg", Qt::CaseInsensitive)) { - pixmapPath = svgParser.saveToTempFile( - svgParser.parseSvgFile(pixmapName) ); - } else { - pixmapPath = pixmapName; - } - } - } - } - - return pixmapPath; -} - PixmapSource SkinContext::getPixmapSource(const QDomNode& pixmapNode) const { PixmapSource source; diff --git a/src/skin/skincontext.h b/src/skin/skincontext.h index 4dbc5be0e8ab..664c86471cb6 100644 --- a/src/skin/skincontext.h +++ b/src/skin/skincontext.h @@ -66,7 +66,6 @@ class SkinContext { const QString& attributeName, QString defaultValue) const; QString nodeToString(const QDomNode& node) const; - QString getPixmapPath(const QDomNode& pixmapNode) const; PixmapSource getPixmapSource(const QDomNode& pixmapNode) const; QScriptValue evaluateScript(const QString& expression, From 7b497519a83a0ac2ab4d03208ade81cb5e7880d3 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 17:49:53 +0100 Subject: [PATCH 88/90] saveToTempFile removal --- src/skin/svgparser.cpp | 21 --------------------- src/skin/svgparser.h | 1 - 2 files changed, 22 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 105cbf1768f8..9b3320282c25 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -167,27 +167,6 @@ void SvgParser::parseAttributes(QDomNode& node) const { } } -QString SvgParser::saveToTempFile(const QDomNode& svgNode) const { - // TODO (jclaveau) : this method could be removed if the Spinny widget - // didn't require it. - - // Save the new svg in a temp file to use it with setPixmap - QTemporaryFile svgFile; - svgFile.setFileTemplate(QDir::temp().filePath("qt_temp.XXXXXX.svg")); - // the file will be removed before being parsed in skin if set to true - svgFile.setAutoRemove(false); - - if (svgFile.open()) { - QTextStream out(&svgFile); - svgNode.save(out, 2); - svgFile.close(); - } else { - qDebug() << "Unable to open temp file for inline svg \n"; - } - - return svgFile.fileName(); -} - QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { // TODO (jclaveau) : a way to look the svg after the parsing would be nice! QByteArray out; diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 69b083d4d6d9..58eee963ee8d 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -18,7 +18,6 @@ class SvgParser { QDomNode parseSvgTree(const QDomNode& svgSkinNode, const QString& sourcePath) const; QDomNode parseSvgFile(const QString& svgFileName) const; - QString saveToTempFile(const QDomNode& svgNode) const; QByteArray saveToQByteArray(const QDomNode& svgNode) const; private: From caea68e55bc3c52b8623f07f1fd9007114b34c4f Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 19:05:02 +0100 Subject: [PATCH 89/90] cleanup --- src/skin/svgparser.cpp | 1 - src/skin/svgparser.h | 1 - 2 files changed, 2 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index 9b3320282c25..b4be5024c371 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "skin/svgparser.h" diff --git a/src/skin/svgparser.h b/src/skin/svgparser.h index 58eee963ee8d..1c656b32554b 100644 --- a/src/skin/svgparser.h +++ b/src/skin/svgparser.h @@ -1,7 +1,6 @@ #ifndef SVGPARSER_H #define SVGPARSER_H -#include #include #include #include From d68a8c10d17a2f6be21c17d3952f5e49836fa097 Mon Sep 17 00:00:00 2001 From: Jean Claveau Date: Sun, 16 Nov 2014 20:56:35 +0100 Subject: [PATCH 90/90] segfault fix --- src/skin/svgparser.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/skin/svgparser.cpp b/src/skin/svgparser.cpp index b4be5024c371..d0fc25018a4e 100644 --- a/src/skin/svgparser.cpp +++ b/src/skin/svgparser.cpp @@ -47,7 +47,6 @@ void SvgParser::scanTree(QDomNode& node) const { } } -// replaces Variables nodes in an svg dom tree void SvgParser::parseElement(QDomNode& node) const { QDomElement element = node.toElement(); @@ -77,7 +76,7 @@ void SvgParser::parseElement(QDomNode& node) const { value = evaluateTemplateExpression( expression, node.lineNumber() ).toString(); } else if (element.hasAttribute("name")){ - /* TODO (jclaveau) : Getting the variable fro the context or the + /* TODO (jclaveau) : Getting the variable from the context or the * script engine have the same result here (in the skin context two) * Isn't it useless? * m_context.variable(name) <=> m_scriptEngine.evaluate(name) @@ -170,10 +169,8 @@ QByteArray SvgParser::saveToQByteArray(const QDomNode& svgNode) const { // TODO (jclaveau) : a way to look the svg after the parsing would be nice! QByteArray out; QTextStream textStream(&out); - // TODO (jclaveau) : saving crashes if there are comments before - // the svg root node. Need help :D - svgNode.save(textStream, 2); - + // cloning avoid segfault during save() + svgNode.cloneNode().save(textStream, 2); return out; }