AddMachineDialog.qml 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // Copyright (c) 2017 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.width: width
  138. sourceSize.height: width
  139. color: palette.windowText
  140. source: base.activeCategory == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  141. }
  142. }
  143. }
  144. onClicked:
  145. {
  146. base.activeCategory = section;
  147. if (machineList.model.getItem(machineList.currentIndex).section != section)
  148. {
  149. // Find the first machine from this section
  150. for(var i = 0; i < machineList.model.rowCount(); i++)
  151. {
  152. var item = machineList.model.getItem(i);
  153. if (item.section == section)
  154. {
  155. machineList.currentIndex = i;
  156. break;
  157. }
  158. }
  159. }
  160. machineName.text = getMachineName();
  161. }
  162. }
  163. delegate: RadioButton
  164. {
  165. id: machineButton
  166. anchors.left: parent.left
  167. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  168. opacity: 1;
  169. height: UM.Theme.getSize("standard_list_lineheight").height;
  170. checked: ListView.isCurrentItem;
  171. exclusiveGroup: printerGroup;
  172. text: model.name
  173. onClicked:
  174. {
  175. ListView.view.currentIndex = index;
  176. machineName.text = getMachineName()
  177. }
  178. states: State
  179. {
  180. name: "collapsed";
  181. when: base.activeCategory != model.section;
  182. PropertyChanges { target: machineButton; opacity: 0; height: 0; }
  183. }
  184. }
  185. }
  186. }
  187. Column
  188. {
  189. anchors
  190. {
  191. top: machinesHolder.top
  192. left: machinesHolder.right
  193. right: parent.right
  194. leftMargin: UM.Theme.getSize("default_margin").width
  195. }
  196. spacing: UM.Theme.getSize("default_margin").height
  197. Label
  198. {
  199. width: parent.width
  200. wrapMode: Text.WordWrap
  201. text: getMachineName()
  202. font.pointSize: 16
  203. elide: Text.ElideRight
  204. }
  205. Grid
  206. {
  207. width: parent.width
  208. columns: 2
  209. rowSpacing: UM.Theme.getSize("default_lining").height
  210. columnSpacing: UM.Theme.getSize("default_margin").width
  211. verticalItemAlignment: Grid.AlignVCenter
  212. Label
  213. {
  214. wrapMode: Text.WordWrap
  215. text: catalog.i18nc("@label", "Manufacturer")
  216. }
  217. Label
  218. {
  219. width: Math.floor(parent.width * 0.65)
  220. wrapMode: Text.WordWrap
  221. text: getMachineMetaDataEntry("manufacturer")
  222. }
  223. Label
  224. {
  225. wrapMode: Text.WordWrap
  226. text: catalog.i18nc("@label", "Author")
  227. }
  228. Label
  229. {
  230. width: Math.floor(parent.width * 0.75)
  231. wrapMode: Text.WordWrap
  232. text: getMachineMetaDataEntry("author")
  233. }
  234. Label
  235. {
  236. wrapMode: Text.WordWrap
  237. text: catalog.i18nc("@label", "Printer Name")
  238. }
  239. TextField
  240. {
  241. id: machineName
  242. text: getMachineName()
  243. width: Math.floor(parent.width * 0.75)
  244. maximumLength: 40
  245. //validator: Cura.MachineNameValidator { } //TODO: Gives a segfault in PyQt5.6. For now, we must use a signal on text changed.
  246. validator: RegExpValidator
  247. {
  248. regExp: {
  249. machineName.machine_name_validator.machineNameRegex
  250. }
  251. }
  252. property var machine_name_validator: Cura.MachineNameValidator { }
  253. }
  254. }
  255. }
  256. Button
  257. {
  258. id: addPrinterButton
  259. text: catalog.i18nc("@action:button", "Add Printer")
  260. anchors.bottom: parent.bottom
  261. anchors.right: parent.right
  262. onClicked: addMachine()
  263. }
  264. onAccepted: addMachine()
  265. function addMachine()
  266. {
  267. base.visible = false
  268. var item = machineList.model.getItem(machineList.currentIndex);
  269. Cura.MachineManager.addMachine(machineName.text, item.id)
  270. base.machineAdded(item.id) // Emit signal that the user added a machine.
  271. }
  272. Item
  273. {
  274. UM.I18nCatalog
  275. {
  276. id: catalog;
  277. name: "cura";
  278. }
  279. SystemPalette { id: palette }
  280. ExclusiveGroup { id: printerGroup; }
  281. }
  282. }