AddMachineDialog.qml 7.3 KB

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