AddMachineDialog.qml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Layouts 1.1
  6. import QtQuick.Window 2.1
  7. import QtQuick.Controls.Styles 1.1
  8. import UM 1.2 as UM
  9. import Cura 1.0 as Cura
  10. UM.Dialog
  11. {
  12. id: base
  13. title: catalog.i18nc("@title:window", "Add Printer")
  14. property bool firstRun: false
  15. property string preferredCategory: "Ultimaker"
  16. property string activeCategory: preferredCategory
  17. minimumWidth: UM.Theme.getSize("modal_window_minimum").width
  18. minimumHeight: UM.Theme.getSize("modal_window_minimum").height
  19. width: minimumWidth
  20. height: minimumHeight
  21. flags:
  22. {
  23. var window_flags = Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint;
  24. if (Cura.MachineManager.activeDefinitionId !== "") //Disallow closing the window if we have no active printer yet. You MUST add a printer.
  25. {
  26. window_flags |= Qt.WindowCloseButtonHint;
  27. }
  28. return window_flags;
  29. }
  30. onVisibilityChanged:
  31. {
  32. // Reset selection and machine name
  33. if (visible) {
  34. activeCategory = preferredCategory;
  35. machineList.currentIndex = 0;
  36. machineName.text = getMachineName();
  37. }
  38. }
  39. signal machineAdded(string id)
  40. function getMachineName()
  41. {
  42. if (machineList.model.getItem(machineList.currentIndex) != undefined)
  43. {
  44. return machineList.model.getItem(machineList.currentIndex).name;
  45. }
  46. return "";
  47. }
  48. function getMachineMetaDataEntry(key)
  49. {
  50. if (machineList.model.getItem(machineList.currentIndex) != undefined)
  51. {
  52. return machineList.model.getItem(machineList.currentIndex).metadata[key];
  53. }
  54. return "";
  55. }
  56. Label
  57. {
  58. id: titleLabel
  59. anchors
  60. {
  61. top: parent.top
  62. left: parent.left
  63. topMargin: UM.Theme.getSize("default_margin").height
  64. }
  65. text: catalog.i18nc("@title:tab", "Add a printer to Cura")
  66. font.pointSize: 18
  67. }
  68. Label
  69. {
  70. id: captionLabel
  71. anchors
  72. {
  73. left: parent.left
  74. top: titleLabel.bottom
  75. topMargin: UM.Theme.getSize("default_margin").height
  76. }
  77. text: catalog.i18nc("@title:tab", "Select the printer you want to use from the list below.\n\nIf your printer is not in the list, use the \"Custom FFF Printer\" from the \"Custom\" category and adjust the settings to match your printer in the next dialog.")
  78. width: parent.width
  79. wrapMode: Text.WordWrap
  80. }
  81. ScrollView
  82. {
  83. id: machinesHolder
  84. anchors
  85. {
  86. top: captionLabel.visible ? captionLabel.bottom : parent.top;
  87. topMargin: captionLabel.visible ? UM.Theme.getSize("default_margin").height : 0;
  88. bottom: addPrinterButton.top;
  89. bottomMargin: UM.Theme.getSize("default_margin").height
  90. }
  91. width: Math.round(parent.width * 0.45)
  92. frameVisible: true;
  93. Rectangle
  94. {
  95. parent: viewport
  96. anchors.fill: parent
  97. color: palette.light
  98. }
  99. ListView
  100. {
  101. id: machineList
  102. model: UM.DefinitionContainersModel
  103. {
  104. id: machineDefinitionsModel
  105. filter: { "visible": true }
  106. sectionProperty: "category"
  107. preferredSectionValue: preferredCategory
  108. }
  109. section.property: "section"
  110. section.delegate: Button
  111. {
  112. id: machineSectionButton
  113. text: section
  114. width: machineList.width
  115. style: ButtonStyle
  116. {
  117. background: Item
  118. {
  119. height: UM.Theme.getSize("standard_list_lineheight").height
  120. width: machineList.width
  121. }
  122. label: Label
  123. {
  124. anchors.left: parent.left
  125. anchors.leftMargin: UM.Theme.getSize("standard_arrow").width + UM.Theme.getSize("default_margin").width
  126. text: control.text
  127. color: palette.windowText
  128. font.bold: true
  129. UM.RecolorImage
  130. {
  131. id: downArrow
  132. anchors.verticalCenter: parent.verticalCenter
  133. anchors.right: parent.left
  134. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  135. width: UM.Theme.getSize("standard_arrow").width
  136. height: UM.Theme.getSize("standard_arrow").height
  137. sourceSize.height: width
  138. color: palette.windowText
  139. source: base.activeCategory == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  140. }
  141. }
  142. }
  143. onClicked:
  144. {
  145. base.activeCategory = section;
  146. if (machineList.model.getItem(machineList.currentIndex).section != section)
  147. {
  148. // Find the first machine from this section
  149. for(var i = 0; i < machineList.model.count; i++)
  150. {
  151. var item = machineList.model.getItem(i);
  152. if (item.section == section)
  153. {
  154. machineList.currentIndex = i;
  155. break;
  156. }
  157. }
  158. }
  159. machineName.text = getMachineName();
  160. }
  161. }
  162. delegate: RadioButton
  163. {
  164. id: machineButton
  165. anchors.left: parent.left
  166. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  167. opacity: 1;
  168. height: UM.Theme.getSize("standard_list_lineheight").height;
  169. checked: ListView.isCurrentItem;
  170. exclusiveGroup: printerGroup;
  171. text: model.name
  172. onClicked:
  173. {
  174. ListView.view.currentIndex = index;
  175. machineName.text = getMachineName()
  176. }
  177. states: State
  178. {
  179. name: "collapsed";
  180. when: base.activeCategory != model.section;
  181. PropertyChanges { target: machineButton; opacity: 0; height: 0; }
  182. }
  183. }
  184. }
  185. }
  186. Column
  187. {
  188. anchors
  189. {
  190. top: machinesHolder.top
  191. left: machinesHolder.right
  192. right: parent.right
  193. leftMargin: UM.Theme.getSize("default_margin").width
  194. }
  195. spacing: UM.Theme.getSize("default_margin").height
  196. Label
  197. {
  198. width: parent.width
  199. wrapMode: Text.WordWrap
  200. text: getMachineName()
  201. font.pointSize: 16
  202. elide: Text.ElideRight
  203. }
  204. Grid
  205. {
  206. width: parent.width
  207. columns: 2
  208. rowSpacing: UM.Theme.getSize("default_lining").height
  209. columnSpacing: UM.Theme.getSize("default_margin").width
  210. verticalItemAlignment: Grid.AlignVCenter
  211. Label
  212. {
  213. wrapMode: Text.WordWrap
  214. text: catalog.i18nc("@label", "Manufacturer")
  215. }
  216. Label
  217. {
  218. width: Math.floor(parent.width * 0.65)
  219. wrapMode: Text.WordWrap
  220. text: getMachineMetaDataEntry("manufacturer")
  221. }
  222. Label
  223. {
  224. wrapMode: Text.WordWrap
  225. text: catalog.i18nc("@label", "Author")
  226. }
  227. Label
  228. {
  229. width: Math.floor(parent.width * 0.75)
  230. wrapMode: Text.WordWrap
  231. text: getMachineMetaDataEntry("author")
  232. }
  233. Label
  234. {
  235. wrapMode: Text.WordWrap
  236. text: catalog.i18nc("@label", "Printer Name")
  237. }
  238. TextField
  239. {
  240. id: machineName
  241. text: getMachineName()
  242. width: Math.floor(parent.width * 0.75)
  243. maximumLength: 40
  244. //validator: Cura.MachineNameValidator { } //TODO: Gives a segfault in PyQt5.6. For now, we must use a signal on text changed.
  245. validator: RegExpValidator
  246. {
  247. regExp: {
  248. machineName.machine_name_validator.machineNameRegex
  249. }
  250. }
  251. property var machine_name_validator: Cura.MachineNameValidator { }
  252. }
  253. }
  254. }
  255. Button
  256. {
  257. id: addPrinterButton
  258. text: catalog.i18nc("@action:button", "Add Printer")
  259. anchors.bottom: parent.bottom
  260. anchors.right: parent.right
  261. onClicked: addMachine()
  262. }
  263. onAccepted: addMachine()
  264. function addMachine()
  265. {
  266. base.visible = false
  267. var item = machineList.model.getItem(machineList.currentIndex);
  268. Cura.MachineManager.addMachine(machineName.text, item.id)
  269. base.machineAdded(item.id) // Emit signal that the user added a machine.
  270. }
  271. Item
  272. {
  273. UM.I18nCatalog
  274. {
  275. id: catalog;
  276. name: "cura";
  277. }
  278. SystemPalette { id: palette }
  279. ExclusiveGroup { id: printerGroup; }
  280. }
  281. }