ConfigurationListView.qml 4.3 KB

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