SettingVisibilityPage.qml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. // Copyright (c) 2016 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import UM 1.2 as UM
  7. import Cura 1.0 as Cura
  8. UM.PreferencesPage
  9. {
  10. title: catalog.i18nc("@title:tab", "Setting Visibility");
  11. property int scrollToIndex: 0
  12. signal scrollToSection( string key )
  13. onScrollToSection:
  14. {
  15. settingsListView.positionViewAtIndex(definitionsModel.getIndex(key), ListView.Beginning)
  16. }
  17. function reset()
  18. {
  19. UM.Preferences.resetPreference("general/visible_settings")
  20. // After calling this function update Setting visibility preset combobox.
  21. // Reset should set "Basic" setting preset
  22. visibilityPreset.setBasicPreset()
  23. }
  24. resetEnabled: true;
  25. Item
  26. {
  27. id: base;
  28. anchors.fill: parent;
  29. CheckBox
  30. {
  31. id: toggleVisibleSettings
  32. anchors
  33. {
  34. verticalCenter: filter.verticalCenter;
  35. left: parent.left;
  36. leftMargin: UM.Theme.getSize("default_margin").width
  37. }
  38. text: catalog.i18nc("@label:textbox", "Check all")
  39. checkedState:
  40. {
  41. if(definitionsModel.visibleCount == definitionsModel.categoryCount)
  42. {
  43. return Qt.Unchecked
  44. }
  45. else if(definitionsModel.visibleCount == definitionsModel.rowCount(null))
  46. {
  47. return Qt.Checked
  48. }
  49. else
  50. {
  51. return Qt.PartiallyChecked
  52. }
  53. }
  54. partiallyCheckedEnabled: true
  55. MouseArea
  56. {
  57. anchors.fill: parent;
  58. onClicked:
  59. {
  60. if(parent.checkedState == Qt.Unchecked || parent.checkedState == Qt.PartiallyChecked)
  61. {
  62. definitionsModel.setAllVisible(true)
  63. }
  64. else
  65. {
  66. definitionsModel.setAllVisible(false)
  67. }
  68. // After change set "Custom" option
  69. // If already "Custom" then don't do nothing
  70. if (visibilityPreset.currentIndex != visibilityPreset.model.count - 1)
  71. {
  72. visibilityPreset.currentIndex = visibilityPreset.model.count - 1
  73. UM.Preferences.setValue("general/preset_setting_visibility_choice", visibilityPreset.model.get(visibilityPreset.currentIndex).text)
  74. }
  75. }
  76. }
  77. }
  78. TextField
  79. {
  80. id: filter;
  81. anchors
  82. {
  83. top: parent.top
  84. left: toggleVisibleSettings.right
  85. leftMargin: UM.Theme.getSize("default_margin").width
  86. right: visibilityPreset.left
  87. rightMargin: UM.Theme.getSize("default_margin").width
  88. }
  89. placeholderText: catalog.i18nc("@label:textbox", "Filter...")
  90. onTextChanged: definitionsModel.filter = {"i18n_label": "*" + text}
  91. }
  92. ComboBox
  93. {
  94. property int customOptionValue: 100
  95. function setBasicPreset()
  96. {
  97. var index = 0
  98. for(var i = 0; i < presetNamesList.count; ++i)
  99. {
  100. if(model.get(i).text == "Basic")
  101. {
  102. index = i;
  103. break;
  104. }
  105. }
  106. visibilityPreset.currentIndex = index
  107. }
  108. id: visibilityPreset
  109. width: 150
  110. anchors
  111. {
  112. top: parent.top
  113. right: parent.right
  114. }
  115. model: ListModel
  116. {
  117. id: presetNamesList
  118. Component.onCompleted:
  119. {
  120. // returned value is Dictionary (Ex: {1:"Basic"}, The number 1 is the weight and sort by weight)
  121. var itemsDict = UM.Preferences.getValue("general/visible_settings_preset")
  122. var sorted = [];
  123. for(var key in itemsDict) {
  124. sorted[sorted.length] = key;
  125. }
  126. sorted.sort();
  127. for(var i = 0; i < sorted.length; i++) {
  128. presetNamesList.append({text: itemsDict[sorted[i]], value: i});
  129. }
  130. // By agreement lets "Custom" option will have value 100
  131. presetNamesList.append({text: "Custom", value: visibilityPreset.customOptionValue});
  132. }
  133. }
  134. currentIndex:
  135. {
  136. // Load previously selected preset.
  137. var text = UM.Preferences.getValue("general/preset_setting_visibility_choice");
  138. var index = 0;
  139. for(var i = 0; i < presetNamesList.count; ++i)
  140. {
  141. if(model.get(i).text == text)
  142. {
  143. index = i;
  144. break;
  145. }
  146. }
  147. return index;
  148. }
  149. onActivated:
  150. {
  151. // TODO What to do if user is selected "Custom from Combobox" ?
  152. if (model.get(index).text == "Custom"){
  153. UM.Preferences.setValue("general/preset_setting_visibility_choice", model.get(index).text)
  154. return
  155. }
  156. var newVisibleSettings = CuraApplication.getVisibilitySettingPreset(model.get(index).text)
  157. UM.Preferences.setValue("general/visible_settings", newVisibleSettings)
  158. UM.Preferences.setValue("general/preset_setting_visibility_choice", model.get(index).text)
  159. }
  160. }
  161. ScrollView
  162. {
  163. id: scrollView
  164. frameVisible: true
  165. anchors
  166. {
  167. top: filter.bottom;
  168. topMargin: UM.Theme.getSize("default_margin").height
  169. left: parent.left;
  170. right: parent.right;
  171. bottom: parent.bottom;
  172. }
  173. ListView
  174. {
  175. id: settingsListView
  176. model: UM.SettingDefinitionsModel
  177. {
  178. id: definitionsModel
  179. containerId: Cura.MachineManager.activeDefinitionId
  180. showAll: true
  181. exclude: ["machine_settings", "command_line_settings"]
  182. showAncestors: true
  183. expanded: ["*"]
  184. visibilityHandler: UM.SettingPreferenceVisibilityHandler { }
  185. }
  186. delegate: Loader
  187. {
  188. id: loader
  189. width: parent.width
  190. height: model.type != undefined ? UM.Theme.getSize("section").height : 0
  191. property var definition: model
  192. property var settingDefinitionsModel: definitionsModel
  193. asynchronous: true
  194. active: model.type != undefined
  195. sourceComponent:
  196. {
  197. switch(model.type)
  198. {
  199. case "category":
  200. return settingVisibilityCategory
  201. default:
  202. return settingVisibilityItem
  203. }
  204. }
  205. }
  206. }
  207. }
  208. UM.I18nCatalog { name: "cura"; }
  209. SystemPalette { id: palette; }
  210. Component
  211. {
  212. id: settingVisibilityCategory;
  213. UM.SettingVisibilityCategory { }
  214. }
  215. Component
  216. {
  217. id: settingVisibilityItem;
  218. UM.SettingVisibilityItem {
  219. // after changing any visibility of settings, set the preset to the "Custom" option
  220. visibilityChangeCallback : function()
  221. {
  222. // If already "Custom" then don't do nothing
  223. if (visibilityPreset.currentIndex != visibilityPreset.model.count - 1)
  224. {
  225. visibilityPreset.currentIndex = visibilityPreset.model.count - 1
  226. UM.Preferences.setValue("general/preset_setting_visibility_choice", visibilityPreset.model.get(visibilityPreset.currentIndex).text)
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }