ObjectItemButton.qml 6.8 KB

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