AddMachineDialog.qml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. var window_flags = Qt.Dialog | Qt.CustomizeWindowHint | Qt.WindowTitleHint;
  23. if (Cura.MachineManager.activeDefinitionId !== "") //Disallow closing the window if we have no active printer yet. You MUST add a printer.
  24. {
  25. window_flags |= Qt.WindowCloseButtonHint;
  26. }
  27. return window_flags;
  28. }
  29. onVisibilityChanged:
  30. {
  31. // Reset selection and machine name
  32. if (visible) {
  33. activeCategory = preferredCategory;
  34. machineList.currentIndex = 0;
  35. machineName.text = getMachineName();
  36. }
  37. }
  38. signal machineAdded(string id)
  39. function getMachineName()
  40. {
  41. var name = machineList.model.getItem(machineList.currentIndex) != undefined ? machineList.model.getItem(machineList.currentIndex).name : ""
  42. return name
  43. }
  44. ScrollView
  45. {
  46. id: machinesHolder
  47. anchors
  48. {
  49. left: parent.left;
  50. top: parent.top;
  51. right: parent.right;
  52. bottom: machineNameRow.top;
  53. bottomMargin: UM.Theme.getSize("default_margin").height
  54. }
  55. ListView
  56. {
  57. id: machineList
  58. model: UM.DefinitionContainersModel
  59. {
  60. id: machineDefinitionsModel
  61. filter: { "visible": true }
  62. sectionProperty: "category"
  63. preferredSectionValue: preferredCategory
  64. }
  65. section.property: "section"
  66. section.delegate: Button
  67. {
  68. id: machineSectionButton
  69. text: section
  70. width: machineList.width
  71. style: ButtonStyle
  72. {
  73. background: Item
  74. {
  75. height: UM.Theme.getSize("standard_list_lineheight").height
  76. width: machineList.width
  77. }
  78. label: Label
  79. {
  80. anchors.left: parent.left
  81. anchors.leftMargin: UM.Theme.getSize("standard_arrow").width + UM.Theme.getSize("default_margin").width
  82. text: control.text
  83. color: palette.windowText
  84. font.bold: true
  85. UM.RecolorImage
  86. {
  87. id: downArrow
  88. anchors.verticalCenter: parent.verticalCenter
  89. anchors.right: parent.left
  90. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  91. width: UM.Theme.getSize("standard_arrow").width
  92. height: UM.Theme.getSize("standard_arrow").height
  93. sourceSize.width: width
  94. sourceSize.height: width
  95. color: palette.windowText
  96. source: base.activeCategory == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  97. }
  98. }
  99. }
  100. onClicked:
  101. {
  102. base.activeCategory = section;
  103. if (machineList.model.getItem(machineList.currentIndex).section != section) {
  104. // Find the first machine from this section
  105. for(var i = 0; i < machineList.model.rowCount(); i++) {
  106. var item = machineList.model.getItem(i);
  107. if (item.section == section) {
  108. machineList.currentIndex = i;
  109. break;
  110. }
  111. }
  112. }
  113. machineName.text = getMachineName();
  114. }
  115. }
  116. delegate: RadioButton
  117. {
  118. id: machineButton
  119. anchors.left: parent.left
  120. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  121. opacity: 1;
  122. height: UM.Theme.getSize("standard_list_lineheight").height;
  123. checked: ListView.isCurrentItem;
  124. exclusiveGroup: printerGroup;
  125. text: model.name
  126. onClicked:
  127. {
  128. ListView.view.currentIndex = index;
  129. machineName.text = getMachineName()
  130. }
  131. states: State
  132. {
  133. name: "collapsed";
  134. when: base.activeCategory != model.section;
  135. PropertyChanges { target: machineButton; opacity: 0; height: 0; }
  136. }
  137. transitions:
  138. [
  139. Transition
  140. {
  141. to: "collapsed";
  142. SequentialAnimation
  143. {
  144. NumberAnimation { property: "opacity"; duration: 75; }
  145. NumberAnimation { property: "height"; duration: 75; }
  146. }
  147. },
  148. Transition
  149. {
  150. from: "collapsed";
  151. SequentialAnimation
  152. {
  153. NumberAnimation { property: "height"; duration: 75; }
  154. NumberAnimation { property: "opacity"; duration: 75; }
  155. }
  156. }
  157. ]
  158. }
  159. }
  160. }
  161. Row
  162. {
  163. id: machineNameRow
  164. anchors.bottom:parent.bottom
  165. spacing: UM.Theme.getSize("default_margin").width
  166. Label
  167. {
  168. text: catalog.i18nc("@label", "Printer Name:")
  169. anchors.verticalCenter: machineName.verticalCenter
  170. }
  171. TextField
  172. {
  173. id: machineName
  174. text: getMachineName()
  175. implicitWidth: UM.Theme.getSize("standard_list_input").width
  176. maximumLength: 40
  177. //validator: Cura.MachineNameValidator { } //TODO: Gives a segfault in PyQt5.6. For now, we must use a signal on text changed.
  178. validator: RegExpValidator
  179. {
  180. regExp: {
  181. machineName.machine_name_validator.machineNameRegex
  182. }
  183. }
  184. property var machine_name_validator: Cura.MachineNameValidator { }
  185. }
  186. }
  187. Button
  188. {
  189. id: addPrinterButton
  190. text: catalog.i18nc("@action:button", "Add Printer")
  191. anchors.bottom: parent.bottom
  192. anchors.right: parent.right
  193. onClicked: addMachine()
  194. }
  195. onAccepted: addMachine()
  196. function addMachine()
  197. {
  198. base.visible = false
  199. var item = machineList.model.getItem(machineList.currentIndex);
  200. Cura.MachineManager.addMachine(machineName.text, item.id)
  201. base.machineAdded(item.id) // Emit signal that the user added a machine.
  202. }
  203. Item
  204. {
  205. UM.I18nCatalog
  206. {
  207. id: catalog;
  208. name: "cura";
  209. }
  210. SystemPalette { id: palette }
  211. ExclusiveGroup { id: printerGroup; }
  212. }
  213. }