MachineSelectorButton.qml 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.5 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 - machineSelectorButton.rightPadding
  33. height: UM.Theme.getSize("action_button").height
  34. UM.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. elide: Text.ElideRight
  48. }
  49. Row
  50. {
  51. id: printerTypes
  52. width: childrenRect.width
  53. anchors
  54. {
  55. right: parent.right
  56. verticalCenter: parent.verticalCenter
  57. }
  58. spacing: UM.Theme.getSize("narrow_margin").width
  59. visible: (updatePrinterTypesOnlyWhenChecked && machineSelectorButton.checked) || !updatePrinterTypesOnlyWhenChecked
  60. Repeater
  61. {
  62. model: printerTypesList
  63. delegate: Cura.PrinterTypeLabel
  64. {
  65. autoFit: printerTypeLabelAutoFit
  66. text: printerTypeLabelConversionFunction(modelData)
  67. }
  68. }
  69. }
  70. }
  71. background: Rectangle
  72. {
  73. id: backgroundRect
  74. color:
  75. {
  76. if (!machineSelectorButton.enabled)
  77. {
  78. return UM.Theme.getColor("action_button_disabled")
  79. }
  80. return machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  81. }
  82. radius: UM.Theme.getSize("action_button_radius").width
  83. border.width: UM.Theme.getSize("default_lining").width
  84. border.color: machineSelectorButton.selected ? UM.Theme.getColor("primary") : "transparent"
  85. }
  86. Connections
  87. {
  88. target: outputDevice
  89. function onUniqueConfigurationsChanged() { updatePrinterTypesFunction() }
  90. }
  91. Connections
  92. {
  93. target: Cura.MachineManager
  94. function onOutputDevicesChanged() { updatePrinterTypesFunction() }
  95. }
  96. Component.onCompleted: updatePrinterTypesFunction()
  97. }