main.qml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. import QtQuick 2.5
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Controls.Styles 1.4
  4. import QtQuick.Dialogs 1.1
  5. import QtQuick.Window 2.2
  6. import "components" as Comps
  7. ApplicationWindow {
  8. id: aw
  9. visible: true
  10. width: 600
  11. height: 960
  12. visibility: Screen.height > Screen.width ? "FullScreen" : "Windowed"
  13. color: "#fffffe"
  14. Comps.WebSocket {
  15. id: socket
  16. }
  17. property alias t_slides: socket.tot_slides
  18. Item {
  19. id: item1
  20. transformOrigin: Item.Center
  21. rotation: Screen.height > Screen.width ? 90 : 0
  22. property alias mouseArea1: mouseArea1
  23. property alias button3: button3
  24. property int curImage: 1
  25. property variant pregs: []
  26. property string curPDF: "EBA"
  27. width: parent.height
  28. height: parent.width
  29. anchors.horizontalCenter: parent.horizontalCenter
  30. anchors.verticalCenter: parent.verticalCenter
  31. onCurPDFChanged: {
  32. canvas.change_image(curPDF, curImage)
  33. diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
  34. t_slides).arg(pregs.length)
  35. }
  36. onPregsChanged: {
  37. diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
  38. t_slides).arg(pregs.length)
  39. }
  40. onCurImageChanged: {
  41. canvas.change_image(curPDF, curImage)
  42. diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
  43. t_slides).arg(pregs.length)
  44. }
  45. function addPreg(p) {
  46. if (pregs.indexOf(p) !== -1) {
  47. return
  48. }
  49. pregs.push(p)
  50. curImageChanged();
  51. }
  52. Grid {
  53. id: grid1
  54. width: parent.width
  55. height: parent.height
  56. columns: 4
  57. spacing: 4
  58. Rectangle {
  59. id: canvasCol
  60. height: grid1.height
  61. width: Screen.height > Screen.width ? grid1.width *3/4 : grid1.width/2
  62. color: "#333"
  63. smooth: false
  64. //aw.color
  65. Canvas {
  66. id: canvas
  67. antialiasing: false
  68. renderTarget: Canvas.Image
  69. renderStrategy: Canvas.Immediate
  70. property color strokeStyle: Qt.darker(fillStyle, 1.2)
  71. property color fillStyle: "#6400aa"
  72. property string curColor: "#ff0000"
  73. property real px: width / 2
  74. property real py: height / 2 + 10
  75. property real alpha: 1.0
  76. property variant points_array: []
  77. property string curImageUrl: "https://plataforma.especificosba.com.ar/diapo/EBA/1.png"
  78. property var ctx : null
  79. width: parent.width
  80. height: parent.height
  81. onPaint: full_repaint(region)
  82. onImageLoaded: {
  83. clean_path()
  84. if (ctx === null)
  85. ctx = canvas.getContext("2d");
  86. ctx.lineCap = 'square'
  87. ctx.lineWidth = 4
  88. requestPaint()
  89. }
  90. function clean_path() {
  91. points_array.length=0
  92. requestPaint()
  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)+4));
  122. }
  123. }
  124. function stroke(points, color) {
  125. if (points.length===0)
  126. return;
  127. if (ctx.strokeStyle !== color){
  128. ctx.strokeStyle = color;
  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(region){
  140. if (ctx === null )
  141. ctx = canvas.getContext("2d");
  142. if ( region === undefined || region.width > 150 || region.height > 150 ) {
  143. console.log("Full", region.width, region.height);
  144. if (canvas.isImageLoaded(curImageUrl)) {
  145. ctx.drawImage(curImageUrl, 0, 0, canvas.width,
  146. canvas.height)
  147. }
  148. var j = 0
  149. for (j = 0; j < points_array.length; j++) {
  150. if (points_array[j].points.length <= 1)
  151. continue
  152. stroke(points_array[j].points,points_array[j].color);
  153. }
  154. } else {
  155. var lastLine = points_array[points_array.length-1];
  156. if (lastLine === undefined)
  157. return;
  158. stroke(lastLine.points, lastLine.color);
  159. }
  160. }
  161. }
  162. MouseArea {
  163. id: mouseArea1
  164. x: 0
  165. y:0
  166. width: canvas.width
  167. height: canvas.height
  168. property var last_point;
  169. onPressed: {
  170. if (!socket.isOpen)
  171. return
  172. canvas.start_path()
  173. last_point = { x: mouse.x, y: mouse.y }
  174. canvas.add_point(last_point)
  175. }
  176. onPositionChanged: {
  177. if (!socket.isOpen)
  178. return
  179. var point = { x: mouse.x, y: mouse.y }
  180. if (distance(last_point, point) <= 61) //distance returns squared dsitance
  181. return;
  182. last_point = point
  183. canvas.add_point(point)
  184. }
  185. onReleased: {
  186. if (!socket.isOpen)
  187. return
  188. socket.finish_path()
  189. }
  190. function distance(p1,p2){
  191. return (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)
  192. }
  193. }
  194. }
  195. Column {
  196. id: columnLayout1
  197. spacing: 10
  198. width: parent.width - canvasCol.width - parent.spacing * 2
  199. height: parent.height
  200. Column {
  201. width: parent.width
  202. height: parent.height / 2 - 10
  203. Row {
  204. id: row2
  205. width: parent.width
  206. height: 120
  207. MouseArea {
  208. id: image1
  209. width: parent.width/2
  210. height: parent.height
  211. Image {
  212. anchors.centerIn: parent.Center
  213. source: "qrc:///images/back.png"
  214. height: parent.height
  215. fillMode: Image.PreserveAspectFit
  216. }
  217. enabled: socket.isOpen && (item1.curImage > 1)
  218. onClicked : socket.prev_diapo()
  219. }
  220. MouseArea {
  221. id: image2
  222. width: parent.width/2
  223. height: parent.height
  224. Image {
  225. anchors.centerIn: parent.Center
  226. height: parent.height
  227. source: "qrc:///images/fwd.png"
  228. fillMode: Image.PreserveAspectFit
  229. }
  230. enabled: socket.isOpen && (item1.curImage < t_slides)
  231. onClicked: socket.next_diapo()
  232. }
  233. }
  234. Row {
  235. id: row1
  236. width: parent.width
  237. height: 70
  238. Button {
  239. height: 70
  240. width: parent.width / 2
  241. id: preg
  242. text: qsTr("Preg")
  243. onClicked: {
  244. socket.set_preg()
  245. }
  246. }
  247. Button {
  248. height: 70
  249. width: parent.width / 2
  250. id: nopreg
  251. text: qsTr("No Preg")
  252. onClicked: {
  253. socket.unset_preg()
  254. }
  255. }
  256. }
  257. }
  258. Column {
  259. id: column1
  260. width: parent.width
  261. height: parent.height / 2 - 10
  262. spacing: 2
  263. Repeater{
  264. model: [ ["#0000ff", "#00ff00", "#ff0000"], ["#ffff00", "#00ffff", "#000000"] ]
  265. Row {
  266. width: parent.width
  267. height: 70
  268. Repeater {
  269. model: modelData
  270. Button {
  271. height: 70
  272. width: parent.width/3
  273. checkable: true
  274. checked: canvas.curColor === modelData
  275. onClicked: canvas.curColor = modelData
  276. style: ButtonStyle {
  277. background: Rectangle {
  278. implicitWidth: 100
  279. implicitHeight: 25
  280. border.width: 3
  281. border.color: canvas.curColor === modelData ?"#000":"#FFF"
  282. radius: 8
  283. gradient: Gradient {
  284. GradientStop { position: 0 ; color: modelData }
  285. GradientStop { position: 1 ; color: modelData }
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. }
  293. Button {
  294. height: 70
  295. width: parent.width
  296. id: button3
  297. text: qsTr("Limpiar")
  298. enabled: socket.isOpen
  299. onClicked: {
  300. canvas.clean_path();
  301. socket.clear_path();
  302. }
  303. }
  304. Text {
  305. id: wsStatus
  306. text: qsTr("WS Status")
  307. }
  308. Text {
  309. id: diapoStatus
  310. text: qsTr("Diapo status")
  311. }
  312. Button {
  313. id: salir
  314. width: 40
  315. height: 20
  316. text: qsTr("Salir")
  317. onClicked: {
  318. messageDialog.visible = true;
  319. }
  320. }
  321. }
  322. }
  323. }
  324. }
  325. MessageDialog {
  326. id: messageDialog
  327. title: "Salir"
  328. text: "Seguro que desea salir?"
  329. standardButtons: StandardButton.Yes | StandardButton.No
  330. icon: StandardIcon.Warning
  331. onYes: {
  332. Qt.quit()
  333. }
  334. onNo: {
  335. visible = false
  336. }
  337. }
  338. }