BarChart.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
  2. import QtQuick 1.1
  3. import "../js/core.js" as Core
  4. Rectangle {
  5. id: barchart
  6. property alias good: bar1.height
  7. property alias bad: bar2.height
  8. //property alias total: bar3.height
  9. color: "#00000000"
  10. Rectangle{
  11. id:bar1
  12. height: 150
  13. width: 60
  14. color: "green"
  15. gradient: Gradient {
  16. GradientStop {
  17. position: 0.00;
  18. color: "#008000";
  19. }
  20. GradientStop {
  21. position: 1.00;
  22. color: "#ffffff";
  23. }
  24. }
  25. border.color: "black"
  26. anchors.right: bar2.left
  27. anchors.bottom: parent.verticalCenter
  28. }
  29. Text{
  30. anchors.horizontalCenter: bar1.horizontalCenter
  31. anchors.bottom: bar1.top
  32. anchors.bottomMargin: 5
  33. text: qsTr("Good")
  34. }
  35. Rectangle{
  36. id:bar2
  37. height: 90
  38. width: 60
  39. color: "red"
  40. gradient: Gradient {
  41. GradientStop {
  42. position: 0.00;
  43. color: "#ff0000";
  44. }
  45. GradientStop {
  46. position: 1.00;
  47. color: "#ffffff";
  48. }
  49. }
  50. border.color: "black"
  51. anchors.horizontalCenter: parent.horizontalCenter
  52. anchors.top: parent.verticalCenter
  53. }
  54. Text{
  55. anchors.horizontalCenter: bar2.horizontalCenter
  56. anchors.top: bar2.bottom
  57. anchors.topMargin: 5
  58. text: qsTr("Bad")
  59. }
  60. Rectangle{
  61. id:bar3
  62. //height: 60
  63. width: 60
  64. color: "blue"
  65. gradient: Gradient {
  66. GradientStop {
  67. position: 0.00;
  68. color: "#0000ff";
  69. }
  70. GradientStop {
  71. position: 1.00;
  72. color: "#ffffff";
  73. }
  74. }
  75. border.color: "blue"
  76. //anchors.bottom: parent.verticalCenter
  77. anchors.left:bar2.right
  78. }
  79. Text{
  80. id: karmatext
  81. anchors.horizontalCenter: bar3.horizontalCenter
  82. text: qsTr("Karma")
  83. }
  84. function getKarma(){
  85. var maxvalue=100
  86. chart.bad=-1*Core.getBadKarma();
  87. chart.good=Core.getGoodKarma();
  88. if (chart.good>chart.bad){
  89. chart.bad=chart.bad*maxvalue/chart.good
  90. chart.good=maxvalue
  91. bar3.height=(bar1.height-bar2.height)
  92. bar3.y=bar1.y+bar2.height
  93. karmatext.anchors.bottom=bar3.top
  94. karmatext.anchors.bottomMargin=5
  95. }else{
  96. chart.good=chart.good*maxvalue/chart.bad
  97. chart.bad=maxvalue
  98. bar3.height=(bar2.height-bar1.height)
  99. bar3.y=bar2.y
  100. karmatext.anchors.top=bar3.bottom
  101. karmatext.anchors.topMargin=5
  102. }
  103. }
  104. }