ObjectItemButton.qml 6.6 KB

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