CommitList.qml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import QtQuick 2.0
  2. import QtQuick.Controls 1.4
  3. FlickPager {
  4. id: root
  5. property QtObject graphModel: null
  6. property QtObject commitsModel: null
  7. property QtObject activeCommit: null
  8. signal commitClicked(var commit)
  9. QtObject {
  10. id: d
  11. property int commitsWidth: 0
  12. property int graphWidth: 0
  13. property int fullMessageWidth: 600
  14. property int annotationWidth: 200
  15. }
  16. width: 120
  17. clip: true
  18. state: "full"
  19. states: [
  20. State {
  21. name: "full"
  22. PropertyChanges {
  23. target: root
  24. width: d.fullMessageWidth + d.commitsWidth + d.graphWidth + d.annotationWidth
  25. }
  26. },
  27. State {
  28. name: "commitsOnly"
  29. PropertyChanges {
  30. target: root
  31. width: d.commitsWidth + d.graphWidth + d.annotationWidth
  32. }
  33. },
  34. State {
  35. name: "treeOnly"
  36. PropertyChanges {
  37. target: root
  38. width: d.graphWidth + d.annotationWidth
  39. }
  40. }
  41. ]
  42. transitions: [
  43. Transition {
  44. NumberAnimation {
  45. properties: "width"
  46. duration: 200
  47. }
  48. }
  49. ]
  50. content: Item {
  51. id: innerItem
  52. width: root.width
  53. height: graph.height
  54. Column {
  55. anchors.left: parent.left
  56. anchors.right: parent.right
  57. clip: true
  58. spacing: graph.spacingV
  59. Repeater {
  60. model: root.commitsModel
  61. Rectangle {
  62. width: parent.width
  63. height: graph.elementHeight
  64. color: {
  65. if(activeCommit && activeCommit.sha1 === model.sha1){
  66. return "#bbeebb"
  67. }
  68. return textSelector.containsMouse ? "#bbbbbb" : "#00bbbbbb"
  69. }
  70. Item {
  71. width: root.width - graph.width - graphAnnotation.width
  72. height: sha1.height
  73. anchors.right: parent.right
  74. Text {
  75. id: sha1
  76. font.family: "Inconsolata"
  77. font.pointSize: 12
  78. anchors.left: parent.left
  79. text: "[" + model.shortSha1 + "]"
  80. Component.onCompleted: {
  81. d.commitsWidth = sha1.width + 10
  82. }
  83. }
  84. Text {
  85. anchors.left: sha1.right
  86. anchors.right: parent.right
  87. anchors.leftMargin: 10
  88. anchors.rightMargin: 10
  89. verticalAlignment: Text.AlignVCenter
  90. text: model.summary
  91. elide: Text.ElideRight
  92. }
  93. }
  94. //TODO: Make as part of graph
  95. // Row {
  96. // anchors.left: parent.left
  97. // Text {
  98. // verticalAlignment: Text.AlignVCenter
  99. // horizontalAlignment: Text.AlignLeft
  100. // text: graphPointData.branch
  101. // }
  102. // Text {
  103. // verticalAlignment: Text.AlignVCenter
  104. // horizontalAlignment: Text.AlignLeft
  105. // text: graphPointData.tag
  106. // }
  107. // }
  108. MouseArea {
  109. id: textSelector
  110. anchors.fill: parent
  111. hoverEnabled: true
  112. focus: true
  113. acceptedButtons: Qt.LeftButton | Qt.RightButton
  114. onClicked: {
  115. if(mouse.button === Qt.RightButton) {
  116. commitMenu.popup()
  117. } else {
  118. root.commitClicked(model.modelData)
  119. //TODO: Because active commit is used in multiple places need to make it part of some model (e.g. git handler)
  120. activeCommit = model.modelData;
  121. }
  122. }
  123. }
  124. Menu {
  125. id: commitMenu
  126. MenuItem {
  127. text: "Copy sha-id"
  128. onTriggered: {
  129. _handler.copySha1(model.sha1)
  130. }
  131. }
  132. MenuItem {
  133. text: "Checkout commit"
  134. onTriggered: {
  135. _handler.activeRepo.checkout(model.modelData)
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
  142. GraphAnnotation {
  143. id: graphAnnotation
  144. elementHeight: graph.elementHeight
  145. spacing: graph.spacingV
  146. width: d.annotationWidth
  147. }
  148. Graph {
  149. id: graph
  150. anchors.left: graphAnnotation.right
  151. model: root.graphModel
  152. onWidthChanged: {
  153. d.graphWidth = graph.width
  154. }
  155. }
  156. }
  157. }