Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. import QtQuick 2.0
  2.  
  3. Item {
  4. width: parent.width
  5. height: parent.width
  6. Canvas {
  7. anchors.centerIn: parent
  8. width: parent.width - 40
  9. height: parent.height - 40
  10. id: canvas
  11.  
  12. property real fieldHeight: 0
  13. property real fieldWidth: 0
  14.  
  15. states: State {
  16. name: "clicked"
  17. PropertyChanges { fieldWidth: width/2; fieldHeight: height/2; target: canvas }
  18. }
  19.  
  20. transitions: Transition {
  21. ParallelAnimation {
  22. NumberAnimation { target: canvas; property: "fieldWidth"; to: width/2; duration: 500 }
  23. NumberAnimation { target: canvas; property: "fieldHeight"; to: height/2; duration: 500 }
  24. }
  25. }
  26.  
  27.  
  28. MouseArea{
  29. id: mouseArea
  30. anchors.fill: parent
  31. onClicked: canvas.state = "clicked"
  32. }
  33.  
  34. onFieldHeightChanged: requestPaint();
  35.  
  36. onPaint: {
  37. var ctx = getContext("2d");
  38. ctx.strokeStyle = Qt.rgba(0, 0, 0, 1);
  39. ctx.lineWidth = 7;
  40. ctx.beginPath();
  41.  
  42. ctx.moveTo(width/3,height/2);
  43. ctx.lineTo(width/3, height/2 - fieldHeight);
  44. ctx.stroke();
  45.  
  46. ctx.moveTo(width/3,height/2);
  47. ctx.lineTo(width/3, height/2 + fieldHeight);
  48. ctx.stroke();
  49.  
  50. ctx.moveTo(2*width/3,height/2);
  51. ctx.lineTo(2*width/3, height/2 - fieldHeight);
  52. ctx.stroke();
  53.  
  54. ctx.moveTo(2*width/3,height/2);
  55. ctx.lineTo(2*width/3, height/2 + fieldHeight);
  56. ctx.stroke();
  57.  
  58. ctx.moveTo(width/2,height/3);
  59. ctx.lineTo(width/2 - fieldWidth, height/3);
  60. ctx.stroke();
  61.  
  62. ctx.moveTo(width/2,height/3);
  63. ctx.lineTo(width/2 + fieldWidth, height/3);
  64. ctx.stroke();
  65.  
  66. ctx.moveTo(width/2, 2*height/3);
  67. ctx.lineTo(width/2 - fieldWidth, 2*height/3);
  68. ctx.stroke();
  69.  
  70. ctx.moveTo(width/2, 2*height/3);
  71. ctx.lineTo(width/2 + fieldWidth, 2*height/3);
  72. ctx.stroke();
  73. ctx.closePath()
  74. }
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement