ConfigurationListView.qml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.3
  5. import UM 1.4 as UM
  6. import Cura 1.0 as Cura
  7. Item
  8. {
  9. id: base
  10. property var outputDevice: null
  11. height: childrenRect.height
  12. function forceModelUpdate()
  13. {
  14. // FIXME For now the model has to be removed and then created again, otherwise changes in the printer don't automatically update the UI
  15. configurationList.model = []
  16. if (outputDevice)
  17. {
  18. configurationList.model = outputDevice.uniqueConfigurations
  19. }
  20. }
  21. // This component will appear when there are no configurations (e.g. when losing connection or when they are being loaded)
  22. Item
  23. {
  24. width: parent.width
  25. visible: configurationList.model.length == 0
  26. height: icon.height
  27. anchors.top: parent.top
  28. anchors.topMargin: UM.Theme.getSize("default_margin").height
  29. UM.StatusIcon
  30. {
  31. id: icon
  32. width: visible ? UM.Theme.getSize("section_icon").width : 0
  33. height: width
  34. anchors.verticalCenter: parent.verticalCenter
  35. status: UM.StatusIcon.Status.WARNING
  36. }
  37. Label
  38. {
  39. id: label
  40. anchors.left: icon.right
  41. anchors.right: parent.right
  42. anchors.verticalCenter: parent.verticalCenter
  43. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  44. // There are two cases that we want to differentiate, one is when Cura is loading the configurations and the
  45. // other when the connection was lost
  46. text: Cura.MachineManager.printerConnected ?
  47. catalog.i18nc("@label", "Loading available configurations from the printer...") :
  48. catalog.i18nc("@label", "The configurations are not available because the printer is disconnected.")
  49. color: UM.Theme.getColor("text")
  50. font: UM.Theme.getFont("default")
  51. renderType: Text.NativeRendering
  52. wrapMode: Text.WordWrap
  53. }
  54. }
  55. ScrollView
  56. {
  57. id: container
  58. width: parent.width
  59. readonly property int maximumHeight: 350 * screenScaleFactor
  60. height: Math.round(Math.min(configurationList.height, maximumHeight))
  61. contentHeight: configurationList.height
  62. clip: true
  63. ScrollBar.vertical.policy: (configurationList.height > maximumHeight) ? ScrollBar.AlwaysOn : ScrollBar.AlwaysOff //The AsNeeded policy also hides it when the cursor is away, and we don't want that.
  64. ScrollBar.vertical.background: Rectangle
  65. {
  66. implicitWidth: UM.Theme.getSize("scrollbar").width
  67. radius: width / 2
  68. color: UM.Theme.getColor("scrollbar_background")
  69. }
  70. ScrollBar.vertical.contentItem: Rectangle
  71. {
  72. implicitWidth: UM.Theme.getSize("scrollbar").width
  73. radius: width / 2
  74. color: UM.Theme.getColor(parent.pressed ? "scrollbar_handle_down" : parent.hovered ? "scrollbar_handle_hover" : "scrollbar_handle")
  75. }
  76. ButtonGroup
  77. {
  78. buttons: configurationList.children
  79. }
  80. ListView
  81. {
  82. id: configurationList
  83. spacing: UM.Theme.getSize("narrow_margin").height
  84. width: container.width - ((height > container.maximumHeight) ? container.ScrollBar.vertical.background.width : 0) //Make room for scroll bar if there is any.
  85. height: contentHeight
  86. interactive: false // let the ScrollView process scroll events.
  87. section.property: "modelData.printerType"
  88. section.criteria: ViewSection.FullString
  89. section.delegate: Item
  90. {
  91. height: printerTypeLabel.height + UM.Theme.getSize("wide_margin").height //Causes a default margin above the label and a default margin below the label.
  92. Cura.PrinterTypeLabel
  93. {
  94. id: printerTypeLabel
  95. text: section
  96. anchors.verticalCenter: parent.verticalCenter //One default margin above and one below.
  97. autoFit: true
  98. }
  99. }
  100. model: (outputDevice != null) ? outputDevice.uniqueConfigurations : []
  101. delegate: ConfigurationItem
  102. {
  103. width: parent.width
  104. configuration: modelData
  105. }
  106. }
  107. }
  108. Connections
  109. {
  110. target: outputDevice
  111. function onUniqueConfigurationsChanged()
  112. {
  113. forceModelUpdate()
  114. }
  115. }
  116. Connections
  117. {
  118. target: Cura.MachineManager
  119. function onOutputDevicesChanged()
  120. {
  121. forceModelUpdate()
  122. }
  123. }
  124. }