AddMachineDialog.qml 7.4 KB

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