DiffFiles.qml 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import QtQuick 2.0
  2. import QtGraphicalEffects 1.0
  3. import org.semlanik.cutegit 1.0
  4. ListView {
  5. id: root
  6. property QtObject diff: null
  7. signal openDiff(var file)
  8. spacing: 10
  9. model: diff ? diff.files : 0
  10. clip: true
  11. delegate: Item {
  12. property QtObject diffModel: root.diff.model(modelData)
  13. width: commitBodyText.width + action.width + 10
  14. height: commitBodyText.height + 10
  15. // Rectangle {
  16. // color: "red"
  17. // anchors.right: action.left
  18. // height: parent.height
  19. // width: parent.width*diffModel.similarity/100
  20. // }
  21. Text {
  22. id: commitBodyText
  23. anchors.bottom: parent.bottom
  24. font.pointSize: 10
  25. width: root.width - action.width - 10
  26. text: modelData
  27. elide: Text.ElideLeft
  28. horizontalAlignment: Text.AlignRight
  29. color:control.containsMouse ? "#aaaaaa" : "#000000"
  30. MouseArea {
  31. id: control
  32. anchors.fill: parent
  33. hoverEnabled: true
  34. acceptedButtons: Qt.RightButton|Qt.LeftButton
  35. onClicked: {
  36. if(mouse.button === Qt.RightButton) {
  37. var coord = commitBodyText.mapToItem(TooltipViewModel.viewport, 0, 0)
  38. TooltipViewModel.x = coord.x
  39. TooltipViewModel.y = coord.y
  40. TooltipViewModel.text = qsTr("Filename copied ") + modelData
  41. TooltipViewModel.visible = true
  42. _handler.copy(modelData)
  43. tttimer.restart()
  44. } else {
  45. root.openDiff(modelData)
  46. }
  47. }
  48. }
  49. }
  50. Image {
  51. id: action
  52. anchors.right: parent.right
  53. anchors.verticalCenter: commitBodyText.verticalCenter
  54. source: {
  55. if(root.diff) {
  56. switch(diffModel.type) {
  57. case DiffModel.Added:
  58. return "qrc:///images/diff-added.png"
  59. case DiffModel.Deleted:
  60. return "qrc:///images/diff-removed.png"
  61. case DiffModel.Modified:
  62. return "qrc:///images/diff-modified.png"
  63. case DiffModel.Renamed:
  64. return "qrc:///images/diff-renamed.png"
  65. default:
  66. return "qrc:///images/diff-ignored.png"
  67. }
  68. }
  69. }
  70. }
  71. }
  72. Timer {
  73. id: tttimer
  74. interval: 1000
  75. repeat: false
  76. onTriggered: {
  77. TooltipViewModel.visible = false
  78. }
  79. Component.onDestruction: {
  80. TooltipViewModel.visible = false
  81. }
  82. }
  83. }