Procházet zdrojové kódy

rotando display + perf

David před 9 roky
rodič
revize
b497cd15ff
5 změnil soubory, kde provedl 86 přidání a 175 odebrání
  1. 1 1
      CanvasController.pro.user
  2. 6 1
      main.cpp
  3. 79 49
      main.qml
  4. 0 1
      qml.qrc
  5. 0 123
      simplify.js

+ 1 - 1
CanvasController.pro.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.2.0, 2017-01-27T19:12:44. -->
+<!-- Written by QtCreator 4.2.0, 2017-01-31T16:30:12. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 6 - 1
main.cpp

@@ -1,12 +1,17 @@
 #include <QApplication>
 #include <QQmlApplicationEngine>
-
+#include <QCursor>
+#include <QScreen>
 int main(int argc, char *argv[])
 {
     QApplication app(argc, argv);
 
     QQmlApplicationEngine engine;
     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
+    QScreen *screen = QApplication::screens().at(0);
+
+    if (screen->availableSize().height() > screen->availableSize().width())
+        QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
 
     return app.exec();
 }

+ 79 - 49
main.qml

@@ -1,16 +1,19 @@
 import QtQuick 2.5
 import QtQuick.Controls 1.4
 import QtQuick.Controls.Styles 1.4
+import QtQuick.Dialogs 1.1
+import QtQuick.Window 2.2
 
