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 | var mouse = Qt.createComponent("Mouse.qml"); | 6 | var mouse = Qt.createComponent("Mouse.qml"); | ||
7 | var touch = Qt.createComponent("Touch.qml"); | ||||
7 | 8 | | |||
8 | // get classname and strip _QML of the name | 9 | // get classname and strip _QML of the name | ||
9 | function getClassName(obj) { | 10 | function getClassName(obj) { | ||
10 | var str = obj.toString(); | 11 | var str = obj.toString(); | ||
11 | str = str.substring(0, str.indexOf("(")); | 12 | str = str.substring(0, str.indexOf("(")); | ||
12 | if (str.search(/_QML/) !== -1) { | 13 | if (str.search(/_QML/) !== -1) { | ||
13 | str = str.substring(0, str.indexOf("_QML")); | 14 | str = str.substring(0, str.indexOf("_QML")); | ||
14 | } | 15 | } | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | |||||
121 | An.prototype.eq = function(n) { | 122 | An.prototype.eq = function(n) { | ||
122 | if (this.nodes.length > n) { | 123 | if (this.nodes.length > n) { | ||
123 | return new An(this.nodes[n]); | 124 | return new An(this.nodes[n]); | ||
124 | } | 125 | } | ||
125 | return new An(); | 126 | return new An(); | ||
126 | } | 127 | } | ||
127 | 128 | | |||
128 | /** | 129 | /** | ||
129 | * Drawing annotation on the nodes | 130 | * Simulate a mouse click on the nodes | ||
130 | */ | 131 | */ | ||
131 | An.prototype.click = function(obj) { | 132 | An.prototype.click = function(obj) { | ||
132 | for (var n = 0; n < this.nodes.length; n++) { | 133 | for (var n = 0; n < this.nodes.length; n++) { | ||
133 | var node = this.nodes[n]; | 134 | var node = this.nodes[n]; | ||
134 | var x = node.mapToItem(null, 0, 0).x + Math.floor(node.width / 2); | 135 | var x = node.mapToItem(null, 0, 0).x + Math.floor(node.width / 2); | ||
135 | var y = node.mapToItem(null, 0, 0).y + Math.floor(node.height / 2); | 136 | var y = node.mapToItem(null, 0, 0).y + Math.floor(node.height / 2); | ||
136 | var m = mouse.createObject(root, {px: x, py: y}); | 137 | var m = mouse.createObject(root, {px: x, py: y}); | ||
137 | m.click(); | 138 | m.click(); | ||
138 | } | 139 | } | ||
139 | return this; | 140 | return this; | ||
140 | } | 141 | } | ||
141 | 142 | | |||
143 | /** | ||||
144 | * Simulate a mouse hover on the nodes | ||||
145 | */ | ||||
146 | An.prototype.hover = function(opt) { | ||||
147 | var options = getOpts({ | ||||
148 | x: 0, | ||||
149 | y: 0 | ||||
150 | }, opt); | ||||
151 | | ||||
152 | for (var n = 0; n < this.nodes.length; n++) { | ||||
153 | var node = this.nodes[n]; | ||||
154 | var x = node.mapToItem(null, 0, 0).x + Math.floor(node.width / 2) + options.x; | ||||
155 | var y = node.mapToItem(null, 0, 0).y + Math.floor(node.height / 2) + options.y; | ||||
156 | var m = mouse.createObject(root, {px: x, py: y}); | ||||
157 | m.hover(); | ||||
158 | } | ||||
159 | return this; | ||||
160 | } | ||||
161 | | ||||
162 | /** | ||||
163 | * Simulate a touch | ||||
164 | */ | ||||
165 | An.prototype.swipe = function(obj) { | ||||
166 | for (var n = 0; n < this.nodes.length; n++) { | ||||
167 | var node = this.nodes[n]; | ||||
168 | var x = node.mapToItem(null, 0, 0).x + Math.floor(node.width / 2) + obj.fromX; | ||||
169 | var y = node.mapToItem(null, 0, 0).y + Math.floor(node.height / 2) - Kirigami.Units.iconSizes.smallMedium / 2 + obj.fromY; | ||||
170 | var t = touch.createObject(root, {fromX: x, fromY: y, toX: x + obj.toX, toY: y + obj.toY}); | ||||
171 | t.swipe(); | ||||
172 | } | ||||
173 | return this; | ||||
174 | } | ||||
142 | 175 | | |||
143 | /** | 176 | /** | ||
144 | * Draw a tree of all the elements | 177 | * Draw a tree of all the elements | ||
145 | */ | 178 | */ | ||
146 | An.prototype.tree = function(lvl) { | 179 | An.prototype.tree = function(lvl) { | ||
147 | if (typeof lvl === "undefined") { | 180 | if (typeof lvl === "undefined") { | ||
148 | lvl = "" | 181 | lvl = "" | ||
149 | } | 182 | } | ||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |