MachineSelectorButton.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import UM 1.1 as UM
  6. import Cura 1.0 as Cura
  7. Button
  8. {
  9. id: machineSelectorButton
  10. width: parent.width
  11. height: UM.Theme.getSize("action_button").height
  12. leftPadding: UM.Theme.getSize("thick_margin").width
  13. rightPadding: UM.Theme.getSize("thick_margin").width
  14. checkable: true
  15. hoverEnabled: true
  16. property bool selected: checked
  17. property bool printerTypeLabelAutoFit: false
  18. property var outputDevice: null
  19. property var printerTypesList: []
  20. // Indicates if only to update the printer types list when this button is checked
  21. property bool updatePrinterTypesOnlyWhenChecked: true
  22. property var updatePrinterTypesFunction: updatePrinterTypesList
  23. // This function converts the printer type string to another string.
  24. property var printerTypeLabelConversionFunction: Cura.MachineManager.getAbbreviatedMachineName
  25. function updatePrinterTypesList()
  26. {
  27. var to_update = (updatePrinterTypesOnlyWhenChecked && checked) || !updatePrinterTypesOnlyWhenChecked
  28. printerTypesList = (to_update && outputDevice != null) ? outputDevice.uniquePrinterTypes : []
  29. }
  30. contentItem: Item
  31. {
  32. width: machineSelectorButton.width - machineSelectorButton.leftPadding
  33. height: UM.Theme.getSize("action_button").height
  34. Label
  35. {
  36. id: buttonText
  37. anchors
  38. {
  39. left: parent.left
  40. right: printerTypes.left
  41. verticalCenter: parent.verticalCenter
  42. }
  43. text: machineSelectorButton.text
  44. color: enabled ? UM.Theme.getColor("text") : UM.Theme.getColor("small_button_text")
  45. font: UM.Theme.getFont("medium")
  46. visible: text != ""
  47. renderType: Text.NativeRendering
  48. verticalAlignment: Text.AlignVCenter
  49. elide: Text.ElideRight
  50. }
  51. Row
  52. {
  53. id: printerTypes
  54. width: childrenRect.width
  55. anchors
  56. {
  57. right: parent.right
  58. verticalCenter: parent.verticalCenter
  59. }
  60. spacing: UM.Theme.getSize("narrow_margin").width
  61. visible: (updatePrinterTypesOnlyWhenChecked && machineSelectorButton.checked) || !updatePrinterTypesOnlyWhenChecked
  62. Repeater
  63. {
  64. model: printerTypesList
  65. delegate: Cura.PrinterTypeLabel
  66. {
  67. autoFit: printerTypeLabelAutoFit
  68. text: printerTypeLabelConversionFunction(modelData)
  69. }
  70. }
  71. }
  72. }
  73. background: Rectangle
  74. {
  75. id: backgroundRect
  76. color:
  77. {
  78. if (!machineSelectorButton.enabled)
  79. {
  80. return UM.Theme.getColor("action_button_disabled")
  81. }
  82. return machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  83. }
  84. radius: UM.Theme.getSize("action_button_radius").width
  85. border.width: UM.Theme.getSize("default_lining").width
  86. border.color: machineSelectorButton.selected ? UM.Theme.getColor("primary") : "transparent"
  87. }
  88. Connections
  89. {
  90. target: outputDevice
  91. function onUniqueConfigurationsChanged() { updatePrinterTypesFunction() }
  92. }
  93. Connections
  94. {
  95. target: Cura.MachineManager
  96. function onOutputDevicesChanged() { updatePrinterTypesFunction() }
  97. }
  98. Component.onCompleted: updatePrinterTypesFunction()
  99. }