MachineListButton.qml 4.4 KB

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