David %!s(int64=10) %!d(string=hai) anos
pai
achega
289ccf2c69
Modificáronse 1 ficheiros con 55 adicións e 28 borrados
  1. 55 28
      main.qml

+ 55 - 28
main.qml

@@ -18,32 +18,52 @@ ApplicationWindow {
         url: "wss://wscasa.especificosba.com.ar"
         onTextMessageReceived: {
             console.log("\nReceived message: " + message)
-            var obj = JSON.parse(message);
-            switch(obj.type){
+            var obj = JSON.parse(message)
+            switch (obj.type) {
             case "diapo":
-                canvas.clean_path();
-                item1.curPDF=obj.PDF;
-                item1.curImage=obj.slide; //automagically change_image
-                total_slides=obj.total_slides;
+                canvas.clean_path()
+                item1.curPDF = obj.PDF
+                item1.curImage = obj.slide //automagically change_image
+                total_slides = obj.total_slides
             }
         }
-        function send_obj(obj){
-            sendTextMessage(JSON.stringify(obj));
+        function send_obj(obj) {
+            sendTextMessage(JSON.stringify(obj))
         }
 
-        function prev_diapo(){
-            var curImage= Math.max(item1.curImage - 1, 1)
-            send_obj({type:"command",commandtype:"diapo", PDF: item1.curPDF, slide: curImage});
+        function prev_diapo() {
+            var curImage = Math.max(item1.curImage - 1, 1)
+            send_obj({
+                         type: "command",
+                         commandtype: "diapo",
+                         PDF: item1.curPDF,
+                         slide: curImage
+                     })
         }
 
-        function next_diapo(){
-            var curImage= Math.min(item1.curImage + 1, total_slides)
-            send_obj({type:"command",commandtype:"diapo", PDF: item1.curPDF, slide: curImage});
+        function next_diapo() {
+            var curImage = Math.min(item1.curImage + 1, total_slides)
+            send_obj({
+                         type: "command",
+                         commandtype: "diapo",
+                         PDF: item1.curPDF,
+                         slide: curImage
+                     })
         }
-        function clear_path(){
-            send_obj({type:"clean"})
+        function clear_path() {
+            send_obj({
+                         type: "clean"
+                     })
             canvas.clean_path()
         }
+        function send_drawing(d) {
+            send_obj({
+                         type: "command",
+                         commandtype: "draw",
+                         points: d,
+                         color: canvas.curColor
+                     })
+        }
 
         onStatusChanged: if (socket.status == WebSocket.Error) {
                              console.log("Error: " + socket.errorString)
@@ -93,7 +113,7 @@ ApplicationWindow {
             Rectangle {
                 id: canvasCol
                 height: parent.height
-                width: height*4/3
+                width: height * 4 / 3
                 color: aw.color
 
                 Canvas {
@@ -103,6 +123,7 @@ ApplicationWindow {
 
                     property color strokeStyle: Qt.darker(fillStyle, 1.2)
                     property color fillStyle: "#6400aa"
+                    property string curColor: "#ff0000"
 
                     property int lineWidth: 3
                     property real px: width / 2
@@ -132,9 +153,15 @@ ApplicationWindow {
 
                     function finish_path() {
                         points_array[points_array.length - 1] = Simplify.simplify(
-                                    points_array[points_array.length - 1], 3)
+                                    points_array[points_array.length - 1], 2.2)
                         requestPaint()
-                        //ws.send()..
+                        //normalized to 800x600
+                        var ar = points_array[points_array.length - 1].map(
+                                    function(el){
+                                        return {x: el.x*800/canvas.width, y:el.y*600/canvas.height}
+                                    }
+                            );
+                        socket.send_drawing(ar)
                     }
 
                     function change_image(pdf, number) {
@@ -204,11 +231,11 @@ ApplicationWindow {
             Column {
                 id: columnLayout1
                 spacing: 15
-                width: parent.width - canvasCol.width - parent.spacing*2
+                width: parent.width - canvasCol.width - parent.spacing * 2
 
                 Button {
-                    width:parent.width
-                    height:80
+                    width: parent.width
+                    height: 80
                     id: button2
                     text: qsTr("Anterior")
                     enabled: socket.active
@@ -216,8 +243,8 @@ ApplicationWindow {
                 }
 
                 Button {
-                    height:80
-                    width:parent.width
+                    height: 80
+                    width: parent.width
                     id: button1
                     text: qsTr("Siguiente")
                     enabled: socket.active
@@ -225,16 +252,16 @@ ApplicationWindow {
                 }
 
                 Button {
-                    height:80
-                    width:parent.width
+                    height: 80
+                    width: parent.width
                     id: button4
                     text: qsTr("Limpiar")
                     enabled: socket.active
                     onClicked: socket.clear_path()
                 }
                 Button {
-                    height:80
-                    width:parent.width
+                    height: 80
+                    width: parent.width
                     id: button3
                     text: qsTr("Break")
                     isDefault: false