MaterialsSlot.qml 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 1.4
  5. import QtQuick.Controls.Styles 1.4
  6. import QtQuick.Layouts 1.3
  7. import QtQuick.Dialogs 1.2
  8. import UM 1.2 as UM
  9. import Cura 1.0 as Cura
  10. // A single material row, typically used in a MaterialsBrandSection
  11. Rectangle
  12. {
  13. id: materialSlot
  14. property var material: null
  15. property var hovered: false
  16. property var is_favorite: material != null && material.is_favorite
  17. height: UM.Theme.getSize("favorites_row").height
  18. width: parent.width
  19. //color: material != null ? (base.currentItem.root_material_id == material.root_material_id ? UM.Theme.getColor("favorites_row_selected") : "transparent") : "transparent"
  20. color:
  21. {
  22. if(material !== null && base.currentItem !== null)
  23. {
  24. if(base.currentItem.root_material_id === material.root_material_id)
  25. {
  26. return UM.Theme.getColor("favorites_row_selected")
  27. }
  28. }
  29. return "transparent"
  30. }
  31. Rectangle
  32. {
  33. id: swatch
  34. color: material != null ? material.color_code : "transparent"
  35. border.width: UM.Theme.getSize("default_lining").width
  36. border.color: "black"
  37. width: UM.Theme.getSize("favorites_button_icon").width
  38. height: UM.Theme.getSize("favorites_button_icon").height
  39. anchors.verticalCenter: materialSlot.verticalCenter
  40. anchors.left: materialSlot.left
  41. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  42. }
  43. Label
  44. {
  45. text: material != null ? material.brand + " " + material.name : ""
  46. verticalAlignment: Text.AlignVCenter
  47. height: parent.height
  48. anchors.left: swatch.right
  49. anchors.verticalCenter: materialSlot.verticalCenter
  50. anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
  51. font.italic: material != null && Cura.MachineManager.currentRootMaterialId[Cura.ExtruderManager.activeExtruderIndex] == material.root_material_id
  52. }
  53. MouseArea
  54. {
  55. anchors.fill: parent
  56. onClicked:
  57. {
  58. materialList.currentBrand = material.brand
  59. materialList.currentType = material.brand + "_" + material.material
  60. base.setExpandedActiveMaterial(material.root_material_id)
  61. }
  62. hoverEnabled: true
  63. onEntered: { materialSlot.hovered = true }
  64. onExited: { materialSlot.hovered = false }
  65. }
  66. Button
  67. {
  68. id: favorite_button
  69. text: ""
  70. implicitWidth: UM.Theme.getSize("favorites_button").width
  71. implicitHeight: UM.Theme.getSize("favorites_button").height
  72. visible: materialSlot.hovered || materialSlot.is_favorite || favorite_button.hovered
  73. anchors
  74. {
  75. right: materialSlot.right
  76. verticalCenter: materialSlot.verticalCenter
  77. }
  78. onClicked:
  79. {
  80. if (materialSlot.is_favorite)
  81. {
  82. CuraApplication.getMaterialManagementModel().removeFavorite(material.root_material_id)
  83. }
  84. else
  85. {
  86. CuraApplication.getMaterialManagementModel().addFavorite(material.root_material_id)
  87. }
  88. }
  89. style: ButtonStyle
  90. {
  91. background: Item { }
  92. }
  93. UM.RecolorImage
  94. {
  95. anchors
  96. {
  97. verticalCenter: favorite_button.verticalCenter
  98. horizontalCenter: favorite_button.horizontalCenter
  99. }
  100. width: UM.Theme.getSize("favorites_button_icon").width
  101. height: UM.Theme.getSize("favorites_button_icon").height
  102. color:
  103. {
  104. if (favorite_button.hovered)
  105. {
  106. return UM.Theme.getColor("primary_hover")
  107. }
  108. else
  109. {
  110. if (materialSlot.is_favorite)
  111. {
  112. return UM.Theme.getColor("primary")
  113. }
  114. else
  115. {
  116. UM.Theme.getColor("text_inactive")
  117. }
  118. }
  119. }
  120. source: materialSlot.is_favorite ? UM.Theme.getIcon("favorites_star_full") : UM.Theme.getIcon("favorites_star_empty")
  121. }
  122. }
  123. }