SettingVisibilityPage.qml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 2.15
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. UM.PreferencesPage
  8. {
  9. title: catalog.i18nc("@title:tab", "Setting Visibility")
  10. Item { enabled: false; UM.I18nCatalog { id: catalog; name: "cura"} }
  11. property QtObject settingVisibilityPresetsModel: CuraApplication.getSettingVisibilityPresetsModel()
  12. property int scrollToIndex: 0
  13. buttons: [
  14. Cura.SecondaryButton
  15. {
  16. text: catalog.i18nc("@action:button", "Defaults")
  17. onClicked: reset()
  18. }
  19. ]
  20. signal scrollToSection( string key )
  21. onScrollToSection:
  22. {
  23. settingsListView.positionViewAtIndex(definitionsModel.getIndex(key), ListView.Beginning)
  24. }
  25. function reset()
  26. {
  27. settingVisibilityPresetsModel.setActivePreset("basic")
  28. }
  29. resetEnabled: true;
  30. Item
  31. {
  32. id: base
  33. anchors.fill: parent
  34. UM.CheckBox
  35. {
  36. id: toggleVisibleSettings
  37. anchors
  38. {
  39. verticalCenter: filter.verticalCenter
  40. left: parent.left
  41. leftMargin: UM.Theme.getSize("default_margin").width
  42. }
  43. text: catalog.i18nc("@label:textbox", "Check all")
  44. checkState:
  45. {
  46. if(definitionsModel.visibleCount == definitionsModel.categoryCount)
  47. {
  48. return Qt.Unchecked
  49. }
  50. else if(definitionsModel.visibleCount == definitionsModel.count)
  51. {
  52. return Qt.Checked
  53. }
  54. else
  55. {
  56. return Qt.PartiallyChecked
  57. }
  58. }
  59. tristate: true
  60. MouseArea
  61. {
  62. anchors.fill: parent;
  63. onClicked:
  64. {
  65. if (parent.checkState == Qt.Unchecked || parent.checkState == Qt.PartiallyChecked)
  66. {
  67. definitionsModel.setAllExpandedVisible(true)
  68. }
  69. else
  70. {
  71. definitionsModel.setAllExpandedVisible(false)
  72. }
  73. }
  74. }
  75. }
  76. Cura.TextField
  77. {
  78. id: filter
  79. anchors
  80. {
  81. top: parent.top
  82. left: toggleVisibleSettings.right
  83. leftMargin: UM.Theme.getSize("default_margin").width
  84. right: visibilityPreset.left
  85. rightMargin: UM.Theme.getSize("default_margin").width
  86. }
  87. placeholderText: catalog.i18nc("@label:textbox", "Filter...")
  88. onTextChanged: definitionsModel.filter = {"i18n_label|i18n_description": "*" + text}
  89. }
  90. Cura.ComboBox
  91. {
  92. id: visibilityPreset
  93. width: UM.Theme.getSize("action_button").width
  94. anchors
  95. {
  96. top: parent.top
  97. right: parent.right
  98. verticalCenter: filter.verticalCenter
  99. }
  100. model: settingVisibilityPresetsModel.items
  101. textRole: "name"
  102. currentIndex:
  103. {
  104. var idx = -1;
  105. for(var i = 0; i < settingVisibilityPresetsModel.items.length; ++i)
  106. {
  107. if(settingVisibilityPresetsModel.items[i].presetId == settingVisibilityPresetsModel.activePreset)
  108. {
  109. idx = i;
  110. break;
  111. }
  112. }
  113. return idx;
  114. }
  115. onActivated:
  116. {
  117. var preset_id = settingVisibilityPresetsModel.items[index].presetId
  118. settingVisibilityPresetsModel.setActivePreset(preset_id)
  119. }
  120. }
  121. ListView
  122. {
  123. id: settingsListView
  124. anchors
  125. {
  126. top: filter.bottom
  127. topMargin: UM.Theme.getSize("default_margin").height
  128. left: parent.left
  129. right: parent.right
  130. bottom: parent.bottom
  131. }
  132. clip: true
  133. ScrollBar.vertical: UM.ScrollBar { id: scrollBar }
  134. model: UM.SettingDefinitionsModel
  135. {
  136. id: definitionsModel
  137. containerId: Cura.MachineManager.activeMachine != null ? Cura.MachineManager.activeMachine.definition.id: ""
  138. showAll: true
  139. exclude: ["machine_settings", "command_line_settings"]
  140. showAncestors: true
  141. expanded: ["*"]
  142. visibilityHandler: UM.SettingPreferenceVisibilityHandler {}
  143. }
  144. property Component settingVisibilityCategory: Cura.SettingVisibilityCategory {}
  145. property Component settingVisibilityItem: Cura.SettingVisibilityItem {}
  146. delegate: Loader
  147. {
  148. id: loader
  149. width: settingsListView.width - scrollBar.width
  150. height: model.type != undefined ? UM.Theme.getSize("section").height : 0
  151. property var definition: model
  152. property var settingDefinitionsModel: definitionsModel
  153. asynchronous: true
  154. active: model.type != undefined
  155. sourceComponent:
  156. {
  157. switch (model.type)
  158. {
  159. case "category":
  160. return settingsListView.settingVisibilityCategory
  161. default:
  162. return settingsListView.settingVisibilityItem
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }