summaryrefslogtreecommitdiffstats
path: root/src/widget/wpushbutton.cpp
diff options
context:
space:
mode:
authorJean Claveau <jean.claveau@c277.fr>2014-07-01 11:25:47 +0200
committerJean Claveau <jean.claveau@c277.fr>2014-07-03 16:19:01 +0200
commit3cfb71a7b43f570aaf0db71c6850aa219b9dbb9b (patch)
tree28d1e4fd12b1345abc1fa0ebf481f39ebed13106 /src/widget/wpushbutton.cpp
parentd489d6f230db3429c88ae358251bc7e114c52ef4 (diff)
proof of concept inlined svg in skin with variables
Diffstat (limited to 'src/widget/wpushbutton.cpp')
-rw-r--r--src/widget/wpushbutton.cpp131
1 files changed, 127 insertions, 4 deletions
diff --git a/src/widget/wpushbutton.cpp b/src/widget/wpushbutton.cpp
index 467ace48b5..d81b4d5887 100644
--- a/src/widget/wpushbutton.cpp
+++ b/src/widget/wpushbutton.cpp
@@ -25,6 +25,7 @@
#include <QTouchEvent>
#include <QPaintEvent>
#include <QApplication>
+#include <QTemporaryFile>
#include "widget/wpixmapstore.h"
#include "controlobject.h"
@@ -73,14 +74,136 @@ void WPushButton::setup(QDomNode node, const SkinContext& context) {
int iState = context.selectInt(state, "Number");
if (iState < m_iNoStates) {
QString pixmapName;
+ QDomNode pressedNode = context.selectNode(state, "Unpressed");
+ if (!pressedNode.isNull()) {
+
+ // inline svg
+ QDomNode svgNode,
+ svgNodeTemp = context.selectNode(pressedNode, "svg");
+
+ if (!svgNodeTemp.isNull()) {
+
+ svgNode = svgNodeTemp.cloneNode( true );
+
+ QDomDocument document;
+ QDomNode parentNode = svgNode;
+ // QString parentTagName = varValueNode.parentNode().toElement().tagName();
+ while( !parentNode.isNull() ){
+ if( parentNode.isDocument() )
+ document = parentNode.toDocument();
+ parentNode = parentNode.parentNode();
+ }
+
+
+ QDomElement svgElement = svgNode.toElement();
+
+ qWarning()
+ << "SVG : SVG node present";
+
+ QDomNodeList variablesElements = svgElement.elementsByTagName( "Variable" );
+
+ qWarning()
+ << "SVG : " << variablesElements.count() << "\n";
+
+ // replace variables
+ uint variableIndex;
+ QDomElement varElement;
+ QString varName, varValue;
+ QDomNode varNode;
+ // QDomText *varValueNode;
+ QDomText varValueNode;
+ QDomNode varParentNode;
+ QDomNode oldChild;
+
+ for (variableIndex=0; variableIndex < variablesElements.length(); variableIndex++){
+
+ varNode = variablesElements.item(variableIndex);
+
+ // retrieve value
+ varElement = varNode.toElement();
+ varName = varElement.attribute("name");
+ varValue = context.variable(varName);
+
+ qWarning()
+ << "SVG : " << varName << " => " << varValue << "\n";
+
+ // replace node by its value
+ varParentNode = varNode.parentNode();
+
+ if( varParentNode.isNull() ){
+
+ qWarning()
+ << "SVG : no parent for dom node \n";
+ }
+
+ varValueNode = document.createTextNode(varValue);
+
+ // newChild = varParentNode.insertAfter( varValueNode, varNode );
+
+ oldChild = varParentNode.replaceChild( varValueNode, varNode );
+ if( oldChild.isNull() ){
+
+ qWarning()
+ << "SVG : unable to replace dom node changed. \n";
+ } else {
+
+ // varParentNode.removeChild( varNode );
+ qWarning()
+ << "SVG : " << varName << " => " << varValue << " changed. \n";
+ }
+
+
+
+
+ }
+
+ // QDomNode parentNode = varParentNode;
+ parentNode = varParentNode;
+ // QString parentTagName = varValueNode.parentNode().toElement().tagName();
+ while( !parentNode.isNull() && parentNode.toElement().tagName() != "svg" ){
+ parentNode = parentNode.parentNode();
+ }
+
+
+
+ // svgContent = "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"><rect x=\"0\" y=\"0\" width=\"12\" height=\"25\" style=\"fill:#ff0000; stroke-width:1; stroke:#ff0000; stroke-linecap:sqare;\" /></svg>";
+
+ QTemporaryFile svgFile;
+ svgFile.setAutoRemove( false );
+ svgFile.setFileTemplate("qt_temp.XXXXXX.svg");
+
+
+ if( svgFile.open() ){
+ QTextStream out(&svgFile);
+
+ parentNode.save( out, -1 );
+
+ // qWarning()
+ // << "SVG : Temp filename" << svgFile.fileName() << " \n";
+
+ svgFile.close();
+
+ setPixmap(iState, false, context.getSkinPath(svgFile.fileName()));
+ } else {
+ qWarning()
+ << "SVG : unable to open svg buffer. Enough space? \n";
+ }
+
+ } else {
+ // filename
+ pixmapName = context.nodeToString(pressedNode);
+ if (!pixmapName.isEmpty()) {
+ setPixmap(iState, false, context.getSkinPath(pixmapName));
+ }
+ }
+
+ }
+
if (context.hasNodeSelectString(state, "Pressed", &pixmapName) &&
!pixmapName.isEmpty()) {
setPixmap(iState, true, context.getSkinPath(pixmapName));
}
- if (context.hasNodeSelectString(state, "Unpressed", &pixmapName) &&
- !pixmapName.isEmpty()) {
- setPixmap(iState, false, context.getSkinPath(pixmapName));
- }
+
m_text.replace(iState, context.selectString(state, "Text"));
QString alignment = context.selectString(state, "Alignment");
if (alignment == "left") {