RecommendedResolutionSelector.qml 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import UM 1.6 as UM
  5. import Cura 1.7 as Cura
  6. Item
  7. {
  8. id: recommendedResolutionSelector
  9. height: childrenRect.height
  10. property real labelColumnWidth: Math.round(width / 3)
  11. property string _previousResolution: "" //Internal variable to detect changes.
  12. Component.onCompleted: _previousResolution = Cura.MachineManager.activeQualityType;
  13. visible: visibilityPreset.count > 0 //Only show if there are quality types to select from.
  14. Cura.IconWithText
  15. {
  16. id: resolutionTitle
  17. anchors.top: parent.top
  18. anchors.left: parent.left
  19. anchors.leftMargin: - UM.Theme.getSize("thick_lining").width
  20. source: UM.Theme.getIcon("PrintQuality")
  21. text: catalog.i18nc("@label", "Resolution")
  22. width: labelColumnWidth
  23. height: parent.height
  24. spacing: UM.Theme.getSize("thick_margin").width
  25. iconSize: UM.Theme.getSize("medium_button_icon").width
  26. }
  27. Cura.ComboBox
  28. {
  29. id: visibilityPreset
  30. implicitHeight: UM.Theme.getSize("combobox").height
  31. implicitWidth: UM.Theme.getSize("combobox").width
  32. anchors
  33. {
  34. top: parent.top
  35. right: parent.right
  36. }
  37. textRole: "display_text"
  38. textFormat: Text.StyledText
  39. model: Cura.ActiveIntentQualitiesModel{}
  40. currentIndex:
  41. {
  42. var current_quality_type = Cura.MachineManager.activeQualityType
  43. var index = 0
  44. for (var i = 0; i < model.count; i++)
  45. {
  46. if (model.getItem(i).quality_type == current_quality_type)
  47. {
  48. index = i
  49. break
  50. }
  51. }
  52. return index
  53. }
  54. onActivated:
  55. {
  56. var selected_item = model.getItem(currentIndex)
  57. Cura.IntentManager.selectIntent(selected_item.intent_category, selected_item.quality_type)
  58. if (Cura.IntentManager.currentIntentCategory == selected_item.intent_category)
  59. {
  60. recommendedResolutionSelector._previousResolution = selected_item.quality_type;
  61. }
  62. }
  63. Connections
  64. {
  65. target: Cura.IntentManager
  66. function onIntentCategoryChanged()
  67. {
  68. if(recommendedResolutionSelector._previousResolution !== Cura.MachineManager.activeQualityType)
  69. {
  70. visibilityPreset.pulse();
  71. }
  72. recommendedResolutionSelector._previousResolution = Cura.MachineManager.activeQualityType;
  73. }
  74. }
  75. }
  76. }