MaterialsSlot.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.1
  5. import QtQuick.Layouts 1.3
  6. import UM 1.5 as UM
  7. import Cura 1.5 as Cura
  8. // A single material row, typically used in a MaterialsBrandSection
  9. Rectangle
  10. {
  11. id: materialSlot
  12. property var material: null
  13. property bool hovered: false
  14. property bool isActive: material != null && Cura.MachineManager.currentRootMaterialId[Cura.ExtruderManager.activeExtruderIndex] == material.root_material_id
  15. height: UM.Theme.getSize("preferences_page_list_item").height
  16. width: parent.width
  17. color: UM.Theme.getColor("main_background")
  18. states:
  19. [
  20. State
  21. {
  22. name: "selected"
  23. when: material !== null && base.currentItem !== null && base.currentItem.root_material_id === material.root_material_id
  24. PropertyChanges { target: materialSlot; color: UM.Theme.getColor("background_3") }
  25. },
  26. State
  27. {
  28. name: "hovered"
  29. when: hovered
  30. PropertyChanges { target: materialSlot; color: UM.Theme.getColor("background_3") }
  31. }
  32. ]
  33. Rectangle
  34. {
  35. id: swatch
  36. color: material != null ? material.color_code : "transparent"
  37. width: UM.Theme.getSize("icon_indicator").width
  38. height: UM.Theme.getSize("icon_indicator").height
  39. radius: width / 2
  40. anchors.verticalCenter: materialSlot.verticalCenter
  41. anchors.left: materialSlot.left
  42. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  43. }
  44. UM.Label
  45. {
  46. id: materialLabel
  47. text: material != null ? `${material.brand} ${material.name}` : ""
  48. font: isActive ? UM.Theme.getFont("default_italic") : UM.Theme.getFont("default")
  49. elide: Text.ElideRight
  50. wrapMode: Text.NoWrap
  51. verticalAlignment: Text.AlignVCenter
  52. anchors.left: swatch.right
  53. anchors.right: favoriteButton.visible ? favoriteButton.left : parent.right
  54. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  55. anchors.rightMargin: UM.Theme.getSize("narrow_margin").width
  56. anchors.verticalCenter: materialSlot.verticalCenter
  57. }
  58. UM.TooltipArea
  59. {
  60. anchors.fill: parent
  61. text: material != null ? `${material.brand} ${material.name}` : ""
  62. acceptedButtons: Qt.LeftButton
  63. onClicked:
  64. {
  65. materialList.currentBrand = material.brand;
  66. materialList.currentType = `${material.brand}_${material.material}`;
  67. base.setExpandedActiveMaterial(material.root_material_id);
  68. }
  69. hoverEnabled: true
  70. onEntered: { materialSlot.hovered = true }
  71. onExited: { materialSlot.hovered = false }
  72. }
  73. Item
  74. {
  75. id: favoriteButton
  76. states:
  77. [
  78. State
  79. {
  80. name: "favorite"
  81. when: material !== null && material.is_favorite
  82. PropertyChanges { target: favoriteIndicator; source: UM.Theme.getIcon("StarFilled");}
  83. PropertyChanges { target: favoriteButton; visible: true }
  84. },
  85. State
  86. {
  87. name: "hovered"
  88. when: hovered
  89. PropertyChanges { target: favoriteButton; visible: true }
  90. }
  91. ]
  92. implicitHeight: parent.height
  93. implicitWidth: favoriteIndicator.width
  94. anchors.right: materialSlot.right
  95. visible: false
  96. UM.ColorImage
  97. {
  98. id: favoriteIndicator
  99. anchors.centerIn: parent
  100. width: UM.Theme.getSize("small_button_icon").width
  101. height: UM.Theme.getSize("small_button_icon").height
  102. color: UM.Theme.getColor("primary")
  103. source: UM.Theme.getIcon("Star")
  104. }
  105. MouseArea
  106. {
  107. anchors.fill: parent
  108. onClicked:
  109. {
  110. if (material !== null)
  111. {
  112. if (material.is_favorite)
  113. {
  114. CuraApplication.getMaterialManagementModel().removeFavorite(material.root_material_id)
  115. }
  116. else
  117. {
  118. CuraApplication.getMaterialManagementModel().addFavorite(material.root_material_id)
  119. }
  120. }
  121. }
  122. }
  123. }
  124. }