ProfileSetup.qml 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. // Copyright (c) 2015 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.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.1 as UM
  8. Item{
  9. id: base;
  10. UM.I18nCatalog { id: catalog; name:"cura"}
  11. property int totalHeightProfileSetup: childrenRect.height
  12. property Action manageProfilesAction
  13. property Action addProfileAction
  14. property Action updateProfileAction
  15. property Action resetProfileAction
  16. signal showTooltip(Item item, point location, string text)
  17. signal hideTooltip()
  18. Rectangle{
  19. id: globalProfileRow
  20. anchors.top: base.top
  21. height: UM.Theme.getSize("sidebar_setup").height
  22. width: base.width
  23. Label{
  24. id: globalProfileLabel
  25. anchors.left: parent.left
  26. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  27. anchors.verticalCenter: parent.verticalCenter
  28. text: catalog.i18nc("@label","Profile:");
  29. width: parent.width/100*45
  30. font: UM.Theme.getFont("default");
  31. color: UM.Theme.getColor("text");
  32. }
  33. ToolButton {
  34. property int rightMargin: customisedSettings.visible ? customisedSettings.width + UM.Theme.getSize("default_margin").width / 2 : 0
  35. id: globalProfileSelection
  36. text: UM.MachineManager.activeProfile
  37. width: parent.width/100*55
  38. height: UM.Theme.getSize("setting_control").height
  39. anchors.right: parent.right
  40. anchors.rightMargin: UM.Theme.getSize("default_margin").width
  41. anchors.verticalCenter: parent.verticalCenter
  42. tooltip: UM.MachineManager.activeProfile
  43. style: UM.Theme.styles.sidebar_header_button
  44. menu: Menu
  45. {
  46. id: profileSelectionMenu
  47. Instantiator
  48. {
  49. id: profileSelectionInstantiator
  50. // model: UM.ProfilesModel {}
  51. property int separatorIndex: -1
  52. Loader {
  53. property QtObject model_data: model
  54. property int model_index: index
  55. sourceComponent: menuItemDelegate
  56. }
  57. onObjectAdded:
  58. {
  59. //Insert a separator between readonly and custom profiles
  60. if(separatorIndex < 0 && index > 0) {
  61. if(model.getItem(index-1).readOnly != model.getItem(index).readOnly) {
  62. profileSelectionMenu.insertSeparator(index);
  63. separatorIndex = index;
  64. }
  65. }
  66. //Because of the separator, custom profiles move one index lower
  67. profileSelectionMenu.insertItem((model.getItem(index).readOnly) ? index : index + 1, object.item);
  68. }
  69. onObjectRemoved:
  70. {
  71. //When adding a profile, the menu is rebuild by removing all items.
  72. //If a separator was added, we need to remove that too.
  73. if(separatorIndex >= 0)
  74. {
  75. profileSelectionMenu.removeItem(profileSelectionMenu.items[separatorIndex])
  76. separatorIndex = -1;
  77. }
  78. profileSelectionMenu.removeItem(object.item);
  79. }
  80. }
  81. ExclusiveGroup { id: profileSelectionMenuGroup; }
  82. Component
  83. {
  84. id: menuItemDelegate
  85. MenuItem
  86. {
  87. id: item
  88. text: model_data ? model_data.name : ""
  89. checkable: true;
  90. checked: model_data ? model_data.active : false;
  91. exclusiveGroup: profileSelectionMenuGroup;
  92. onTriggered:
  93. {
  94. UM.MachineManager.setActiveProfile(model_data.name);
  95. if (!model_data.active) {
  96. //Selecting a profile was canceled; undo menu selection
  97. profileSelectionInstantiator.model.setProperty(model_index, "active", false);
  98. var activeProfileName = UM.MachineManager.activeProfile;
  99. var activeProfileIndex = profileSelectionInstantiator.model.find("name", activeProfileName);
  100. profileSelectionInstantiator.model.setProperty(activeProfileIndex, "active", true);
  101. }
  102. }
  103. }
  104. }
  105. MenuSeparator { }
  106. MenuItem {
  107. action: base.updateProfileAction;
  108. }
  109. MenuItem {
  110. action: base.resetProfileAction;
  111. }
  112. MenuItem {
  113. action: base.addProfileAction;
  114. }
  115. MenuSeparator { }
  116. MenuItem {
  117. action: base.manageProfilesAction;
  118. }
  119. }
  120. }
  121. UM.SimpleButton {
  122. id: customisedSettings
  123. visible: UM.ActiveProfile.hasCustomisedValues
  124. height: parent.height * 0.6
  125. width: parent.height * 0.6
  126. anchors.verticalCenter: parent.verticalCenter
  127. anchors.right: parent.right
  128. anchors.rightMargin: UM.Theme.getSize("setting_preferences_button_margin").width
  129. color: hovered ? UM.Theme.getColor("setting_control_button_hover") : UM.Theme.getColor("setting_control_button");
  130. iconSource: UM.Theme.getIcon("star");
  131. onClicked: base.manageProfilesAction.trigger()
  132. onEntered:
  133. {
  134. var content = catalog.i18nc("@tooltip","Some setting values are different from the values stored in the profile.\n\nClick to open the profile manager.")
  135. base.showTooltip(globalProfileRow, Qt.point(0, globalProfileRow.height / 2), content)
  136. }
  137. onExited: base.hideTooltip()
  138. }
  139. }
  140. }