Changeset View
Changeset View
Standalone View
Standalone View
source/qml/lib/annotate.js
| 1 | var ruler = Qt.createComponent("Ruler.qml"); | 1 | var ruler = Qt.createComponent("Ruler.qml"); | ||
|---|---|---|---|---|---|
| 2 | var brace = Qt.createComponent("Brace.qml"); | 2 | var brace = Qt.createComponent("Brace.qml"); | ||
| 3 | var outline = Qt.createComponent("Outline.qml"); | 3 | var outline = Qt.createComponent("Outline.qml"); | ||
| 4 | var messure = Qt.createComponent("Messure.qml"); | 4 | var messure = Qt.createComponent("Messure.qml"); | ||
| 5 | var padding = Qt.createComponent("Padding.qml"); | 5 | var padding = Qt.createComponent("Padding.qml"); | ||
| 6 | 6 | | |||
| 7 | // get classname and strip _QML of the name | 7 | // get classname and strip _QML of the name | ||
| 8 | function getClassName(obj) { | 8 | function getClassName(obj) { | ||
| 9 | var str = obj.toString(); | 9 | var str = obj.toString(); | ||
| 10 | str = str.substring(0, str.indexOf("(")); | 10 | str = str.substring(0, str.indexOf("(")); | ||
| 11 | if (str.search(/_QML/) !== -1) { | 11 | if (str.search(/_QML/) !== -1) { | ||
| 12 | str = str.substring(0, str.indexOf("_QML")); | 12 | str = str.substring(0, str.indexOf("_QML")); | ||
| 13 | } | 13 | } | ||
| 14 | return str.toLowerCase(); | 14 | return str.toLowerCase(); | ||
| 15 | } | 15 | } | ||
| 16 | 16 | | |||
| 17 | // Merge 2 objects of options | ||||
| 18 | function getOpts(opts, choices) { | ||||
| 19 | for (var choice in choices) { | ||||
| 20 | opts[choice] = choices[choice]; | ||||
| 21 | } | ||||
| 22 | return opts; | ||||
| 23 | } | ||||
| 24 | | ||||
| 17 | // An extended array of QML elements | 25 | // An extended array of QML elements | ||
| 18 | function An(node) { | 26 | function An(node) { | ||
| 19 | this.nodes = []; | 27 | this.nodes = []; | ||
| 20 | if (typeof node === "undefined") { | 28 | if (typeof node === "undefined") { | ||
| 21 | this.nodes = [] | 29 | this.nodes = [] | ||
| 22 | } | 30 | } | ||
| 23 | else if (typeof node === "Array") { | 31 | else if (typeof node === "Array") { | ||
| 24 | this.nodes = node; | 32 | this.nodes = node; | ||
| ▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Line(s) | |||||
| 160 | */ | 168 | */ | ||
| 161 | An.prototype._draw = function(node, type, opt) { | 169 | An.prototype._draw = function(node, type, opt) { | ||
| 162 | //console.log("drawing " + type) | 170 | //console.log("drawing " + type) | ||
| 163 | switch (type) { | 171 | switch (type) { | ||
| 164 | case "outline": | 172 | case "outline": | ||
| 165 | outline.createObject(root, {item: node, label: opt.label, aspectratio: opt.aspectratio}); | 173 | outline.createObject(root, {item: node, label: opt.label, aspectratio: opt.aspectratio}); | ||
| 166 | break | 174 | break | ||
| 167 | case "ruler": | 175 | case "ruler": | ||
| 168 | ruler.createObject(root, {rx: node.mapToItem(null, 0, 0).x, horizontal: false}); | 176 | var options = getOpts({ | ||
| 177 | offset: opt.horizontal ? node.mapToItem(null, 0, 0).y : node.mapToItem(null, 0, 0).x, | ||||
| 178 | horizontal: false | ||||
| 179 | }, opt); | ||||
| 180 | ruler.createObject(root, options); | ||||
| 169 | break | 181 | break | ||
| 170 | case "padding": | 182 | case "padding": | ||
| 171 | padding.createObject(root, {item: node}); | 183 | padding.createObject(root, {item: node}); | ||
| 172 | break | 184 | break | ||
| 173 | case "brace": | 185 | case "brace": | ||
| 174 | brace.createObject(root, {"from": node, "to": opt.to.nodes[0], "text": opt.text, "center": opt.center, "horizontal": opt.horizontal}); | 186 | brace.createObject(root, {"from": node, "to": opt.to.nodes[0], "text": opt.text, "center": opt.center, "horizontal": opt.horizontal}); | ||
| 175 | break | 187 | break | ||
| 176 | case "messure": | 188 | case "messure": | ||
| ▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines | |||||