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