ViewsSelector.qml 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. import Cura 1.0 as Cura
  7. Cura.ExpandablePopup
  8. {
  9. id: viewSelector
  10. contentPadding: UM.Theme.getSize("default_lining").width
  11. contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
  12. property var viewModel: UM.ViewModel
  13. {
  14. onDataChanged: updateActiveView()
  15. }
  16. property var activeView: null
  17. function updateActiveView()
  18. {
  19. for (var index in viewModel.items)
  20. {
  21. if (viewModel.items[index].active)
  22. {
  23. activeView = viewModel.items[index]
  24. return
  25. }
  26. }
  27. activeView = null
  28. }
  29. Component.onCompleted:
  30. {
  31. if (activeView == null)
  32. {
  33. UM.Controller.setActiveView(viewModel.getItem(0).id)
  34. }
  35. }
  36. headerItem: Item
  37. {
  38. UM.Label
  39. {
  40. id: title
  41. text: catalog.i18nc("@label", "View type")
  42. height: parent.height
  43. elide: Text.ElideRight
  44. font: UM.Theme.getFont("medium")
  45. color: UM.Theme.getColor("text_medium")
  46. }
  47. UM.Label
  48. {
  49. text: viewSelector.activeView ? viewSelector.activeView.name : ""
  50. anchors
  51. {
  52. left: title.right
  53. leftMargin: UM.Theme.getSize("default_margin").width
  54. right: parent.right
  55. }
  56. height: parent.height
  57. elide: Text.ElideRight
  58. font: UM.Theme.getFont("medium")
  59. }
  60. }
  61. contentItem: Column
  62. {
  63. id: viewSelectorPopup
  64. width: viewSelector.width - 2 * viewSelector.contentPadding
  65. // For some reason the height/width of the column gets set to 0 if this is not set...
  66. Component.onCompleted:
  67. {
  68. height = implicitHeight
  69. width = viewSelector.width - 2 * viewSelector.contentPadding
  70. }
  71. Repeater
  72. {
  73. id: viewsList
  74. model: viewSelector.viewModel
  75. delegate: Button
  76. {
  77. id: viewsSelectorButton
  78. text: model.name
  79. width: parent.width - viewSelectorPopup.leftPadding - viewSelectorPopup.rightPadding
  80. height: UM.Theme.getSize("action_button").height
  81. leftPadding: UM.Theme.getSize("default_margin").width
  82. rightPadding: UM.Theme.getSize("default_margin").width
  83. checkable: true
  84. checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false
  85. contentItem: UM.Label
  86. {
  87. id: buttonText
  88. text: viewsSelectorButton.text
  89. font: UM.Theme.getFont("medium")
  90. elide: Text.ElideRight
  91. }
  92. background: Rectangle
  93. {
  94. id: backgroundRect
  95. color: viewsSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  96. radius: UM.Theme.getSize("action_button_radius").width
  97. border.width: UM.Theme.getSize("default_lining").width
  98. border.color: viewsSelectorButton.checked ? UM.Theme.getColor("primary") : "transparent"
  99. }
  100. onClicked:
  101. {
  102. toggleContent()
  103. UM.Controller.setActiveView(id)
  104. }
  105. }
  106. }
  107. }
  108. }