AddMachineDialog.qml 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. text: section
  69. width: machineList.width
  70. style: ButtonStyle
  71. {
  72. background: Item
  73. {
  74. height: UM.Theme.getSize("standard_list_lineheight").height
  75. width: machineList.width
  76. }
  77. label: Label
  78. {
  79. anchors.left: parent.left
  80. anchors.leftMargin: UM.Theme.getSize("standard_arrow").width + UM.Theme.getSize("default_margin").width
  81. text: control.text
  82. color: palette.windowText
  83. font.bold: true
  84. UM.RecolorImage
  85. {
  86. id: downArrow
  87. anchors.verticalCenter: parent.verticalCenter
  88. anchors.right: parent.left
  89. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  90. width: UM.Theme.getSize("standard_arrow").width
  91. height: UM.Theme.getSize("standard_arrow").height
  92. sourceSize.width: width
  93. sourceSize.height: width
  94. color: palette.windowText
  95. source: base.activeCategory == section ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_right")
  96. }
  97. }
  98. }
  99. onClicked:
  100. {
  101. base.activeCategory = section;
  102. if (machineList.model.getItem(machineList.currentIndex).section != section) {
  103. // Find the first machine from this section
  104. for(var i = 0; i < machineList.model.rowCount(); i++) {
  105. var item = machineList.model.getItem(i);
  106. if (item.section == section) {
  107. machineList.currentIndex = i;
  108. break;
  109. }
  110. }
  111. }
  112. machineName.text = getMachineName();
  113. }
  114. }
  115. delegate: RadioButton
  116. {
  117. id: machineButton
  118. anchors.left: parent.left
  119. anchors.leftMargin: UM.Theme.getSize("standard_list_lineheight").width
  120. opacity: 1;
  121. height: UM.Theme.getSize("standard_list_lineheight").height;
  122. checked: ListView.isCurrentItem;
  123. exclusiveGroup: printerGroup;
  124. text: model.name
  125. onClicked:
  126. {
  127. ListView.view.currentIndex = index;
  128. machineName.text = getMachineName()
  129. }
  130. states: State
  131. {
  132. name: "collapsed";
  133. when: base.activeCategory != model.section;
  134. PropertyChanges { target: machineButton; opacity: 0; height: 0; }
  135. }
  136. transitions:
  137. [
  138. Transition
  139. {
  140. to: "collapsed";
  141. SequentialAnimation
  142. {
  143. NumberAnimation { property: "opacity"; duration: 75; }
  144. NumberAnimation { property: "height"; duration: 75; }
  145. }
  146. },
  147. Transition
  148. {
  149. from: "collapsed";
  150. SequentialAnimation
  151. {
  152. NumberAnimation { property: "height"; duration: 75; }
  153. NumberAnimation { property: "opacity"; duration: 75; }
  154. }
  155. }
  156. ]
  157. }
  158. }
  159. }
  160. Row
  161. {
  162. id: machineNameRow
  163. anchors.bottom:parent.bottom
  164. spacing: UM.Theme.getSize("default_margin").width
  165. Label
  166. {
  167. text: catalog.i18nc("@label", "Printer Name:")
  168. anchors.verticalCenter: machineName.verticalCenter
  169. }
  170. TextField
  171. {
  172. id: machineName
  173. text: getMachineName()
  174. implicitWidth: UM.Theme.getSize("standard_list_input").width
  175. maximumLength: 40
  176. //validator: Cura.MachineNameValidator { } //TODO: Gives a segfault in PyQt5.6. For now, we must use a signal on text changed.
  177. validator: RegExpValidator
  178. {
  179. regExp: {
  180. machineName.machine_name_validator.machineNameRegex
  181. }
  182. }
  183. property var machine_name_validator: Cura.MachineNameValidator { }
  184. }
  185. }
  186. Button
  187. {
  188. text: catalog.i18nc("@action:button", "Add Printer")
  189. anchors.bottom: parent.bottom
  190. anchors.right: parent.right
  191. onClicked: addMachine()
  192. }
  193. onAccepted: addMachine()
  194. function addMachine()
  195. {
  196. base.visible = false
  197. var item = machineList.model.getItem(machineList.currentIndex);
  198. Cura.MachineManager.addMachine(machineName.text, item.id)
  199. base.machineAdded(item.id) // Emit signal that the user added a machine.
  200. }
  201. Item
  202. {
  203. UM.I18nCatalog
  204. {
  205. id: catalog;
  206. name: "cura";
  207. }
  208. SystemPalette { id: palette }
  209. ExclusiveGroup { id: printerGroup; }
  210. }
  211. }