MaterialView.qml 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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", "Brand") }
  37. ReadOnlyTextField
  38. {
  39. id: textField;
  40. width: base.secondColumnWidth;
  41. text: properties.supplier;
  42. readOnly: !base.editingEnabled;
  43. onEditingFinished: base.setMetaDataEntry("brand", properties.supplier, text)
  44. }
  45. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Material Type") }
  46. ReadOnlyTextField
  47. {
  48. width: base.secondColumnWidth;
  49. text: properties.material_type;
  50. readOnly: !base.editingEnabled;
  51. onEditingFinished: base.setMetaDataEntry("material", properties.material_type, text)
  52. }
  53. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Color") }
  54. Row
  55. {
  56. width: base.secondColumnWidth;
  57. height: parent.rowHeight;
  58. spacing: UM.Theme.getSize("default_margin").width/2
  59. Rectangle
  60. {
  61. id: colorSelector
  62. color: properties.color_code
  63. width: colorLabel.height * 0.75
  64. height: colorLabel.height * 0.75
  65. border.width: UM.Theme.getSize("default_lining").height
  66. anchors.verticalCenter: parent.verticalCenter
  67. MouseArea { anchors.fill: parent; onClicked: colorDialog.open(); enabled: base.editingEnabled }
  68. }
  69. ReadOnlyTextField
  70. {
  71. id: colorLabel;
  72. text: properties.color_name;
  73. readOnly: !base.editingEnabled
  74. onEditingFinished: base.setMetaDataEntry("color_name", properties.color_name, text)
  75. }
  76. ColorDialog { id: colorDialog; color: properties.color_code; onAccepted: base.setMetaDataEntry("color_code", properties.color_code, color) }
  77. }
  78. Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
  79. Label { width: parent.width; height: parent.rowHeight; font.bold: true; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Properties") }
  80. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Density") }
  81. ReadOnlySpinBox
  82. {
  83. width: base.secondColumnWidth;
  84. value: properties.density;
  85. decimals: 2
  86. suffix: "g/cm"
  87. stepSize: 0.01
  88. readOnly: !base.editingEnabled;
  89. onEditingFinished: base.setMetaDataEntry("properties/density", properties.density, value)
  90. }
  91. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Diameter") }
  92. ReadOnlySpinBox
  93. {
  94. width: base.secondColumnWidth;
  95. value: properties.diameter;
  96. decimals: 2
  97. suffix: "mm³"
  98. stepSize: 0.01
  99. readOnly: !base.editingEnabled;
  100. onEditingFinished: base.setMetaDataEntry("properties/diameter", properties.diameter, value)
  101. }
  102. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament Cost") }
  103. SpinBox
  104. {
  105. width: base.secondColumnWidth;
  106. value: properties.spool_cost;
  107. prefix: base.currency
  108. enabled: false
  109. }
  110. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament weight") }
  111. SpinBox
  112. {
  113. width: base.secondColumnWidth;
  114. value: properties.spool_weight;
  115. suffix: "g";
  116. stepSize: 10
  117. enabled: false
  118. }
  119. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Filament length") }
  120. SpinBox
  121. {
  122. width: base.secondColumnWidth;
  123. value: parseFloat(properties.spool_length);
  124. suffix: "m";
  125. enabled: false
  126. }
  127. Label { width: base.firstColumnWidth; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Cost per Meter (Approx.)") }
  128. SpinBox
  129. {
  130. width: base.secondColumnWidth;
  131. value: parseFloat(properties.cost_per_meter);
  132. suffix: catalog.i18nc("@label", "%1/m".arg(base.currency));
  133. enabled: false
  134. }
  135. Item { width: parent.width; height: UM.Theme.getSize("default_margin").height }
  136. Label { width: parent.width; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Description") }
  137. ReadOnlyTextArea
  138. {
  139. text: properties.description;
  140. width: base.firstColumnWidth + base.secondColumnWidth
  141. wrapMode: Text.WordWrap
  142. readOnly: !base.editingEnabled;
  143. onEditingFinished: base.setMetaDataEntry("description", properties.description, text)
  144. }
  145. Label { width: parent.width; height: parent.rowHeight; verticalAlignment: Qt.AlignVCenter; text: catalog.i18nc("@label", "Adhesion Information") }
  146. ReadOnlyTextArea
  147. {
  148. text: properties.adhesion_info;
  149. width: base.firstColumnWidth + base.secondColumnWidth
  150. wrapMode: Text.WordWrap
  151. readOnly: !base.editingEnabled;
  152. onEditingFinished: base.setMetaDataEntry("adhesion_info", properties.adhesion_info, text)
  153. }
  154. }
  155. }
  156. }
  157. Tab
  158. {
  159. title: catalog.i18nc("@label", "Print settings")
  160. anchors
  161. {
  162. leftMargin: UM.Theme.getSize("default_margin").width
  163. topMargin: UM.Theme.getSize("default_margin").height
  164. bottomMargin: UM.Theme.getSize("default_margin").height
  165. rightMargin: 0
  166. }
  167. ScrollView
  168. {
  169. anchors.fill: parent;
  170. ListView
  171. {
  172. model: UM.SettingDefinitionsModel
  173. {
  174. containerId: Cura.MachineManager.activeDefinitionId
  175. visibilityHandler: Cura.MaterialSettingsVisibilityHandler { }
  176. expanded: ["*"]
  177. }
  178. delegate: UM.TooltipArea
  179. {
  180. width: childrenRect.width
  181. height: childrenRect.height
  182. text: model.description
  183. Label
  184. {
  185. id: label
  186. width: base.firstColumnWidth;
  187. height: spinBox.height
  188. text: model.label
  189. }
  190. ReadOnlySpinBox
  191. {
  192. id: spinBox
  193. anchors.left: label.right
  194. value: parseFloat(provider.properties.value);
  195. width: base.secondColumnWidth;
  196. readOnly: !base.editingEnabled
  197. suffix: model.unit
  198. maximumValue: 99999
  199. decimals: model.unit == "mm" ? 2 : 0
  200. onEditingFinished: provider.setPropertyValue("value", value)
  201. }
  202. UM.ContainerPropertyProvider { id: provider; containerId: base.containerId; watchedProperties: [ "value" ]; key: model.key }
  203. }
  204. }
  205. }
  206. }
  207. // Tiny convenience function to check if a value really changed before trying to set it.
  208. function setMetaDataEntry(entry_name, old_value, new_value)
  209. {
  210. if(old_value != new_value)
  211. {
  212. Cura.ContainerManager.setContainerMetaDataEntry(base.containerId, entry_name, new_value)
  213. }
  214. }
  215. }