ViewsSelector.qml 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.2 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. Label
  39. {
  40. id: title
  41. text: catalog.i18nc("@label", "View type")
  42. verticalAlignment: Text.AlignVCenter
  43. height: parent.height
  44. elide: Text.ElideRight
  45. font: UM.Theme.getFont("medium")
  46. color: UM.Theme.getColor("text_medium")
  47. renderType: Text.NativeRendering
  48. }
  49. Label
  50. {
  51. text: viewSelector.activeView ? viewSelector.activeView.name : ""
  52. verticalAlignment: Text.AlignVCenter
  53. anchors
  54. {
  55. left: title.right
  56. leftMargin: UM.Theme.getSize("default_margin").width
  57. right: parent.right
  58. }
  59. height: parent.height
  60. elide: Text.ElideRight
  61. font: UM.Theme.getFont("medium")
  62. color: UM.Theme.getColor("text")
  63. renderType: Text.NativeRendering
  64. }
  65. }
  66. contentItem: Column
  67. {
  68. id: viewSelectorPopup
  69. width: viewSelector.width - 2 * viewSelector.contentPadding
  70. // For some reason the height/width of the column gets set to 0 if this is not set...
  71. Component.onCompleted:
  72. {
  73. height = implicitHeight
  74. width = viewSelector.width - 2 * viewSelector.contentPadding
  75. }
  76. Repeater
  77. {
  78. id: viewsList
  79. model: viewSelector.viewModel
  80. delegate: Button
  81. {
  82. id: viewsSelectorButton
  83. text: model.name
  84. width: parent.width - viewSelectorPopup.leftPadding - viewSelectorPopup.rightPadding
  85. height: UM.Theme.getSize("action_button").height
  86. leftPadding: UM.Theme.getSize("default_margin").width
  87. rightPadding: UM.Theme.getSize("default_margin").width
  88. checkable: true
  89. checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false
  90. contentItem: Label
  91. {
  92. id: buttonText
  93. text: viewsSelectorButton.text
  94. color: UM.Theme.getColor("text")
  95. font: UM.Theme.getFont("medium")
  96. renderType: Text.NativeRendering
  97. verticalAlignment: Text.AlignVCenter
  98. elide: Text.ElideRight
  99. }
  100. background: Rectangle
  101. {
  102. id: backgroundRect
  103. color: viewsSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  104. radius: UM.Theme.getSize("action_button_radius").width
  105. border.width: UM.Theme.getSize("default_lining").width
  106. border.color: viewsSelectorButton.checked ? UM.Theme.getColor("primary") : "transparent"
  107. }
  108. onClicked:
  109. {
  110. toggleContent()
  111. UM.Controller.setActiveView(id)
  112. }
  113. }
  114. }
  115. }
  116. }