ConfigurationListView.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // Copyright (c) 2022 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.5 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. UM.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. wrapMode: Text.WordWrap
  50. }
  51. }
  52. ScrollView
  53. {
  54. id: container
  55. width: parent.width
  56. readonly property int maximumHeight: 350 * screenScaleFactor
  57. height: Math.round(Math.min(configurationList.height, maximumHeight))
  58. contentHeight: configurationList.height
  59. clip: true
  60. ScrollBar.vertical: UM.ScrollBar {
  61. parent: container.parent
  62. anchors
  63. {
  64. top: parent.top
  65. right: parent.right
  66. bottom: parent.bottom
  67. }
  68. }
  69. ButtonGroup
  70. {
  71. buttons: configurationList.children
  72. }
  73. ListView
  74. {
  75. id: configurationList
  76. spacing: UM.Theme.getSize("narrow_margin").height
  77. width: container.width - ((height > container.maximumHeight) ? container.ScrollBar.vertical.background.width : 0) //Make room for scroll bar if there is any.
  78. height: contentHeight
  79. interactive: false // let the ScrollView process scroll events.
  80. section.property: "modelData.printerType"
  81. section.criteria: ViewSection.FullString
  82. section.delegate: Item
  83. {
  84. height: printerTypeLabel.height + UM.Theme.getSize("wide_margin").height //Causes a default margin above the label and a default margin below the label.
  85. Cura.PrinterTypeLabel
  86. {
  87. id: printerTypeLabel
  88. text: section
  89. anchors.verticalCenter: parent.verticalCenter //One default margin above and one below.
  90. autoFit: true
  91. }
  92. }
  93. model: (outputDevice != null) ? outputDevice.uniqueConfigurations : []
  94. delegate: ConfigurationItem
  95. {
  96. width: parent.width
  97. configuration: modelData
  98. }
  99. }
  100. }
  101. Connections
  102. {
  103. target: outputDevice
  104. function onUniqueConfigurationsChanged()
  105. {
  106. forceModelUpdate()
  107. }
  108. }
  109. Connections
  110. {
  111. target: Cura.MachineManager
  112. function onOutputDevicesChanged()
  113. {
  114. forceModelUpdate()
  115. }
  116. }
  117. }