ConfigurationListView.qml 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. Column
  9. {
  10. id: base
  11. property var outputDevice: null
  12. property var computedHeight: container.height + configurationListHeading.height + 3 * padding
  13. height: childrenRect.height + 2 * padding
  14. padding: UM.Theme.getSize("default_margin").width
  15. spacing: Math.round(UM.Theme.getSize("default_margin").height / 2)
  16. function forceModelUpdate()
  17. {
  18. // FIXME For now the model should be removed and then created again, otherwise changes in the printer don't automatically update the UI
  19. configurationList.model = []
  20. if(outputDevice)
  21. {
  22. configurationList.model = outputDevice.uniqueConfigurations
  23. }
  24. }
  25. Label
  26. {
  27. id: configurationListHeading
  28. text: catalog.i18nc("@label:header configurations", "Available configurations")
  29. font: UM.Theme.getFont("large")
  30. width: parent.width - 2 * parent.padding
  31. color: UM.Theme.getColor("configuration_item_text")
  32. }
  33. Component
  34. {
  35. id: sectionHeading
  36. Rectangle
  37. {
  38. height: childrenRect.height + UM.Theme.getSize("default_margin").height
  39. Label
  40. {
  41. text: section
  42. font: UM.Theme.getFont("default_bold")
  43. color: UM.Theme.getColor("configuration_item_text")
  44. }
  45. }
  46. }
  47. ScrollView
  48. {
  49. id: container
  50. width: parent.width - parent.padding
  51. height: Math.min(configurationList.contentHeight, 350 * screenScaleFactor)
  52. style: UM.Theme.styles.scrollview
  53. __wheelAreaScrollSpeed: 75 // Scroll three lines in one scroll event
  54. ListView
  55. {
  56. id: configurationList
  57. spacing: Math.round(UM.Theme.getSize("default_margin").height / 2)
  58. width: container.width
  59. contentHeight: childrenRect.height
  60. section.property: "modelData.printerType"
  61. section.criteria: ViewSection.FullString
  62. section.delegate: sectionHeading
  63. model: (outputDevice != null) ? outputDevice.uniqueConfigurations : []
  64. delegate: ConfigurationItem
  65. {
  66. width: parent.width - UM.Theme.getSize("default_margin").width
  67. configuration: modelData
  68. onActivateConfiguration:
  69. {
  70. switchPopupState()
  71. Cura.MachineManager.applyRemoteConfiguration(configuration)
  72. }
  73. }
  74. }
  75. }
  76. Connections
  77. {
  78. target: outputDevice
  79. onUniqueConfigurationsChanged:
  80. {
  81. forceModelUpdate()
  82. }
  83. }
  84. Connections
  85. {
  86. target: Cura.MachineManager
  87. onOutputDevicesChanged:
  88. {
  89. forceModelUpdate()
  90. }
  91. }
  92. }