MachineListButton.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (c) 2022 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. Loader {
  8. id: loader
  9. width: parent.width
  10. sourceComponent: {
  11. switch (model.componentType) {
  12. case "HIDE_BUTTON":
  13. hideButtonComponent
  14. break;
  15. case "SHOW_BUTTON":
  16. showButtonComponent
  17. break;
  18. case "MACHINE":
  19. machineListButtonComponent
  20. break;
  21. default:
  22. }
  23. }
  24. property var onClicked
  25. Component
  26. {
  27. id: hideButtonComponent
  28. Cura.TertiaryButton
  29. {
  30. text: catalog.i18nc("@label", "Hide all connected printers")
  31. height: UM.Theme.getSize("large_button").height
  32. onClicked: if (loader.onClicked) loader.onClicked()
  33. iconSource: UM.Theme.getIcon("ChevronSingleUp")
  34. width: parent.width
  35. }
  36. }
  37. Component
  38. {
  39. id: showButtonComponent
  40. Cura.TertiaryButton
  41. {
  42. text: catalog.i18nc("@label", "Show all connected printers")
  43. height: UM.Theme.getSize("large_button").height
  44. onClicked: if (loader.onClicked) loader.onClicked()
  45. iconSource: UM.Theme.getIcon("ChevronSingleDown")
  46. width: parent.width
  47. }
  48. }
  49. Component
  50. {
  51. id: machineListButtonComponent
  52. Button
  53. {
  54. id: machineListButton
  55. onClicked: if (loader.onClicked) loader.onClicked()
  56. width: parent.width
  57. height: UM.Theme.getSize("large_button").height
  58. leftPadding: UM.Theme.getSize("default_margin").width
  59. rightPadding: UM.Theme.getSize("default_margin").width
  60. checkable: true
  61. hoverEnabled: true
  62. contentItem: Item
  63. {
  64. width: machineListButton.width - machineListButton.leftPadding - machineListButton.rightPadding
  65. height: UM.Theme.getSize("action_button").height
  66. UM.ColorImage
  67. {
  68. id: printerIcon
  69. height: UM.Theme.getSize("medium_button").height
  70. width: UM.Theme.getSize("medium_button").width
  71. color: UM.Theme.getColor("machine_selector_printer_icon")
  72. visible: model.isAbstractMachine || !model.isOnline
  73. source: model.isAbstractMachine ? UM.Theme.getIcon("PrinterTriple", "medium") : UM.Theme.getIcon("Printer", "medium")
  74. anchors
  75. {
  76. left: parent.left
  77. verticalCenter: parent.verticalCenter
  78. }
  79. }
  80. UM.Label
  81. {
  82. id: buttonText
  83. anchors
  84. {
  85. left: printerIcon.right
  86. right: printerCount.left
  87. verticalCenter: parent.verticalCenter
  88. leftMargin: UM.Theme.getSize("default_margin").width
  89. }
  90. text: model.name ? model.name : ""
  91. font: model.isAbstractMachine ? UM.Theme.getFont("medium_bold") : UM.Theme.getFont("medium")
  92. visible: text != ""
  93. elide: Text.ElideRight
  94. }
  95. Rectangle
  96. {
  97. id: printerCount
  98. color: UM.Theme.getColor("background_2")
  99. radius: height
  100. width: height
  101. anchors
  102. {
  103. right: parent.right
  104. top: buttonText.top
  105. bottom: buttonText.bottom
  106. }
  107. visible: model.isAbstractMachine ? model.isAbstractMachine : false
  108. UM.Label
  109. {
  110. text: model.machineCount ? model.machineCount : ""
  111. anchors.centerIn: parent
  112. font: UM.Theme.getFont("default_bold")
  113. }
  114. }
  115. }
  116. background: Rectangle
  117. {
  118. id: backgroundRect
  119. color: machineListButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  120. }
  121. }
  122. }
  123. }