ObjectItemButton.qml 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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.1 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. 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. font: UM.Theme.getFont("default")
  60. color: UM.Theme.getColor("text_scene")
  61. opacity: (outsideBuildArea) ? 0.5 : 1.0
  62. visible: text != ""
  63. renderType: Text.NativeRendering
  64. verticalAlignment: Text.AlignVCenter
  65. elide: Text.ElideRight
  66. }
  67. Button
  68. {
  69. id: perObjectSettingsInfo
  70. anchors
  71. {
  72. right: parent.right
  73. rightMargin: 0
  74. }
  75. width: childrenRect.width
  76. height: parent.height
  77. padding: 0
  78. leftPadding: UM.Theme.getSize("thin_margin").width
  79. visible: meshType != "" || perObjectSettingsCount > 0
  80. onClicked:
  81. {
  82. Cura.SceneController.changeSelection(index)
  83. UM.Controller.setActiveTool("PerObjectSettingsTool")
  84. }
  85. property string tooltipText:
  86. {
  87. var result = "";
  88. if (!visible)
  89. {
  90. return result;
  91. }
  92. if (meshType != "")
  93. {
  94. result += "<br>";
  95. switch (meshType) {
  96. case "support_mesh":
  97. result += catalog.i18nc("@label", "Is printed as support.");
  98. break;
  99. case "cutting_mesh":
  100. result += catalog.i18nc("@label", "Other models overlapping with this model are modified.");
  101. break;
  102. case "infill_mesh":
  103. result += catalog.i18nc("@label", "Infill overlapping with this model is modified.");
  104. break;
  105. case "anti_overhang_mesh":
  106. result += catalog.i18nc("@label", "Overlaps with this model are not supported.");
  107. break;
  108. }
  109. }
  110. if (perObjectSettingsCount != "")
  111. {
  112. result += "<br>" + catalog.i18ncp(
  113. "@label %1 is the number of settings it overrides.", "Overrides %1 setting.", "Overrides %1 settings.", perObjectSettingsCount
  114. ).arg(perObjectSettingsCount);
  115. }
  116. return result;
  117. }
  118. contentItem: Item
  119. {
  120. height: parent.height
  121. width: meshTypeIcon.width + perObjectSettingsCountLabel.width + UM.Theme.getSize("narrow_margin").width
  122. Cura.NotificationIcon
  123. {
  124. id: perObjectSettingsCountLabel
  125. anchors
  126. {
  127. right: parent.right
  128. rightMargin: 0
  129. }
  130. visible: perObjectSettingsCount > 0
  131. color: UM.Theme.getColor("text_scene")
  132. labelText: perObjectSettingsCount.toString()
  133. }
  134. UM.RecolorImage
  135. {
  136. id: meshTypeIcon
  137. anchors
  138. {
  139. right: perObjectSettingsCountLabel.left
  140. rightMargin: UM.Theme.getSize("narrow_margin").width
  141. }
  142. width: parent.height
  143. height: parent.height
  144. color: UM.Theme.getColor("text_scene")
  145. visible: meshType != ""
  146. source:
  147. {
  148. switch (meshType) {
  149. case "support_mesh":
  150. return UM.Theme.getIcon("MeshTypeSupport");
  151. case "cutting_mesh":
  152. case "infill_mesh":
  153. return UM.Theme.getIcon("MeshTypeIntersect");
  154. case "anti_overhang_mesh":
  155. return UM.Theme.getIcon("BlockSupportOverlaps");
  156. }
  157. return "";
  158. }
  159. }
  160. }
  161. background: Item {}
  162. }
  163. }
  164. TextMetrics
  165. {
  166. id: buttonTextMetrics
  167. text: buttonText.text
  168. font: buttonText.font
  169. elide: buttonText.elide
  170. elideWidth: buttonText.width
  171. }
  172. Cura.ToolTip
  173. {
  174. id: tooltip
  175. tooltipText: objectItemButton.text + perObjectSettingsInfo.tooltipText
  176. }
  177. UM.I18nCatalog
  178. {
  179. id: catalog
  180. name: "cura"
  181. }
  182. }