main.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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: true
  65. renderTarget: Canvas.Image
  66. property color strokeStyle: Qt.darker(fillStyle, 1.2)
  67. property color fillStyle: "#6400aa"
  68. property string curColor: "#ff0000"
  69. property real px: width / 2
  70. property real py: height / 2 + 10
  71. property real alpha: 1.0
  72. property variant points_array: []
  73. property string curImageUrl: "https://plataforma.especificosba.com.ar/diapo/EBA/1.png"
  74. width: parent.width
  75. height: parent.height
  76. onPaint: paint_canvas()
  77. onImageLoaded: {
  78. clean_path()
  79. requestPaint()
  80. }
  81. function clean_path() {
  82. points_array = []
  83. requestPaint()
  84. }
  85. function start_path() {
  86. points_array.push({
  87. points: [],
  88. color: curColor
  89. })
  90. }
  91. function finish_path() {
  92. points_array[points_array.length - 1].points = Simplify.simplify(
  93. points_array[points_array.length - 1].points,
  94. 2.2)
  95. requestPaint()
  96. //normalized to 800x600
  97. var ar = points_array[points_array.length - 1].points.map(
  98. function (el) {
  99. return {
  100. x: Math.round(
  101. el.x * 800 / canvas.width),
  102. y: Math.round(
  103. el.y * 600 / canvas.height)
  104. }
  105. })
  106. while (ar.length > 30) {
  107. socket.send_drawing(ar.splice(0, 29))
  108. }
  109. socket.send_drawing(ar)
  110. }
  111. function change_image(pdf, number) {
  112. curImageUrl = "https://plataforma.especificosba.com.ar/diapo/"
  113. + pdf + "/" + number + ".png"
  114. requestPaint()
  115. }
  116. function add_point(p) {
  117. var pts = points_array[points_array.length - 1].points
  118. pts.push(p)
  119. if (pts.length > 60) {
  120. //FIXME
  121. finish_path()
  122. start_path()
  123. pts.push(p)
  124. } else {
  125. requestPaint()
  126. }
  127. }
  128. function paint_canvas() {
  129. var ctx = canvas.getContext("2d")
  130. canvas.loadImage(curImageUrl)
  131. if (canvas.isImageLoaded(curImageUrl)) {
  132. ctx.drawImage(curImageUrl, 0, 0, canvas.width,
  133. canvas.height)
  134. }
  135. ctx.lineCap = 'square'
  136. ctx.lineWidth = 4
  137. ctx.strokeStyle = "#000000"
  138. var i = 0, j = 0
  139. for (j = 0; j < points_array.length; j++) {
  140. var points = points_array[j].points
  141. if (points.length === 0)
  142. continue
  143. ctx.strokeStyle = points_array[j].color
  144. ctx.beginPath()
  145. ctx.moveTo(points[0].x, points[0].y)
  146. for (i = 0; i < points.length - 1; i++) {
  147. ctx.moveTo(points[i].x, points[i].y)
  148. ctx.lineTo(points[i + 1].x, points[i + 1].y)
  149. }
  150. ctx.stroke()
  151. }
  152. }
  153. }
  154. MouseArea {
  155. id: mouseArea1
  156. x: 0
  157. y: 0
  158. width: canvas.width
  159. height: canvas.height
  160. onPressed: {
  161. if (!socket.isOpen())
  162. return
  163. canvas.start_path()
  164. }
  165. onPositionChanged: {
  166. if (!socket.isOpen())
  167. return
  168. canvas.add_point({
  169. x: mouse.x,
  170. y: mouse.y
  171. })
  172. }
  173. onReleased: {
  174. if (!socket.isOpen())
  175. return
  176. canvas.finish_path()
  177. }
  178. }
  179. }
  180. Column {
  181. id: columnLayout1
  182. spacing: 10
  183. width: parent.width - canvasCol.width - parent.spacing * 2
  184. height: parent.height
  185. Column {
  186. width: parent.width
  187. height: parent.height / 2 - 60
  188. Row {
  189. id: row2
  190. width: parent.width
  191. height: 70
  192. MouseArea {
  193. id: image1
  194. width: parent.width/2
  195. height: 70
  196. Image {
  197. source: "qrc:///images/back.png"
  198. height: parent.height
  199. fillMode: Image.PreserveAspectFit
  200. }
  201. enabled: socket.isOpen() && (item1.curImage > 1)
  202. onClicked : socket.prev_diapo()
  203. }
  204. MouseArea {
  205. id: image2
  206. width: parent.width/2
  207. height: 70
  208. Image {
  209. height: parent.height
  210. source: "qrc:///images/fwd.png"
  211. fillMode: Image.PreserveAspectFit
  212. }
  213. enabled: socket.isOpen() && (item1.curImage < t_slides)
  214. onClicked: socket.next_diapo()
  215. }
  216. }
  217. Row {
  218. id: row1
  219. width: parent.width
  220. height: 70
  221. Button {
  222. height: 70
  223. width: parent.width / 2
  224. id: preg
  225. text: qsTr("Preg")
  226. onClicked: {
  227. socket.set_preg()
  228. }
  229. }
  230. Button {
  231. height: 70
  232. width: parent.width / 2
  233. id: nopreg
  234. text: qsTr("No Preg")
  235. onClicked: {
  236. socket.unset_preg()
  237. }
  238. }
  239. }
  240. }
  241. Column {
  242. id: column1
  243. width: parent.width
  244. height: parent.height / 2 - 60
  245. Row {
  246. id: row3
  247. width: parent.width
  248. height: 70
  249. Button {
  250. height: 70
  251. width: parent.width/3
  252. id: color3
  253. checkable: true
  254. onClicked: {
  255. color1.checked = false
  256. color2.checked = false
  257. checked = true
  258. canvas.curColor = "#0000ff"
  259. }
  260. style: ButtonStyle {
  261. background: Rectangle {
  262. implicitWidth: 100
  263. implicitHeight: 25
  264. border.width: 2
  265. border.color: color3.checked?"#000":"#FFF"
  266. radius: 8
  267. gradient: Gradient {
  268. GradientStop { position: 0 ; color: "#00f" }
  269. GradientStop { position: 1 ; color: "#00f" }
  270. }
  271. }
  272. }
  273. }
  274. Button {
  275. height: 70
  276. width: parent.width/3
  277. id: color2
  278. checkable: true
  279. onClicked: {
  280. color1.checked = false
  281. color3.checked = false
  282. checked = true
  283. canvas.curColor = "#00ff00"
  284. }
  285. style: ButtonStyle {
  286. background: Rectangle {
  287. implicitWidth: 100
  288. implicitHeight: 25
  289. border.width: 2
  290. border.color: color2.checked?"#000":"#FFF"
  291. radius: 8
  292. gradient: Gradient {
  293. GradientStop { position: 0 ; color: "#0f0" }
  294. GradientStop { position: 1 ; color: "#0f0" }
  295. }
  296. }
  297. }
  298. }
  299. Button {
  300. width: parent.width/3
  301. height: 70
  302. id: color1
  303. checked: true
  304. checkable: true
  305. onClicked: {
  306. color2.checked = false
  307. color3.checked = false
  308. checked = true
  309. canvas.curColor = "#ff0000"
  310. }
  311. style: ButtonStyle {
  312. background: Rectangle {
  313. implicitWidth: 100
  314. implicitHeight: 25
  315. border.width: 2
  316. border.color: color1.checked?"#000":"#FFF"
  317. radius: 8
  318. gradient: Gradient {
  319. GradientStop { position: 0 ; color: "#f00" }
  320. GradientStop { position: 1 ; color: "#f00" }
  321. }
  322. }
  323. }
  324. }
  325. }
  326. Button {
  327. height: 70
  328. width: parent.width
  329. id: button3
  330. text: qsTr("Limpiar")
  331. enabled: socket.isOpen()
  332. onClicked: socket.clear_path()
  333. }
  334. Text {
  335. id: wsStatus
  336. text: qsTr("WS")
  337. }
  338. Text {
  339. id: diapoStatus
  340. text: qsTr("test123")
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }