diff options
| author | Jens Bache-Wiig <jens.bache-wiig@nokia.com> | 2010-10-19 17:30:18 +0200 |
|---|---|---|
| committer | Jens Bache-Wiig <jens.bache-wiig@nokia.com> | 2010-10-19 17:35:19 +0200 |
| commit | 0bce1e8213dcc16357f8e20c479a4c8de990069e (patch) | |
| tree | 91603c14644d5f71afb44d77fe846aa685cdfdfc | |
| parent | 9359df776b77abac95494034eb094ad76dd826eb (diff) | |
Modified script to use hex-values instead of Qt.rgba colors
This seems more friendly to designers and more
common in general.
| -rw-r--r-- | Export QML.jsx | 69 | ||||
| -rw-r--r-- | example_output/MyElement.qml | 166 | ||||
| -rw-r--r-- | example_output/images/background.png | bin | 55513 -> 61692 bytes |
3 files changed, 139 insertions, 96 deletions
diff --git a/Export QML.jsx b/Export QML.jsx index 0b2403e..d021d19 100644 --- a/Export QML.jsx +++ b/Export QML.jsx @@ -54,9 +54,52 @@ var rasterizeKey = 2; main(); +function hexValue(dec) +{ + var result; + switch (dec) { + case 10: + result = "a"; + break; + case 11: + result = "b" + break; + case 12: + result = "c"; + break; + case 13: + result = "d"; + break; + case 14: + result = "e" + case 15: + result = "f" + break; + default: + result = dec + break; + } + return result; +} + // Converts SolidColor to a QML color property function qtColor(color) { - return "Qt.rgba(" + color.rgb.red + "," + color.rgb.green + "," + color.rgb.blue + ", 1.0)"; + var r = Math.floor(color.rgb.red) + var g = Math.floor(color.rgb.green); + var b = Math.floor(color.rgb.blue) + var a = Math.floor(color.rgb.alpha * 255) + var v1 = hexValue(Math.floor(r / 16)); + var v2 = hexValue(r % 16); + var v3 = hexValue(Math.floor(g / 16)); + var v4 = hexValue(g % 16); + var v5 = hexValue(Math.floor(b / 16)); + var v6 = hexValue(b % 16); + if (a > 0) { + var v7 = hexValue(Math.floor(a / 16)); + var v8 = hexValue(a % 16); + return "\"#" + v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + "\""; + } + return "\"#" + v1 + v2 + v3 + v4 + v5 + v6 + "\""; } function main() { @@ -231,38 +274,38 @@ function exportChildren(dupObj, orgObj, exportInfo, dupDocRef, fileNamePrefix) { if (isText) qmlfile.write(" Text {\n"); else qmlfile.write(" Image {\n"); var filename = fileNameBody + ".png"; - qmlfile.write(" id:" + fileNameBody + "\n"); + qmlfile.write(" id: " + fileNameBody + "\n"); var xoffset = currentLayer.bounds[0].as("px"); var yoffset = currentLayer.bounds[1].as("px"); if (isText) { var textItem = currentLayer.textItem; - qmlfile.write(" text:\"" + textItem.contents + "\"\n"); + qmlfile.write(" text: \"" + textItem.contents + "\"\n"); // ### Temporary hack to set font positioning // Using pointsize doesnt work for some reason and we need to // figure out which metric we need to use ascending, perhaps? yoffset -= textItem.size.as("px") / 4; - qmlfile.write(" font.pixelSize:" + Math.floor(textItem.size.as("px")) + "\n"); + qmlfile.write(" font.pixelSize: " + Math.floor(textItem.size.as("px")) + "\n"); //var fontfamily = app.textFonts.getByName(textitem.font); - qmlfile.write(" font.family:\"" + textItem.font + "\"\n"); + qmlfile.write(" font.family: \"" + textItem.font + "\"\n"); - if (textItem.font.indexOf("Bold") != -1) qmlfile.write(" font.bold:true\n"); + if (textItem.font.indexOf("Bold") != -1) qmlfile.write(" font.bold: true\n"); - if (textItem.font.indexOf("Italic") != -1) qmlfile.write(" font.italic:true\n"); + if (textItem.font.indexOf("Italic") != -1) qmlfile.write(" font.italic: true\n"); - qmlfile.write(" color:" + qtColor(currentLayer.textItem.color) + "\n"); - qmlfile.write(" smooth:true\n"); + qmlfile.write(" color: " + qtColor(currentLayer.textItem.color) + "\n"); + qmlfile.write(" smooth: true\n"); } else { - qmlfile.write(" source:\"images/" + filename + "\"\n"); + qmlfile.write(" source: \"images/" + filename + "\"\n"); } - qmlfile.write(" x:" + xoffset + "\n"); - qmlfile.write(" y:" + yoffset + "\n"); - qmlfile.write(" opacity:" + opacity + "\n"); + qmlfile.write(" x: " + xoffset + "\n"); + qmlfile.write(" y: " + yoffset + "\n"); + qmlfile.write(" opacity: " + opacity + "\n"); qmlfile.write(" }\n"); // Save document diff --git a/example_output/MyElement.qml b/example_output/MyElement.qml index 521db9b..18b20ef 100644 --- a/example_output/MyElement.qml +++ b/example_output/MyElement.qml @@ -3,116 +3,116 @@ Rectangle { width:400 height:255 Image { - id:background - source:"images/background.png" - x:-2 - y:0 - opacity:1 + id: background + source: "images/background.png" + x: -2 + y: 0 + opacity: 1 } Image { - id:new_layer_1 - source:"images/new_layer_1.png" - x:1 - y:64 - opacity:0.2 + id: new_layer_1 + source: "images/new_layer_1.png" + x: 1 + y: 64 + opacity: 0.2 } Image { - id:new_layer - source:"images/new_layer.png" - x:63 - y:161 - opacity:1 + id: new_layer + source: "images/new_layer.png" + x: 63 + y: 161 + opacity: 1 } Image { - id:new_layer_copy - source:"images/new_layer_copy.png" - x:136 - y:12 - opacity:1 + id: new_layer_copy + source: "images/new_layer_copy.png" + x: 136 + y: 12 + opacity: 1 } Text { - id:push_me - text:"Push me" - font.pixelSize:22 - font.family:"Tahoma" - color:Qt.rgba(255,255,255, 1.0) - smooth:true - x:164 - y:17.5 - opacity:1 + id: push_me + text: "Push me" + font.pixelSize: 22 + font.family: "Tahoma" + color: "#ffffff" + smooth: true + x: 164 + y: 17.5 + opacity: 1 } Image { - id:drop_shadow_2 - source:"images/drop_shadow_2.png" - x:22 - y:75 - opacity:0.3843137254902 + id: drop_shadow_2 + source: "images/drop_shadow_2.png" + x: 22 + y: 75 + opacity: 0.3843137254902 } Image { - id:background_text - source:"images/background_text.png" - x:24 - y:77 - opacity:1 + id: background_text + source: "images/background_text.png" + x: 24 + y: 77 + opacity: 1 } Image { - id:drop_shadow_1 - source:"images/drop_shadow_1.png" - x:296 - y:158 - opacity:0.8 + id: drop_shadow_1 + source: "images/drop_shadow_1.png" + x: 296 + y: 158 + opacity: 0.8 } Image { - id:mybutton - source:"images/mybutton.png" - x:309 - y:168 - opacity:1 + id: mybutton + source: "images/mybutton.png" + x: 309 + y: 168 + opacity: 1 } Image { - id:new_layer_copy_1 - source:"images/new_layer_copy_1.png" - x:116 - y:145 - opacity:0.63921568627451 + id: new_layer_copy_1 + source: "images/new_layer_copy_1.png" + x: 116 + y: 145 + opacity: 0.63921568627451 } Image { - id:drop_shadow - source:"images/drop_shadow.png" - x:139 - y:112 - opacity:0.8 + id: drop_shadow + source: "images/drop_shadow.png" + x: 139 + y: 112 + opacity: 0.8 } Image { - id:new_layer_copy_2 - source:"images/new_layer_copy_2.png" - x:159 - y:121 - opacity:0.63921568627451 + id: new_layer_copy_2 + source: "images/new_layer_copy_2.png" + x: 159 + y: 121 + opacity: 0.63921568627451 } Image { - id:drop_shadow_3 - source:"images/drop_shadow_3.png" - x:315 - y:194 - opacity:0.57254901960784 + id: drop_shadow_3 + source: "images/drop_shadow_3.png" + x: 315 + y: 194 + opacity: 0.57254901960784 } Text { - id:button - text:"Button" - font.pixelSize:30 - font.family:"Tahoma" - color:Qt.rgba(255,255,255, 1.0) - smooth:true - x:187 - y:128.5 - opacity:1 + id: button + text: "Button" + font.pixelSize: 30 + font.family: "Tahoma" + color: "#ffffff" + smooth: true + x: 187 + y: 128.5 + opacity: 1 } Image { - id:qml - source:"images/qml.png" - x:319 - y:197 - opacity:1 + id: qml + source: "images/qml.png" + x: 319 + y: 197 + opacity: 1 } } diff --git a/example_output/images/background.png b/example_output/images/background.png Binary files differindex 12e2dee..0e89eef 100644 --- a/example_output/images/background.png +++ b/example_output/images/background.png |
