ObjectItemButton.qml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. // Copyright (c) 2020 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. Button
  8. {
  9. id: objectItemButton
  10. width: parent.width
  11. height: UM.Theme.getSize("action_button").height
  12. checkable: true
  13. hoverEnabled: true
  14. onHoveredChanged:
  15. {
  16. if(hovered && (buttonTextMetrics.elidedText != buttonText.text || perObjectSettingsInfo.visible))
  17. {
  18. tooltip.show()
  19. } else
  20. {
  21. tooltip.hide()
  22. }
  23. }
  24. onClicked: Cura.SceneController.changeSelection(index)
  25. background: Rectangle
  26. {
  27. id: backgroundRect
  28. color: objectItemButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  29. radius: UM.Theme.getSize("action_button_radius").width
  30. border.width: UM.Theme.getSize("default_lining").width
  31. border.color: objectItemButton.checked ? UM.Theme.getColor("primary") : "transparent"
  32. }
  33. contentItem: Item
  34. {
  35. width: objectItemButton.width - objectItemButton.leftPadding
  36. height: UM.Theme.getSize("action_button").height
  37. Rectangle
  38. {
  39. id: swatch
  40. anchors.verticalCenter: parent.verticalCenter
  41. anchors.left: parent.left
  42. width: UM.Theme.getSize("standard_arrow").height
  43. height: UM.Theme.getSize("standard_arrow").height
  44. radius: Math.round(width / 2)
  45. color: extruderColor
  46. visible: showExtruderSwatches && extruderColor != ""
  47. }
  48. UM.Label
  49. {
  50. id: buttonText
  51. anchors
  52. {
  53. left: showExtruderSwatches ? swatch.right : parent.left
  54. leftMargin: showExtruderSwatches ? UM.Theme.getSize("narrow_margin").width : 0
  55. right: perObjectSettingsInfo.visible ? perObjectSettingsInfo.left : parent.right
  56. verticalCenter: parent.verticalCenter
  57. }
  58. text: objectItemButton.text
  59. color: UM.Theme.getColor("text_scene")
  60. opacity: (outsideBuildArea) ? 0.5 : 1.0
  61. visible: text != ""
  62. elide: Text.ElideRight
  63. }
  64. Button
  65. {
  66. id: perObjectSettingsInfo
  67. anchors
  68. {
  69. right: parent.right
  70. rightMargin: 0
  71. }
  72. width: meshTypeIcon.width + perObjectSettingsCountLabel.width + UM.Theme.getSize("narrow_margin").width
  73. height: parent.height
  74. padding: 0
  75. leftPadding: UM.Theme.getSize("thin_margin").width
  76. visible: meshType != "" || perObjectSettingsCount > 0
  77. onClicked:
  78. {
  79. Cura.SceneController.changeSelection(index)
  80. UM.Controller.setActiveTool("PerObjectSettingsTool")
  81. }
  82. property string tooltipText:
  83. {
  84. var result = "";
  85. if (!visible)
  86. {
  87. return result;
  88. }
  89. if (meshType != "")
  90. {
  91. result += "<br>";
  92. switch (meshType) {
  93. case "support_mesh":
  94. result += catalog.i18nc("@label", "Is printed as support.");
  95. break;
  96. case "cutting_mesh":
  97. result += catalog.i18nc("@label", "Other models overlapping with this model are modified.");
  98. break;
  99. case "infill_mesh":
  100. result += catalog.i18nc("@label", "Infill overlapping with this model is modified.");
  101. break;
  102. case "anti_overhang_mesh":
  103. result += catalog.i18nc("@label", "Overlaps with this model are not supported.");
  104. break;
  105. }
  106. }
  107. if (perObjectSettingsCount != "")
  108. {
  109. result += "<br>" + catalog.i18ncp(
  110. "@label %1 is the number of settings it overrides.", "Overrides %1 setting.", "Overrides %1 settings.", perObjectSettingsCount
  111. ).arg(perObjectSettingsCount);
  112. }
  113. return result;
  114. }
  115. contentItem: Item
  116. {
  117. height: parent.height
  118. width: perObjectSettingsInfo.width
  119. Cura.NotificationIcon
  120. {
  121. id: perObjectSettingsCountLabel
  122. anchors
  123. {
  124. right: parent.right
  125. rightMargin: 0
  126. }
  127. visible: perObjectSettingsCount > 0
  128. color: UM.Theme.getColor("text_scene")
  129. labelText: perObjectSettingsCount.toString()
  130. }
  131. UM.RecolorImage
  132. {
  133. id: meshTypeIcon
  134. anchors
  135. {
  136. right: perObjectSettingsCountLabel.left
  137. rightMargin: UM.Theme.getSize("narrow_margin").width
  138. }
  139. width: parent.height
  140. height: parent.height
  141. color: UM.Theme.getColor("text_scene")
  142. visible: meshType != ""
  143. source:
  144. {
  145. switch (meshType) {
  146. case "support_mesh":
  147. return UM.Theme.getIcon("MeshTypeSupport");
  148. case "cutting_mesh":
  149. case "infill_mesh":
  150. return UM.Theme.getIcon("MeshTypeIntersect");
  151. case "anti_overhang_mesh":
  152. return UM.Theme.getIcon("BlockSupportOverlaps");
  153. }
  154. return "";
  155. }
  156. }
  157. }
  158. background: Item {}
  159. }
  160. }
  161. TextMetrics
  162. {
  163. id: buttonTextMetrics
  164. text: buttonText.text
  165. font: buttonText.font
  166. elide: buttonText.elide
  167. elideWidth: buttonText.width
  168. }
  169. UM.ToolTip
  170. {
  171. id: tooltip
  172. tooltipText: objectItemButton.text + perObjectSettingsInfo.tooltipText
  173. }
  174. UM.I18nCatalog
  175. {
  176. id: catalog
  177. name: "cura"
  178. }
  179. }