MainView.qml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3. import QtQuick.Dialogs 1.2
  4. import org.semlanik.nicegit 1.0
  5. Item {
  6. id: root
  7. Row {
  8. id: selector
  9. Text {
  10. text: "Active repository" + repoOpenDialog.fileUrl
  11. }
  12. Button {
  13. text: "Choose..."
  14. onClicked: repoOpenDialog.open()
  15. }
  16. }
  17. Column {
  18. anchors.top: selector.bottom
  19. Repeater {
  20. model: _handler.repositories
  21. Text {
  22. text: model.name
  23. }
  24. }
  25. }
  26. Flickable {
  27. width: root.width/2
  28. anchors.top: parent.top
  29. anchors.bottom: parent.bottom
  30. anchors.right: parent.right
  31. contentWidth: innerItem.width
  32. contentHeight: innerItem.height
  33. Column {
  34. width: parent.width
  35. spacing: 20
  36. Repeater {
  37. model: _handler.graph.points.length
  38. Rectangle {
  39. width: parent.width
  40. height: innerItem.elementHeight
  41. color: textSelector.containsMouse ? "#9999ff" : "#009999ff"
  42. Text {
  43. anchors.fill: parent
  44. verticalAlignment: Text.AlignVCenter
  45. horizontalAlignment: Text.AlignRight
  46. text: _handler.graph.points[_handler.graph.points.length - model.index - 1].sha1
  47. }
  48. MouseArea {
  49. id: textSelector
  50. anchors.fill: parent
  51. hoverEnabled: true
  52. }
  53. }
  54. }
  55. }
  56. Canvas {
  57. id: innerItem
  58. width: root.width/2
  59. property int elementWidth: 20
  60. property int elementHeight: 20
  61. height: _handler.graph.points.length*(elementWidth + 20)
  62. onPaint: {
  63. var ctx = getContext("2d")
  64. for(var i = 0; i < _handler.graph.points.length; i++) {
  65. var point = _handler.graph.points[i]
  66. ctx.beginPath()
  67. ctx.fillStyle = "#"+point.color
  68. ctx.roundedRect(point.x*(elementWidth + 20), point.y*(elementHeight + 20), elementWidth, elementHeight, elementWidth, elementHeight)
  69. ctx.fill()
  70. ctx.closePath()
  71. var childPoints = point.childPoints
  72. for(var j = 0; j < childPoints.length; j++) {
  73. var childPoint = childPoints[j]
  74. ctx.beginPath()
  75. ctx.strokeStyle = "#" + childPoint.color
  76. ctx.lineWidth = 2
  77. if(point.x !== childPoint.x) {
  78. if(point.x < childPoint.x) {
  79. ctx.moveTo(point.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight + 20)
  80. ctx.bezierCurveTo(
  81. point.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight,
  82. childPoint.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight + 20 + elementHeight/2,
  83. childPoint.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight/2)
  84. } else {
  85. ctx.moveTo(point.x*(elementWidth + 20) + elementWidth/2, point.y*(elementHeight + 20) + elementHeight/2)
  86. ctx.lineTo(point.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight + 20 + elementHeight)
  87. ctx.bezierCurveTo(
  88. point.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight/2,
  89. childPoint.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight + 20 + elementHeight/2,
  90. childPoint.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight/2)
  91. }
  92. } else {
  93. ctx.moveTo(point.x*(elementWidth + 20) + elementWidth/2, point.y*(elementHeight + 20) + elementHeight/2)
  94. ctx.lineTo(childPoint.x*(elementWidth + 20) + elementWidth/2, childPoint.y*(elementHeight + 20) + elementHeight/2)
  95. }
  96. ctx.stroke()
  97. ctx.closePath()
  98. }
  99. }
  100. }
  101. }
  102. }
  103. FileDialog {
  104. id: repoOpenDialog
  105. folder: "."
  106. selectFolder: true
  107. selectMultiple: false
  108. onAccepted: {
  109. _handler.open(repoOpenDialog.fileUrl)
  110. }
  111. }
  112. }