main.qml 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. import QtWebSockets 1.0
  4. import "./simplify.js" as Simplify
  5. ApplicationWindow {
  6. id: aw
  7. visible: true
  8. width: 800
  9. height: 480
  10. title: qsTr("Hello World")
  11. color: "#fffffe"
  12. WebSocket {
  13. id: socket
  14. url: "wss://ws.especificosba.com.ar"
  15. onTextMessageReceived: {
  16. console.log("\nReceived message: " + message)
  17. }
  18. onStatusChanged: if (socket.status == WebSocket.Error) {
  19. console.log("Error: " + socket.errorString)
  20. } else if (socket.status == WebSocket.Open) {
  21. socket.sendTextMessage("Hello World")
  22. } else if (socket.status == WebSocket.Closed) {
  23. console.log("\nSocket closed")
  24. }
  25. active: true
  26. }
  27. Item {
  28. id: item1
  29. width: parent.width
  30. height: parent.height
  31. //property alias gridLayout1: gridLayout1
  32. property alias button4: button4
  33. property alias mouseArea1: mouseArea1
  34. property alias button2: button2
  35. property alias button3: button3
  36. property alias button1: button1
  37. property int curImage: 1
  38. anchors.fill: parent
  39. onCurImageChanged: {
  40. canvas.change_image("EBA", curImage)
  41. }
  42. Grid {
  43. id: grid1
  44. width: parent.width
  45. height: parent.height
  46. anchors.right: parent.right
  47. anchors.bottom: parent.bottom
  48. anchors.top: parent.top
  49. anchors.left: parent.left
  50. columns: 4
  51. spacing: 4
  52. Rectangle {
  53. id: canvasCol
  54. height: parent.height
  55. width: height*4/3
  56. color: aw.color
  57. Canvas {
  58. id: canvas
  59. antialiasing: true
  60. renderTarget: Canvas.Image
  61. property color strokeStyle: Qt.darker(fillStyle, 1.2)
  62. property color fillStyle: "#6400aa"
  63. property int lineWidth: 2
  64. property real px: width / 2
  65. property real py: height / 2 + 10
  66. property real alpha: 1.0
  67. property variant points_array: []
  68. property string curImageUrl: "https://plataforma.especificosba.com.ar/diapo/EBA/1.png"
  69. width: parent.width
  70. height: parent.height
  71. onPaint: paint_canvas()
  72. onLineWidthChanged: requestPaint()
  73. onImageLoaded: {
  74. clean_path()
  75. requestPaint()
  76. }
  77. function clean_path() {
  78. points_array = []
  79. requestPaint()
  80. //ws.send()..
  81. }
  82. function start_path() {
  83. points_array.push([])
  84. }
  85. function finish_path() {
  86. points_array[points_array.length - 1] = Simplify.simplify(
  87. points_array[points_array.length - 1], 3)
  88. requestPaint()
  89. //ws.send()..
  90. }
  91. function change_image(pdf, number) {
  92. curImageUrl = "https://plataforma.especificosba.com.ar/diapo/"
  93. + pdf + "/" + number + ".png"
  94. requestPaint()
  95. }
  96. function add_point(p) {
  97. points_array[points_array.length - 1].push(p)
  98. requestPaint()
  99. }
  100. function paint_canvas() {
  101. var curColor = '#ff0000'
  102. var ctx = canvas.getContext("2d")
  103. canvas.loadImage(curImageUrl)
  104. if (canvas.isImageLoaded(curImageUrl)) {
  105. ctx.drawImage(curImageUrl, 0, 0, canvas.width,
  106. canvas.height)
  107. }
  108. ctx.lineCap = 'square'
  109. ctx.lineWidth = 2
  110. ctx.strokeStyle = curColor
  111. ctx.beginPath()
  112. var i = 0, j = 0
  113. for (j = 0; j < points_array.length; j++) {
  114. var points = points_array[j]
  115. ctx.moveTo(points[0].x, points[0].y)
  116. for (i = 0; i < points.length - 1; i++) {
  117. ctx.moveTo(points[i].x, points[i].y)
  118. ctx.lineTo(points[i + 1].x, points[i + 1].y)
  119. }
  120. }
  121. ctx.stroke()
  122. }
  123. }
  124. MouseArea {
  125. id: mouseArea1
  126. x: 0
  127. y: 0
  128. width: canvas.width
  129. height: canvas.height
  130. onPressed: {
  131. if (!socket.active)
  132. return
  133. canvas.start_path()
  134. }
  135. onPositionChanged: {
  136. if (!socket.active)
  137. return
  138. canvas.add_point({
  139. x: mouse.x,
  140. y: mouse.y
  141. })
  142. }
  143. onReleased: {
  144. if (!socket.active)
  145. return
  146. canvas.finish_path()
  147. }
  148. }
  149. }
  150. Column {
  151. id: columnLayout1
  152. spacing: 15
  153. width: parent.width - canvasCol.width - parent.spacing*2
  154. Button {
  155. width:parent.width
  156. height:80
  157. id: button2
  158. text: qsTr("Anterior")
  159. enabled: socket.active
  160. onClicked: item1.curImage = Math.max(item1.curImage - 1, 1)
  161. }
  162. Button {
  163. height:80
  164. width:parent.width
  165. id: button1
  166. text: qsTr("Siguiente")
  167. enabled: socket.active
  168. onClicked: item1.curImage = Math.min(item1.curImage + 1, 5)
  169. }
  170. Button {
  171. height:80
  172. width:parent.width
  173. id: button4
  174. text: qsTr("Limpiar")
  175. enabled: socket.active
  176. onClicked: canvas.clean_path()
  177. }
  178. Button {
  179. height:80
  180. width:parent.width
  181. id: button3
  182. text: qsTr("Break")
  183. isDefault: false
  184. checkable: false
  185. onClicked: canvas.paint_canvas()
  186. }
  187. }
  188. }
  189. }
  190. }