MachineSelectorButton.qml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. Repeater
  62. {
  63. model: printerTypesList
  64. delegate: Cura.PrinterTypeLabel
  65. {
  66. autoFit: printerTypeLabelAutoFit
  67. text: printerTypeLabelConversionFunction(modelData)
  68. }
  69. }
  70. }
  71. }
  72. background: Rectangle
  73. {
  74. id: backgroundRect
  75. color:
  76. {
  77. if (!machineSelectorButton.enabled)
  78. {
  79. return UM.Theme.getColor("action_button_disabled")
  80. }
  81. return machineSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  82. }
  83. radius: UM.Theme.getSize("action_button_radius").width
  84. border.width: UM.Theme.getSize("default_lining").width
  85. border.color: machineSelectorButton.selected ? UM.Theme.getColor("primary") : "transparent"
  86. }
  87. Connections
  88. {
  89. target: outputDevice
  90. onUniqueConfigurationsChanged: updatePrinterTypesFunction()
  91. }
  92. Connections
  93. {
  94. target: Cura.MachineManager
  95. onOutputDevicesChanged: updatePrinterTypesFunction()
  96. }
  97. Component.onCompleted: updatePrinterTypesFunction()
  98. }