MaterialView.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Uranium is released under the terms of the AGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.3
  5. import QtQuick.Dialogs 1.2
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. TabView
  9. {
  10. id: base
  11. property QtObject properties;
  12. property bool editingEnabled: false;
  13. property string currency: UM.Preferences.getValue("general/currency") ? UM.Preferences.getValue("general/currency") : "€"
  14. property real firstColumnWidth: width * 0.45
  15. property real secondColumnWidth: width * 0.45
  16. property string containerId: ""
  17. Tab
  18. {
  19. title: "Information"
  20. anchors
  21. {
  22. leftMargin: UM.Theme.getSize("default_margin").width
  23. topMargin: UM.Theme.getSize("default_margin").height
  24. bottomMargin: UM.Theme.getSize("default_margin").height
  25. rightMargin: 0
  26. }
  27. ScrollView
  28. {
  29. anchors.fill: parent
  30. horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
  31. Flow
  32. {
  33. id: containerGrid
  34. width: base.width;
  35. property real rowHeight: textField.height;
  36. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Display Name") }
  37. ReadOnlyTextField
  38. {
  39. id: displayNameTextField;
  40. width: base.secondColumnWidth;
  41. text: properties.name;
  42. readOnly: !base.editingEnabled;
  43. onEditingFinished: base.setName(properties.name, text)
  44. }
  45. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Brand") }
  46. ReadOnlyTextField
  47. {
  48. id: textField;
  49. width: base.secondColumnWidth;
  50. text: properties.supplier;
  51. readOnly: !base.editingEnabled;
  52. onEditingFinished: base.setMetaDataEntry("brand", properties.supplier, text)
  53. }
  54. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Material Type") }
  55. ReadOnlyTextField
  56. {
  57. width: base.secondColumnWidth;
  58. text: properties.material_type;
  59. readOnly: !base.editingEnabled;
  60. onEditingFinished: base.setMetaDataEntry("material", properties.material_type, text)
  61. }
  62. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Color") }
  63. Row
  64. {
  65. width: base.secondColumnWidth;
  66. height: parent.rowHeight;
  67. spacing: UM.Theme.getSize("default_margin").width/2
  68. Rectangle
  69. {
  70. id: colorSelector
  71. color: properties.color_code
  72. width: colorLabel.height * 0.75
  73. height: colorLabel.height * 0.75
  74. border.width: UM.Theme.getSize("default_lining").height
  75. anchors.verticalCenter: parent.verticalCenter
  76. MouseArea { anchors.fill: parent; onClicked: colorDialog.open(); enabled: base.editingEnabled }
  77. }
  78. ReadOnlyTextField
  79. {
  80. id: colorLabel;
  81. text: properties.color_name;
  82. readOnly: !base.editingEnabled
  83. onEditingFinished: base.setMetaDataEntry("color_name", properties.color_name, text)
  84. }
  85. ColorDialog { id: colorDialog; color: properties.color_code; onAccepted: base.setMetaDataEntry("color_code", properties.color_code, color) }
  86. }
  87. Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
  88. Label { width: parent.width; height: parent.rowHeight; font.bold: true; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Properties") }
  89. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Density") }
  90. ReadOnlySpinBox
  91. {
  92. width: base.secondColumnWidth;
  93. value: properties.density;
  94. decimals: 2
  95. suffix: "g/cm"
  96. stepSize: 0.01
  97. readOnly: !base.editingEnabled;
  98. onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value)
  99. }
  100. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Diameter") }
  101. ReadOnlySpinBox
  102. {
  103. width: base.secondColumnWidth;
  104. value: properties.diameter;
  105. decimals: 2
  106. suffix: "mm³"
  107. stepSize: 0.01
  108. readOnly: !base.editingEnabled;
  109. onEditingFinished: base.setMetaDataEntry("properties/diameter", properties.diameter, value)
  110. }
  111. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament Cost") }
  112. SpinBox
  113. {
  114. width: base.secondColumnWidth;
  115. value: properties.spool_cost;
  116. prefix: base.currency
  117. enabled: false
  118. }
  119. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament weight") }
  120. SpinBox
  121. {
  122. width: base.secondColumnWidth;
  123. value: properties.spool_weight;
  124. suffix: "g";
  125. stepSize: 10
  126. enabled: false
  127. }
  128. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament length") }
  129. SpinBox
  130. {
  131. width: base.secondColumnWidth;
  132. value: parseFloat(properties.spool_length);
  133. suffix: "m";
  134. enabled: false
  135. }
  136. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Cost per Meter (Approx.)") }
  137. SpinBox
  138. {
  139. width: base.secondColumnWidth;
  140. value: parseFloat(properties.cost_per_meter);
  141. suffix: catalog.i18nc("@label", "%1/m".arg(base.currency));
  142. enabled: false
  143. }
  144. Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
  145. Label { width: parent.width; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Description") }
  146. ReadOnlyTextArea
  147. {
  148. text: properties.description;
  149. width: base.firstColumnWidth + base.secondColumnWidth
  150. wrapMode: Text.WordWrap
  151. readOnly: !base.editingEnabled;
  152. onEditingFinished: base.setMetaDataEntry("description", properties.description, text)
  153. }
  154. Label { width: parent.width; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Adhesion Information") }
  155. ReadOnlyTextArea
  156. {
  157. text: properties.adhesion_info;
  158. width: base.firstColumnWidth + base.secondColumnWidth
  159. wrapMode: Text.WordWrap
  160. readOnly: !base.editingEnabled;
  161. onEditingFinished: base.setMetaDataEntry("adhesion_info", properties.adhesion_info, text)
  162. }
  163. }
  164. }
  165. }
  166. Tab
  167. {
  168. title: catalog.i18nc("@label", "Print settings")
  169. anchors
  170. {
  171. leftMargin: UM.Theme.getSize("default_margin").width
  172. topMargin: UM.Theme.getSize("default_margin").height
  173. bottomMargin: UM.Theme.getSize("default_margin").height
  174. rightMargin: 0
  175. }
  176. ScrollView
  177. {
  178. anchors.fill: parent;
  179. ListView
  180. {
  181. model: UM.SettingDefinitionsModel
  182. {
  183. containerId: Cura.MachineManager.activeDefinitionId
  184. visibilityHandler: Cura.MaterialSettingsVisibilityHandler { }
  185. expanded: ["*"]
  186. }
  187. delegate: UM.TooltipArea
  188. {
  189. width: childrenRect.width
  190. height: childrenRect.height
  191. text: model.description
  192. Label
  193. {
  194. id: label
  195. width: base.firstColumnWidth;
  196. height: spinBox.height
  197. text: model.label
  198. }
  199. ReadOnlySpinBox
  200. {
  201. id: spinBox
  202. anchors.left: label.right
  203. value: parseFloat(provider.properties.value);
  204. width: base.secondColumnWidth;
  205. readOnly: !base.editingEnabled
  206. suffix: model.unit
  207. maximumValue: 99999
  208. decimals: model.unit == "mm" ? 2 : 0
  209. onEditingFinished: provider.setPropertyValue("value", value)
  210. }
  211. UM.ContainerPropertyProvider { id: provider; containerId: base.containerId; watchedProperties: [ "value" ]; key: model.key }
  212. }
  213. }
  214. }
  215. }
  216. // Tiny convenience function to check if a value really changed before trying to set it.
  217. function setMetaDataEntry(entry_name, old_value, new_value)
  218. {
  219. if(old_value != new_value)
  220. {
  221. Cura.ContainerManager.setContainerMetaDataEntry(base.containerId, entry_name, new_value);
  222. }
  223. }
  224. function setName(old_value, new_value)
  225. {
  226. if(old_value != new_value)
  227. {
  228. Cura.ContainerManager.setContainerName(base.containerId, new_value);
  229. }
  230. }
  231. }