CommitList.qml 6.5 KB

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