-import "./simplify.js" as Simplify
 import "components" as Comps
 
 
 ApplicationWindow {
     id: aw
     visible: true
-    width: 960
-    height: 540
+    width: 600
+    height: 960
+    visibility: Screen.height > Screen.width ? "FullScreen" : "Windowed"
+
     color: "#fffffe"
 
     Comps.WebSocket {
@@ -19,17 +22,19 @@ ApplicationWindow {
     property alias t_slides: socket.tot_slides
     Item {
         id: item1
-        width: parent.width
-        height: parent.height
-
 
+        transformOrigin: Item.Center
+        rotation: Screen.height > Screen.width ? 90 : 0
         property alias mouseArea1: mouseArea1
         property alias button3: button3
         property int curImage: 1
         property variant pregs: []
 
         property string curPDF: "EBA"
-        anchors.fill: parent
+        width: parent.height
+        height: parent.width
+        anchors.horizontalCenter: parent.horizontalCenter
+        anchors.verticalCenter: parent.verticalCenter
         onCurPDFChanged: {
             canvas.change_image(curPDF, curImage)
             diapoStatus.text = qsTr("%1/%2 (%3 preg)").arg(curImage).arg(
@@ -57,18 +62,18 @@ ApplicationWindow {
             id: grid1
             width: parent.width
             height: parent.height
-            anchors.right: parent.right
-            anchors.bottom: parent.bottom
-            anchors.top: parent.top
-            anchors.left: parent.left
+
             columns: 4
             spacing: 4
 
             Rectangle {
                 id: canvasCol
-                height: parent.height
-                width: height * 4 / 3
-                color: aw.color
+                height: grid1.height
+                width: Screen.height > Screen.width ? grid1.width *3/4 : grid1.width/2
+                color: "#333"
+                smooth: false
+                //aw.color
+
 
                 Canvas {
                     id: canvas
@@ -89,20 +94,20 @@ ApplicationWindow {
                     width: parent.width
                     height: parent.height
 
-                    onPaint: full_repaint()
-                    //paint_canvas()
+
+                    onPaint: full_repaint(region)
                     onImageLoaded: {
                         clean_path()
                         if (ctx === null)
                             ctx = canvas.getContext("2d");
                         ctx.lineCap = 'square'
                         ctx.lineWidth = 4
-                        full_repaint()
+                        requestPaint()
                     }
 
                     function clean_path() {
                         points_array.length=0
-                        full_repaint()
+                        requestPaint()
                     }
 
                     function start_path() {
@@ -135,15 +140,19 @@ ApplicationWindow {
                             lastpoint = pts[pts.length-1];
 
                         pts.push(p)
-                        socket.send_point(p);
-                        if (lastpoint)
-                            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))
+                        /*socket.send_point(p);*/
+                        if (lastpoint) {
+                            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));
+
+                        }
+
                     }
 
 
                     function stroke(points, color) {
                         if (points.length===0)
                             return;
+
                         if (ctx.strokeStyle !== color){
                             ctx.strokeStyle = color;
                         }
@@ -157,31 +166,31 @@ ApplicationWindow {
                         ctx.stroke()
                     }
 
-                    function full_repaint(){
-                        //console.log("Fullpaint")
+                    function full_repaint(region){
                         if (ctx === null )
                             ctx = canvas.getContext("2d");
-                        if (canvas.isImageLoaded(curImageUrl)) {
-                            ctx.drawImage(curImageUrl, 0, 0, canvas.width,
-                                          canvas.height)
-                        }
-                        var j = 0
-                        for (j = 0; j < points_array.length; j++) {
-                            if (points_array[j].points.length <= 1)
-                                continue
-                            stroke(points_array[j].points,points_array[j].color);
+
+
+                        if ( region === undefined || region.width > 150 || region.height > 150 ) {
+                            console.log("Full", region.width, region.height);
+                            if (canvas.isImageLoaded(curImageUrl)) {
+                                ctx.drawImage(curImageUrl, 0, 0, canvas.width,
+                                              canvas.height)
+                            }
+                            var j = 0
+                            for (j = 0; j < points_array.length; j++) {
+                                if (points_array[j].points.length <= 1)
+                                    continue
+                                stroke(points_array[j].points,points_array[j].color);
+                            }
+                        } else {
+                            var lastLine = points_array[points_array.length-1];
+                            if (lastLine === undefined)
+                                return;
+                            stroke(lastLine.points, lastLine.color);
                         }
-                        requestPaint()
                     }
 
-                    function paint_canvas() {
-                        if (ctx === null )
-                            ctx = canvas.getContext("2d");
-                        if (points_array.length === 0)
-                            return;
-                        var ar = points_array[points_array.length -1];
-                        stroke(ar.points,ar.color);
-                    }
                 }
 
                 MouseArea {
@@ -223,20 +232,17 @@ ApplicationWindow {
                 spacing: 10
                 width: parent.width - canvasCol.width - parent.spacing * 2
                 height: parent.height
-
                 Column {
                     width: parent.width
-                    height: parent.height / 2 - 60
-
+                    height: parent.height / 2 - 10
                     Row {
                         id: row2
                         width: parent.width
-                        height: 70
-
+                        height: 120
                         MouseArea {
                             id: image1
                             width: parent.width/2
-                            height: 70
+                            height: parent.height
                             Image {
                                 anchors.centerIn: parent.Center
                                 source: "qrc:///images/back.png"
@@ -250,7 +256,7 @@ ApplicationWindow {
                         MouseArea {
                             id: image2
                             width: parent.width/2
-                            height: 70
+                            height: parent.height
 
                             Image {
                                 anchors.centerIn: parent.Center
@@ -294,7 +300,8 @@ ApplicationWindow {
                 Column {
                     id: column1
                     width: parent.width
-                    height: parent.height / 2 - 60
+                    height: parent.height / 2 - 10
+                    spacing: 2
                     Repeater{
                         model: [ ["#0000ff", "#00ff00", "#ff0000"], ["#ffff00", "#00ffff", "#000000"] ]
                         Row {
@@ -348,6 +355,15 @@ ApplicationWindow {
                         id: diapoStatus
                         text: qsTr("Diapo status")
                     }
+                    Button {
+                        id: salir
+                        width: 40
+                        height: 20
+                        text: qsTr("Salir")
+                        onClicked: {
+                            messageDialog.visible = true;
+                        }
+                    }
 
 
                 }
@@ -355,4 +371,18 @@ ApplicationWindow {
             }
         }
     }
+    MessageDialog {
+        id: messageDialog
+        title: "Salir"
+        text: "Seguro que desea salir?"
+        standardButtons: StandardButton.Yes | StandardButton.No
+        icon: StandardIcon.Warning
+        onYes: {
+            Qt.quit()
+        }
+        onNo: {
+            visible = false
+        }
+    }
 }
+

+ 0 - 1
qml.qrc

@@ -1,7 +1,6 @@
 <RCC>
     <qresource prefix="/">
         <file>main.qml</file>
-        <file>simplify.js</file>
         <file>images/back.png</file>
         <file>images/fwd.png</file>
         <file>components/WebSocket.qml</file>

+ 0 - 123
simplify.js

@@ -1,123 +0,0 @@
-.pragma library
-/*
- (c) 2013, Vladimir Agafonkin
- Simplify.js, a high-performance JS polyline simplification library
- mourner.github.io/simplify-js
-*/
-
-'use strict';
-
-// to suit your point format, run search/replace for '.x' and '.y';
-// for 3D version, see 3d branch (configurability would draw significant performance overhead)
-
-// square distance between 2 points
-function getSqDist(p1, p2) {
-
-    var dx = p1.x - p2.x,
-        dy = p1.y - p2.y;
-
-    return dx * dx + dy * dy;
-}
-
-// square distance from a point to a segment
-function getSqSegDist(p, p1, p2) {
-
-    var x = p1.x,
-        y = p1.y,
-        dx = p2.x - x,
-        dy = p2.y - y;
-
-    if (dx !== 0 || dy !== 0) {
-
-        var t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
-
-        if (t > 1) {
-            x = p2.x;
-            y = p2.y;
-
-        } else if (t > 0) {
-            x += dx * t;
-            y += dy * t;
-        }
-    }
-
-    dx = p.x - x;
-    dy = p.y - y;
-
-    return dx * dx + dy * dy;
-}
-// rest of the code doesn't care about point format
-
-// basic distance-based simplification
-function simplifyRadialDist(points, sqTolerance) {
-
-    var prevPoint = points[0],
-        newPoints = [prevPoint],
-        point;
-
-    for (var i = 1, len = points.length; i < len; i++) {
-        point = points[i];
-
-        if (getSqDist(point, prevPoint) > sqTolerance) {
-            newPoints.push(point);
-            prevPoint = point;
-        }
-    }
-
-    if (prevPoint !== point) newPoints.push(point);
-
-    return newPoints;
-}
-
-function simplifyDPStep(points, first, last, sqTolerance, simplified) {
-    var maxSqDist = sqTolerance,
-        index;
-
-    for (var i = first + 1; i < last; i++) {
-        var sqDist = getSqSegDist(points[i], points[first], points[last]);
-
-        if (sqDist > maxSqDist) {
-            index = i;
-            maxSqDist = sqDist;
-        }
-    }
-
-    if (maxSqDist > sqTolerance) {
-        if (index - first > 1) simplifyDPStep(points, first, index, sqTolerance, simplified);
-        simplified.push(points[index]);
-        if (last - index > 1) simplifyDPStep(points, index, last, sqTolerance, simplified);
-    }
-}
-
-// simplification using Ramer-Douglas-Peucker algorithm
-function simplifyDouglasPeucker(points, sqTolerance) {
-    var last = points.length - 1;
-
-    var simplified = [points[0]];
-    simplifyDPStep(points, 0, last, sqTolerance, simplified);
-    simplified.push(points[last]);
-
-    return simplified;
-}
-
-// both algorithms combined for awesome performance
-function simplify(points, tolerance, highestQuality) {
-
-    if (points.length <= 2) return points;
-
-    var sqTolerance = tolerance !== undefined ? tolerance * tolerance : 1;
-
-    points = highestQuality ? points : simplifyRadialDist(points, sqTolerance);
-    points = simplifyDouglasPeucker(points, sqTolerance);
-
-    return points;
-}
-/*
-// export as AMD module / Node module / browser or worker variable
-if (typeof define === 'function' && define.amd) define(function() { return simplify; });
-else if (typeof module !== 'undefined') module.exports = simplify;
-else if (typeof self !== 'undefined') self.simplify = simplify;
-else window.simplify = simplify;
-
-})();
-*/