ViewsSelector.qml 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. contentWidth: viewSelector.width - 2 * viewSelector.contentPadding
  62. contentItem: Column
  63. {
  64. id: viewSelectorPopup
  65. Repeater
  66. {
  67. id: viewsList
  68. model: viewSelector.viewModel
  69. delegate: Button
  70. {
  71. id: viewsSelectorButton
  72. text: model.name
  73. width: parent.width - viewSelectorPopup.leftPadding - viewSelectorPopup.rightPadding
  74. height: UM.Theme.getSize("action_button").height
  75. leftPadding: UM.Theme.getSize("default_margin").width
  76. rightPadding: UM.Theme.getSize("default_margin").width
  77. checkable: true
  78. checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false
  79. contentItem: UM.Label
  80. {
  81. id: buttonText
  82. text: viewsSelectorButton.text
  83. font: UM.Theme.getFont("medium")
  84. elide: Text.ElideRight
  85. }
  86. background: Rectangle
  87. {
  88. id: backgroundRect
  89. color: viewsSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  90. radius: UM.Theme.getSize("action_button_radius").width
  91. border.width: UM.Theme.getSize("default_lining").width
  92. border.color: viewsSelectorButton.checked ? UM.Theme.getColor("primary") : "transparent"
  93. }
  94. onClicked:
  95. {
  96. toggleContent()
  97. UM.Controller.setActiveView(id)
  98. }
  99. }
  100. }
  101. }
  102. }