main.qml 13 KB

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