GraphAnnotation.qml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3. import org.semlanik.cutegit 1.0
  4. Item {
  5. id: root
  6. property int elementHeight: 20
  7. property int spacing: 10
  8. QtObject {
  9. id: d
  10. property int fullHeight: elementHeight + spacing
  11. }
  12. Repeater {
  13. id: branches
  14. model: _handler.branchList
  15. Item {
  16. anchors.left: parent.left
  17. height: d.fullHeight
  18. width: root.width / 2
  19. y: _handler.graph.point(model.oid).y*d.fullHeight - spacing/2
  20. clip: true
  21. Rectangle {
  22. anchors.left: parent.left
  23. anchors.right: parent.right
  24. anchors.verticalCenter: parent.verticalCenter
  25. height: 25
  26. color:"#77ccff"
  27. Rectangle {
  28. id:branchIconRect
  29. width: 20
  30. height: parent.height
  31. color:"#55aaff"
  32. Image {
  33. id: branchIcon
  34. anchors.centerIn: parent
  35. height: 16
  36. width: 10
  37. source: "qrc:///images/branch.svg"
  38. }
  39. }
  40. Text {
  41. id: branchNameText
  42. anchors.left: branchIconRect.right
  43. anchors.leftMargin: 5
  44. anchors.right: parent.right
  45. anchors.rightMargin: 5
  46. anchors.verticalCenter: parent.verticalCenter
  47. verticalAlignment: Text.AlignVCenter
  48. font.pixelSize: 12
  49. text: model.fullName
  50. elide: Text.ElideMiddle
  51. }
  52. }
  53. MouseArea {
  54. anchors.fill: parent
  55. hoverEnabled: true
  56. acceptedButtons: Qt.LeftButton | Qt.RightButton
  57. onContainsMouseChanged: {
  58. if(containsMouse) {
  59. if(branchNameText.implicitWidth <= branchNameText.width) {
  60. return
  61. }
  62. var coord = parent.mapToItem(TooltipViewModel.viewport, 0, 0)
  63. TooltipViewModel.x = coord.x
  64. TooltipViewModel.y = coord.y + spacing/2
  65. TooltipViewModel.text = model.fullName
  66. TooltipViewModel.visible = true
  67. } else {
  68. TooltipViewModel.visible = false
  69. }
  70. }
  71. onClicked: {
  72. if(mouse.button === Qt.RightButton) {
  73. branchMenu.popup()
  74. } else {
  75. root.commitClicked(model.modelData)
  76. }
  77. }
  78. }
  79. Menu {
  80. id: branchMenu
  81. MenuItem {
  82. text: "Checkout branch"
  83. onTriggered: {
  84. _handler.activeRepo.checkout(model.modelData)
  85. }
  86. }
  87. }
  88. }
  89. }
  90. Repeater {
  91. id: tags
  92. model: _handler.tagList
  93. Item {
  94. id: tagContainer
  95. anchors.right: parent.right
  96. height: d.fullHeight
  97. width: root.width / 2
  98. y: _handler.graph.point(model.targetId).y*d.fullHeight - spacing/2
  99. clip: true
  100. Rectangle {
  101. anchors.left: parent.left
  102. anchors.right: parent.right
  103. anchors.verticalCenter: parent.verticalCenter
  104. height: 25
  105. color:"#ccff77"
  106. Rectangle {
  107. id: tagIconRect
  108. width: 20
  109. height: parent.height
  110. color:"#aaff55"
  111. Image {
  112. id: tagIcon
  113. anchors.centerIn: parent
  114. height: 14
  115. width: height
  116. source: "qrc:///images/tag.svg"
  117. }
  118. }
  119. Text {
  120. id: tagNameText
  121. anchors.left: tagIconRect.right
  122. anchors.leftMargin: 5
  123. anchors.right: parent.right
  124. anchors.rightMargin: 5
  125. anchors.verticalCenter: parent.verticalCenter
  126. text: model.name
  127. font.pixelSize: 12
  128. elide: Text.ElideRight
  129. }
  130. }
  131. MouseArea {
  132. anchors.fill: parent
  133. hoverEnabled: true
  134. onContainsMouseChanged: {
  135. if(tagNameText.implicitWidth <= tagNameText.width) {
  136. return
  137. }
  138. if(containsMouse) {
  139. var coord = parent.mapToItem(TooltipViewModel.viewport, 0, 0)
  140. TooltipViewModel.x = coord.x
  141. TooltipViewModel.y = coord.y + spacing/2
  142. TooltipViewModel.text = model.name
  143. TooltipViewModel.visible = true
  144. } else {
  145. TooltipViewModel.visible = false
  146. }
  147. }
  148. }
  149. }
  150. }
  151. }