main.qml 5.6 KB

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