MaterialsSlot.qml 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Uranium 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. Rectangle
  11. {
  12. id: material_slot
  13. property var material
  14. property var hovered: false
  15. property var is_favorite: material.is_favorite
  16. height: UM.Theme.getSize("favorites_row").height
  17. width: parent.width
  18. color: base.currentItem.root_material_id == material.root_material_id ? UM.Theme.getColor("favorites_row_selected") : "transparent"
  19. Rectangle
  20. {
  21. id: swatch
  22. color: material.color_code
  23. border.width: UM.Theme.getSize("default_lining").width
  24. border.color: "black"
  25. width: UM.Theme.getSize("favorites_button_icon").width
  26. height: UM.Theme.getSize("favorites_button_icon").height
  27. anchors.verticalCenter: parent.verticalCenter
  28. anchors.left: parent.left
  29. anchors.leftMargin: UM.Theme.getSize("default_margin").width
  30. }
  31. Label
  32. {
  33. text: material.brand + " " + material.name
  34. verticalAlignment: Text.AlignVCenter
  35. height: parent.height
  36. anchors.left: swatch.right
  37. anchors.verticalCenter: parent.verticalCenter
  38. anchors.leftMargin: UM.Theme.getSize("narrow_margin").width
  39. }
  40. MouseArea
  41. {
  42. anchors.fill: parent
  43. onClicked:
  44. {
  45. materialList.currentBrand = material.brand
  46. materialList.currentType = material.brand + "_" + material.material
  47. base.currentItem = material
  48. }
  49. hoverEnabled: true
  50. onEntered: { material_slot.hovered = true }
  51. onExited: { material_slot.hovered = false }
  52. }
  53. Button
  54. {
  55. id: favorite_button
  56. text: ""
  57. implicitWidth: UM.Theme.getSize("favorites_button").width
  58. implicitHeight: UM.Theme.getSize("favorites_button").height
  59. visible: material_slot.hovered || material_slot.is_favorite || favorite_button.hovered
  60. anchors
  61. {
  62. right: parent.right
  63. verticalCenter: parent.verticalCenter
  64. }
  65. onClicked:
  66. {
  67. if (material_slot.is_favorite) {
  68. base.materialManager.removeFavorite(material.root_material_id)
  69. material_slot.is_favorite = false
  70. return
  71. }
  72. base.materialManager.addFavorite(material.root_material_id)
  73. material_slot.is_favorite = true
  74. return
  75. }
  76. style: ButtonStyle
  77. {
  78. background: Rectangle
  79. {
  80. anchors.fill: parent
  81. color: "transparent"
  82. }
  83. }
  84. UM.RecolorImage {
  85. anchors
  86. {
  87. verticalCenter: parent.verticalCenter
  88. horizontalCenter: parent.horizontalCenter
  89. }
  90. width: UM.Theme.getSize("favorites_button_icon").width
  91. height: UM.Theme.getSize("favorites_button_icon").height
  92. sourceSize.width: width
  93. sourceSize.height: height
  94. color:
  95. {
  96. if (favorite_button.hovered)
  97. {
  98. return UM.Theme.getColor("primary_hover")
  99. }
  100. else
  101. {
  102. if (material_slot.is_favorite)
  103. {
  104. return UM.Theme.getColor("primary")
  105. }
  106. else
  107. {
  108. UM.Theme.getColor("text_inactive")
  109. }
  110. }
  111. }
  112. source: material_slot.is_favorite ? UM.Theme.getIcon("favorites_star_full") : UM.Theme.getIcon("favorites_star_empty")
  113. }
  114. }
  115. }