Advertisement
Guest User

Untitled

a guest
Apr 18th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 1.72 KB | None | 0 0
  1. import QtQuick 2.5
  2. import QtQuick.Window 2.2
  3.  
  4. Window {
  5.     visible: true
  6.     width: 640
  7.     height: 480
  8.     title: qsTr("Hello World")
  9.  
  10.     Item {
  11.         id: root
  12.         anchors.fill: parent
  13.         property string chirality: "left"
  14.  
  15.         Rectangle {
  16.             id: rec
  17.             anchors.fill: parent
  18.             color: "red"
  19.         }
  20.  
  21.         Canvas {
  22.             id: painter
  23.             anchors.fill: parent
  24.  
  25.             onPaint: {
  26.                 var ctx = getContext("2d");
  27.                 ctx.reset();
  28.                 ctx.lineJoin = "round";
  29.  
  30.                 ctx.lineWidth = 4;
  31.                 ctx.strokeStyle = "black";
  32.  
  33.                 var Ax, Ay, Bx, By, Cx, Cy;
  34.  
  35.                 // NOTE: You might have to subtract half the line width.
  36.                 if (root.chirality === "left") {
  37.                     Ax = root.width - (ctx.lineWidth / 2);
  38.                     Ay = 0 + (ctx.lineWidth / 2);
  39.                     Bx = Ax;
  40.                     By = root.height - (ctx.lineWidth / 2);
  41.                     Cx = 0 + (ctx.lineWidth / 2);
  42.                     Cy = root.height / 2;
  43.                 }
  44.                 if (root.chirality === "right") {
  45.  
  46.                 }
  47.  
  48.                 ctx.beginPath();
  49.                 ctx.moveTo(Ax, Ay);
  50.                 ctx.lineTo(Bx, By);
  51.                 ctx.lineTo(Cx, Cy);
  52.                 ctx.lineTo(Ax, Ay);
  53.                 ctx.stroke();
  54.                 ctx.closePath();
  55.             }
  56.         }
  57.  
  58.  
  59.  
  60.         Timer{
  61.             interval: 5000
  62.             running: true
  63.             repeat: NumberAnimation.Infinite
  64.             onTriggered: {
  65.                 console.log("Paint ! ")
  66.                 painter.paint(rec)
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement