ConfigurationListView.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.2 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: label.height + UM.Theme.getSize("wide_margin").height
  27. anchors.top: parent.top
  28. anchors.topMargin: UM.Theme.getSize("default_margin").height
  29. UM.RecolorImage
  30. {
  31. id: icon
  32. anchors.left: parent.left
  33. anchors.verticalCenter: label.verticalCenter
  34. source: UM.Theme.getIcon("warning")
  35. color: UM.Theme.getColor("warning")
  36. width: UM.Theme.getSize("section_icon").width
  37. height: width
  38. }
  39. Label
  40. {
  41. id: label
  42. anchors.left: icon.right
  43. anchors.right: parent.right
  44. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  45. // There are two cases that we want to diferenciate, one is when Cura is loading the configurations and the
  46. // other when the connection was lost
  47. text: Cura.MachineManager.printerConnected ?
  48. catalog.i18nc("@label", "Loading available configurations from the printer...") :
  49. catalog.i18nc("@label", "The configurations are not available because the printer is disconnected.")
  50. color: UM.Theme.getColor("text")
  51. font: UM.Theme.getFont("default")
  52. renderType: Text.NativeRendering
  53. wrapMode: Text.WordWrap
  54. }
  55. }
  56. ScrollView
  57. {
  58. id: container
  59. width: parent.width
  60. readonly property int maximumHeight: 350 * screenScaleFactor
  61. height: Math.round(Math.min(configurationList.height, maximumHeight))
  62. contentHeight: configurationList.height
  63. clip: true
  64. 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.
  65. ScrollBar.vertical.background: Rectangle
  66. {
  67. implicitWidth: UM.Theme.getSize("scrollbar").width
  68. radius: width / 2
  69. color: UM.Theme.getColor("scrollbar_background")
  70. }
  71. ScrollBar.vertical.contentItem: Rectangle
  72. {
  73. implicitWidth: UM.Theme.getSize("scrollbar").width
  74. radius: width / 2
  75. color: UM.Theme.getColor(parent.pressed ? "scrollbar_handle_down" : parent.hovered ? "scrollbar_handle_hover" : "scrollbar_handle")
  76. }
  77. ButtonGroup
  78. {
  79. buttons: configurationList.children
  80. }
  81. ListView
  82. {
  83. id: configurationList
  84. spacing: UM.Theme.getSize("narrow_margin").height
  85. width: container.width - ((height > container.maximumHeight) ? container.ScrollBar.vertical.background.width : 0) //Make room for scroll bar if there is any.
  86. height: childrenRect.height
  87. interactive: false // let the ScrollView process scroll events.
  88. section.property: "modelData.printerType"
  89. section.criteria: ViewSection.FullString
  90. section.delegate: Item
  91. {
  92. height: printerTypeLabel.height + UM.Theme.getSize("wide_margin").height //Causes a default margin above the label and a default margin below the label.
  93. Cura.PrinterTypeLabel
  94. {
  95. id: printerTypeLabel
  96. text: section
  97. anchors.verticalCenter: parent.verticalCenter //One default margin above and one below.
  98. autoFit: true
  99. }
  100. }
  101. model: (outputDevice != null) ? outputDevice.uniqueConfigurations : []
  102. delegate: ConfigurationItem
  103. {
  104. width: parent.width
  105. configuration: modelData
  106. }
  107. }
  108. }
  109. Connections
  110. {
  111. target: outputDevice
  112. onUniqueConfigurationsChanged:
  113. {
  114. forceModelUpdate()
  115. }
  116. }
  117. Connections
  118. {
  119. target: Cura.MachineManager
  120. onOutputDevicesChanged:
  121. {
  122. forceModelUpdate()
  123. }
  124. }
  125. }