main.qml 14 KB

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