Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. import QtQuick 2.0
  2.  
  3. Item{
  4. id: root
  5.  
  6. width: 100
  7. height: 100
  8.  
  9. property alias model: r_elements.model;
  10. property color backgroundColor:"#253544";
  11. property color fontColor: "#ffffff";
  12. property color nothingDataColor: "silver"
  13. property int titleHeight: 30
  14. property alias backgroundRole: middle.color;
  15. Item{
  16. id: fn;
  17. width: 100;
  18. height: 100;
  19.  
  20. function drawPie(ctx, centerX, centerY, radius, startAngle, endAngle, color){
  21.  
  22. ctx.beginPath();
  23. ctx.fillStyle = color;
  24. ctx.moveTo(centerX,centerY);
  25. ctx.arc(centerX, centerY, radius, Math.PI * (startAngle / 180), Math.PI * ( endAngle /180), false);
  26. ctx.lineTo(centerX, centerY);
  27. ctx.closePath();
  28. ctx.stroke();
  29. ctx.fill();
  30.  
  31. }
  32. function getPieValue(total, part){
  33. return total === 0 ? 0 : ( part * 360 / total);
  34. }
  35.  
  36. Repeater {
  37. id: r_elements
  38. delegate: r_serie;
  39. }
  40. Rectangle{
  41. id: nothingData
  42. width: parent.width - 10
  43. height: parent.height - 10
  44. color: nothingDataColor
  45. radius: width/2
  46. anchors.top: parent.top
  47. anchors.topMargin: 5
  48. anchors.horizontalCenter: parent.horizontalCenter
  49.  
  50. }
  51.  
  52. Rectangle{
  53. id: middle
  54. width: parent.width - 50
  55. height: parent.height - 50;
  56. radius: width/2
  57. anchors.verticalCenter: parent.verticalCenter
  58. anchors.horizontalCenter: parent.horizontalCenter
  59.  
  60.  
  61. color: backgroundColor
  62. }
  63.  
  64. }
  65.  
  66. Component{
  67. id: r_serie
  68. Canvas{
  69. id: canvas
  70. width: parent.width -10
  71. height: parent.height -10
  72. anchors.top: parent.top
  73. anchors.topMargin: 5
  74. anchors.horizontalCenter: parent.horizontalCenter
  75. onPaint: {
  76. var ctx = canvas.getContext('2d');
  77. var center = canvas.width / 2;
  78. var radius = center;
  79. var mTotal = model.total;
  80. console.log("start: "+model.startPie+" ,end: "+model.endPie+" ,PAUSE: "+model.name);
  81. fn.drawPie(ctx, center, center, radius, fn.getPieValue(mTotal, model.startPie), fn.getPieValue(mTotal, model.endPie), model.color);
  82. }
  83. Connections{
  84. target: r_elements.model;
  85. onDataChanged:{
  86. console.log("Repaint");
  87. // canvas.update();
  88. if (model.total !==0){
  89. nothingData.visible = false
  90. canvas.requestPaint();
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement