AddMachineDialog.qml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  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. transitions:
  185. [
  186. Transition
  187. {
  188. to: "collapsed";
  189. SequentialAnimation
  190. {
  191. NumberAnimation { property: "opacity"; duration: 75; }
  192. NumberAnimation { property: "height"; duration: 75; }
  193. }
  194. },
  195. Transition
  196. {
  197. from: "collapsed";
  198. SequentialAnimation
  199. {
  200. NumberAnimation { property: "height"; duration: 75; }
  201. NumberAnimation { property: "opacity"; duration: 75; }
  202. }
  203. }
  204. ]
  205. }
  206. }
  207. }
  208. Column
  209. {
  210. anchors
  211. {
  212. top: machinesHolder.top
  213. left: machinesHolder.right
  214. right: parent.right
  215. leftMargin: UM.Theme.getSize("default_margin").width
  216. }
  217. spacing: UM.Theme.getSize("default_margin").height
  218. Label
  219. {
  220. width: parent.width
  221. wrapMode: Text.WordWrap
  222. text: getMachineName()
  223. font.pointSize: 16
  224. elide: Text.ElideRight
  225. }
  226. Grid
  227. {
  228. width: parent.width
  229. columns: 2
  230. rowSpacing: UM.Theme.getSize("default_lining").height
  231. columnSpacing: UM.Theme.getSize("default_margin").width
  232. verticalItemAlignment: Grid.AlignVCenter
  233. Label
  234. {
  235. wrapMode: Text.WordWrap
  236. text: catalog.i18nc("@label", "Manufacturer")
  237. }
  238. Label
  239. {
  240. width: Math.floor(parent.width * 0.65)
  241. wrapMode: Text.WordWrap
  242. text: getMachineMetaDataEntry("manufacturer")
  243. }
  244. Label
  245. {
  246. wrapMode: Text.WordWrap
  247. text: catalog.i18nc("@label", "Author")
  248. }
  249. Label
  250. {
  251. width: Math.floor(parent.width * 0.75)
  252. wrapMode: Text.WordWrap
  253. text: getMachineMetaDataEntry("author")
  254. }
  255. Label
  256. {
  257. wrapMode: Text.WordWrap
  258. text: catalog.i18nc("@label", "Printer Name")
  259. }
  260. TextField
  261. {
  262. id: machineName
  263. text: getMachineName()
  264. width: Math.floor(parent.width * 0.75)
  265. implicitWidth: UM.Theme.getSize("standard_list_input").width
  266. maximumLength: 40
  267. //validator: Cura.MachineNameValidator { } //TODO: Gives a segfault in PyQt5.6. For now, we must use a signal on text changed.
  268. validator: RegExpValidator
  269. {
  270. regExp: {
  271. machineName.machine_name_validator.machineNameRegex
  272. }
  273. }
  274. property var machine_name_validator: Cura.MachineNameValidator { }
  275. }
  276. }
  277. }
  278. Button
  279. {
  280. id: addPrinterButton
  281. text: catalog.i18nc("@action:button", "Add Printer")
  282. anchors.bottom: parent.bottom
  283. anchors.right: parent.right
  284. onClicked: addMachine()
  285. }
  286. onAccepted: addMachine()
  287. function addMachine()
  288. {
  289. base.visible = false
  290. var item = machineList.model.getItem(machineList.currentIndex);
  291. Cura.MachineManager.addMachine(machineName.text, item.id)
  292. base.machineAdded(item.id) // Emit signal that the user added a machine.
  293. }
  294. Item
  295. {
  296. UM.I18nCatalog
  297. {
  298. id: catalog;
  299. name: "cura";
  300. }
  301. SystemPalette { id: palette }
  302. ExclusiveGroup { id: printerGroup; }
  303. }
  304. }