main.qml 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.4
  4. import "./simplify.js" as Simplify
  5. import "components" as Comps
  6. ApplicationWindow {
  7. id: aw
  8. visible: true
  9. width: 960
  10. height: 540
  11. color: "#fffffe"
  12. Comps.WebSocket {
  13. id: socket
  14. }
  15. property alias t_slides: socket.tot_slides
  16. Item {
  17. id: item1
  18. width: parent.width
  19. height: parent.height
  20. property alias mouseArea1: mouseArea1
  21. property alias button3: button3
  22. property int curImage: 1
  23. property variant pregs: []
  24. property string curPDF: "EBA"
  25. anchors.fill: parent
  26. onCurPDFChanged: {
  27. canvas.change_image(curPDF, curImage)
  28. diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
  29. t_slides).arg(pregs.length)
  30. }
  31. onPregsChanged: {
  32. diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
  33. t_slides).arg(pregs.length)
  34. }
  35. onCurImageChanged: {
  36. canvas.change_image(curPDF, curImage)
  37. diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
  38. t_slides).arg(pregs.length)
  39. }
  40. function addPreg(p) {
  41. if (pregs.indexOf(p) !== -1) {
  42. return
  43. }
  44. pregs.push(p)
  45. curImageChanged();
  46. }
  47. Grid {
  48. id: grid1
  49. width: parent.width
  50. height: parent.height
  51. anchors.right: parent.right
  52. anchors.bottom: parent.bottom
  53. anchors.top: parent.top
  54. anchors.left: parent.left
  55. columns: 4
  56. spacing: 4
  57. Rectangle {
  58. id: canvasCol
  59. height: parent.height
  60. width: height * 4 / 3
  61. color: aw.color
  62. Canvas {
  63. id: canvas
  64. antialiasing: false
  65. renderTarget: Canvas.Image
  66. renderStrategy: Canvas.Immediate
  67. property color strokeStyle: Qt.darker(fillStyle, 1.2)
  68. property color fillStyle: "#6400aa"
  69. property string curColor: "#ff0000"
  70. property real px: width / 2
  71. property real py: height / 2 + 10
  72. property real alpha: 1.0
  73. property variant points_array: []
  74. property string curImageUrl: "https://plataforma.especificosba.com.ar/diapo/EBA/1.png"
  75. property var ctx : null
  76. width: parent.width
  77. height: parent.height
  78. onPaint: full_repaint()
  79. //paint_canvas()
  80. onImageLoaded: {
  81. clean_path()
  82. if (ctx === null)
  83. ctx = canvas.getContext("2d");
  84. ctx.lineCap = 'square'
  85. ctx.lineWidth = 4
  86. full_repaint()
  87. }
  88. function clean_path() {
  89. points_array.length=0
  90. full_repaint()
  91. }
  92. function start_path() {
  93. points_array.push({
  94. points: [],
  95. color: curColor
  96. })
  97. }
  98. function normalizeTo800by600(point) {
  99. return {
  100. x: Math.round(
  101. point.x * 800 / canvas.width),
  102. y: Math.round(
  103. point.y * 600 / canvas.height)
  104. }
  105. }
  106. function change_image(pdf, number) {
  107. curImageUrl = "https://plataforma.especificosba.com.ar/diapo/"
  108. + pdf + "/" + number + ".png"
  109. canvas.loadImage(curImageUrl)
  110. }
  111. function add_point(p) {
  112. var pts = points_array[points_array.length - 1].points
  113. var lastpoint;
  114. if (pts.length>1)
  115. lastpoint = pts[pts.length-1];
  116. pts.push(p)
  117. socket.send_point(p);
  118. if (lastpoint)
  119. markDirty(Qt.rect(Math.min(p.x,lastpoint.x),Math.min(p.y,lastpoint.y), Math.abs(p.x-lastpoint.x)+4, Math.abs(p.y-lastpoint.y)+1))
  120. }
  121. function stroke(points, color) {
  122. if (points.length===0)
  123. return;
  124. if (ctx.strokeStyle !== color){
  125. ctx.strokeStyle = color;
  126. }
  127. ctx.beginPath()
  128. ctx.moveTo(points[0].x, points[0].y)
  129. var i = 0;
  130. for (i = 0; i < points.length - 1; i++) {
  131. ctx.moveTo(points[i].x, points[i].y)
  132. ctx.lineTo(points[i + 1].x, points[i + 1].y)
  133. }
  134. ctx.stroke()
  135. }
  136. function full_repaint(){
  137. //console.log("Fullpaint")
  138. if (ctx === null )
  139. ctx = canvas.getContext("2d");
  140. if (canvas.isImageLoaded(curImageUrl)) {
  141. ctx.drawImage(curImageUrl, 0, 0, canvas.width,
  142. canvas.height)
  143. }
  144. var j = 0
  145. for (j = 0; j < points_array.length; j++) {
  146. if (points_array[j].points.length <= 1)
  147. continue
  148. stroke(points_array[j].points,points_array[j].color);
  149. }
  150. requestPaint()
  151. }
  152. function paint_canvas() {
  153. if (ctx === null )
  154. ctx = canvas.getContext("2d");
  155. if (points_array.length === 0)
  156. return;
  157. var ar = points_array[points_array.length -1];
  158. stroke(ar.points,ar.color);
  159. }
  160. }
  161. MouseArea {
  162. id: mouseArea1
  163. x: 0
  164. y:0
  165. width: canvas.width
  166. height: canvas.height
  167. property var last_point;
  168. onPressed: {
  169. if (!socket.isOpen)
  170. return
  171. canvas.start_path()
  172. last_point = { x: mouse.x, y: mouse.y }
  173. canvas.add_point(last_point)
  174. }
  175. onPositionChanged: {
  176. if (!socket.isOpen)
  177. return
  178. var point = { x: mouse.x, y: mouse.y }
  179. if (distance(last_point, point) <= 61) //distance returns squared dsitance
  180. return;
  181. last_point = point
  182. canvas.add_point(point)
  183. }
  184. onReleased: {
  185. if (!socket.isOpen)
  186. return
  187. socket.finish_path()
  188. }
  189. function distance(p1,p2){
  190. return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)
  191. }
  192. }
  193. }
  194. Column {
  195. id: columnLayout1
  196. spacing: 10
  197. width: parent.width - canvasCol.width - parent.spacing * 2
  198. height: parent.height
  199. Column {
  200. width: parent.width
  201. height: parent.height / 2 - 60
  202. Row {
  203. id: row2
  204. width: parent.width
  205. height: 70
  206. MouseArea {
  207. id: image1
  208. width: parent.width/2
  209. height: 70
  210. Image {
  211. anchors.centerIn: parent.Center
  212. source: "qrc:///images/back.png"
  213. height: parent.height
  214. fillMode: Image.PreserveAspectFit
  215. }
  216. enabled: socket.isOpen && (item1.curImage > 1)
  217. onClicked : socket.prev_diapo()
  218. }
  219. MouseArea {
  220. id: image2
  221. width: parent.width/2
  222. height: 70
  223. Image {
  224. anchors.centerIn: parent.Center
  225. height: parent.height
  226. source: "qrc:///images/fwd.png"
  227. fillMode: Image.PreserveAspectFit
  228. }
  229. enabled: socket.isOpen && (item1.curImage < t_slides)
  230. onClicked: socket.next_diapo()
  231. }
  232. }
  233. Row {
  234. id: row1
  235. width: parent.width
  236. height: 70
  237. Button {
  238. height: 70
  239. width: parent.width / 2
  240. id: preg
  241. text: qsTr("Preg")
  242. onClicked: {
  243. socket.set_preg()
  244. }
  245. }
  246. Button {
  247. height: 70
  248. width: parent.width / 2
  249. id: nopreg
  250. text: qsTr("No Preg")
  251. onClicked: {
  252. socket.unset_preg()
  253. }
  254. }
  255. }
  256. }
  257. Column {
  258. id: column1
  259. width: parent.width
  260. height: parent.height / 2 - 60
  261. Repeater{
  262. model: [ ["#0000ff", "#00ff00", "#ff0000"], ["#ffff00", "#00ffff", "#000000"] ]
  263. Row {
  264. width: parent.width
  265. height: 70
  266. Repeater {
  267. model: modelData
  268. Button {
  269. height: 70
  270. width: parent.width/3
  271. checkable: true
  272. checked: canvas.curColor === modelData
  273. onClicked: canvas.curColor = modelData
  274. style: ButtonStyle {
  275. background: Rectangle {
  276. implicitWidth: 100
  277. implicitHeight: 25
  278. border.width: 3
  279. border.color: canvas.curColor === modelData ?"#000":"#FFF"
  280. radius: 8
  281. gradient: Gradient {
  282. GradientStop { position: 0 ; color: modelData }
  283. GradientStop { position: 1 ; color: modelData }
  284. }
  285. }
  286. }
  287. }
  288. }
  289. }
  290. }
  291. Button {
  292. height: 70
  293. width: parent.width
  294. id: button3
  295. text: qsTr("Limpiar")
  296. enabled: socket.isOpen
  297. onClicked: {
  298. canvas.clean_path();
  299. socket.clear_path();
  300. }
  301. }
  302. Text {
  303. id: wsStatus
  304. text: qsTr("WS Status")
  305. }
  306. Text {
  307. id: diapoStatus
  308. text: qsTr("Diapo status")
  309. }
  310. }
  311. }
  312. }
  313. }
  314. }