Advertisement
Guest User

main.qml

a guest
Sep 27th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. import QtQuick 2.14
  2. import QtQuick.Shapes 1.14
  3.  
  4. import QtQuick.Controls 1.1
  5. //import QtQuick.Controls 2.14 // no vertical scrollbar when using 2.14
  6.  
  7. ApplicationWindow {
  8. id: myApp
  9.  
  10. visible: true
  11. width: 500
  12. height: 350
  13. title: qsTr("QML Gantt Test")
  14.  
  15. // visual styles
  16. readonly property int barHeight: 40
  17. readonly property int innerBarHeight: barHeight - 2
  18. readonly property int taskInfoWidth: 152
  19. readonly property color backgroundColor: "#ccc"
  20.  
  21. // states
  22. readonly property int futureDistance: 100 // space left to the time axis (the unknown future)
  23. property int fullGanttSpace: sim.ticks + futureDistance
  24. property int posInTime: sim.ticks
  25. property ListModel taskModel: sim.taskModel // [{taskName, ranges[{start, duration},...]},...]
  26.  
  27. // Simulates fix amount of tasks + ongoing activity
  28. TaskSimulation
  29. {
  30. id:sim
  31. intervalInMsec: 50
  32. taskCount: 10
  33. }
  34.  
  35. Component.onCompleted: {
  36. sim.start()
  37. }
  38.  
  39. Rectangle{
  40. id: ganttArea
  41. height: 300
  42. clip: true
  43. width: 450
  44. anchors.centerIn: parent
  45.  
  46. color: backgroundColor
  47.  
  48. ListView{
  49. id: ganttNameView // vertical List with Names and Gantt Ranges
  50.  
  51. anchors.fill: parent
  52.  
  53. interactive: false
  54. contentY: ganttView.contentY
  55. model: taskModel
  56. delegate: Rectangle{
  57. width: ganttNameView.width
  58. height: barHeight
  59. Rectangle{
  60. color: backgroundColor
  61. width: parent.width
  62. height: innerBarHeight
  63. Text{
  64. anchors.verticalCenter: parent.verticalCenter
  65. anchors.left: parent.left
  66. text: taskName
  67. }
  68. }
  69. }
  70.  
  71. Rectangle{
  72. id: rangeArea
  73.  
  74. height: parent.height
  75. width: parent.width - taskInfoWidth
  76. x: taskInfoWidth
  77. color: backgroundColor
  78.  
  79. ScrollView{ // Activity list
  80. id: mainScroll
  81. anchors.fill: parent
  82.  
  83. ListView{
  84. id: ganttView
  85.  
  86. height: parent.height
  87. contentWidth: fullGanttSpace
  88. model: taskModel
  89.  
  90. delegate: Rectangle{
  91. width: ganttView.width
  92. height: barHeight
  93.  
  94. color: backgroundColor
  95.  
  96. Repeater {
  97. model: ranges
  98. Rectangle {
  99. x: model.start
  100. y: height / 2.0
  101.  
  102. width: model.duration
  103. height: innerBarHeight/2.0
  104.  
  105. border.width: 1
  106. color: "lightblue"
  107. }
  108. }
  109.  
  110.  
  111. Shape {
  112. ShapePath {
  113. strokeColor: "green"
  114. strokeWidth: 2
  115.  
  116. startX: posInTime
  117. startY: 0
  118.  
  119. PathLine { x: posInTime; y: ganttView.height }
  120. }
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement