Graph.qml 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import QtQuick 2.0
  2. Canvas {
  3. id: root
  4. property int elementWidth: 20
  5. property int elementHeight: 20
  6. property int spacingH: 12
  7. property int spacingV: 20
  8. property int lineWidth: 1
  9. property QtObject model: null
  10. height: model.points.count*(elementWidth + spacingV)
  11. width: (elementWidth + spacingH)*model.branchesCount
  12. property int headY: 0
  13. QtObject {
  14. id: d
  15. property int halfElementWidth: elementWidth/2
  16. property int halfElementHeight: elementHeight/2
  17. Component.onCompleted: {
  18. root.loadImage("qrc:///images/aim.svg")
  19. _handler.activeRepo.headChanged.connect(update)
  20. }
  21. function update() {
  22. root.requestPaint()
  23. }
  24. }
  25. onPaint: {
  26. var ctx = getContext("2d")
  27. ctx.clearRect(region.x, region.y ,region.width, region.height)
  28. for(var i = 0; i < model.points.count; i++) {
  29. var point = model.points.at(i)
  30. var pointAbsX = point.x*(elementWidth + spacingH)
  31. var pointAbsY = point.y*(elementHeight + spacingV)
  32. var childPoints = point.childPoints
  33. if(!_handler.activeRepo.isHead(point.oid)) {
  34. ctx.beginPath()
  35. ctx.lineWidth = root.lineWidth
  36. ctx.strokeStyle = "#"+point.color
  37. ctx.roundedRect(pointAbsX, pointAbsY, elementWidth, elementHeight, elementWidth, elementHeight)
  38. ctx.stroke()
  39. ctx.closePath()
  40. } else {
  41. ctx.beginPath()
  42. root.headY = pointAbsY;
  43. // ctx.lineWidth = root.lineWidth
  44. ctx.fillStyle = "#"+point.color
  45. ctx.roundedRect(pointAbsX, pointAbsY, elementWidth, elementHeight, elementWidth, elementHeight)
  46. ctx.fill()
  47. ctx.closePath()
  48. ctx.drawImage("qrc:///images/aim.svg", pointAbsX + 1, pointAbsY + 1, 18, 18)
  49. }
  50. for(var j = 0; j < childPoints.length; j++) {
  51. var childPoint = childPoints[j]
  52. var childPointAbsX = childPoint.x*(elementWidth + spacingH)
  53. var childPointAbsY = childPoint.y*(elementHeight + spacingV)
  54. ctx.beginPath()
  55. ctx.strokeStyle = "#" + childPoint.color
  56. ctx.lineWidth = root.lineWidth
  57. if(point.x !== childPoint.x) {
  58. if(point.x < childPoint.x) {
  59. ctx.moveTo(pointAbsX + d.halfElementWidth, childPointAbsY + elementHeight + spacingV)
  60. ctx.bezierCurveTo(
  61. pointAbsX + d.halfElementWidth, childPointAbsY + elementHeight,
  62. childPointAbsX + d.halfElementWidth, childPointAbsY + elementHeight + spacingV/* + d.halfElementHeight*/,
  63. childPointAbsX + d.halfElementWidth, childPointAbsY + elementHeight/*d.halfElementHeight*/)
  64. } else {
  65. ctx.moveTo(pointAbsX + d.halfElementWidth, pointAbsY/* + d.halfElementHeight*/)
  66. ctx.lineTo(pointAbsX + d.halfElementWidth, childPointAbsY + elementHeight + spacingV + elementHeight)
  67. ctx.bezierCurveTo(
  68. pointAbsX + d.halfElementWidth, childPointAbsY + d.halfElementHeight,
  69. childPointAbsX + d.halfElementWidth, childPointAbsY + elementHeight + spacingV/* + d.halfElementHeight*/,
  70. childPointAbsX + d.halfElementWidth, childPointAbsY + elementHeight/*d.halfElementHeight*/)
  71. //For debuggin bazier curve migh be replaced buy straight line
  72. // ctx.lineTo(childPointAbsX + d.halfElementWidth, childPointAbsY + d.halfElementHeight)
  73. }
  74. } else {
  75. ctx.moveTo(pointAbsX + d.halfElementWidth, pointAbsY/* + d.halfElementHeight*/)
  76. ctx.lineTo(childPointAbsX + d.halfElementWidth, childPointAbsY + elementHeight)
  77. }
  78. ctx.stroke()
  79. ctx.closePath()
  80. }
  81. }
  82. }
  83. }