SettingVisibilityPage.qml 5.7 KB

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