ViewsSelector.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. property var activeView:
  14. {
  15. for (var i = 0; i < viewModel.count; i++)
  16. {
  17. if (viewModel.items[i].active)
  18. {
  19. return viewModel.items[i]
  20. }
  21. }
  22. return null
  23. }
  24. Component.onCompleted:
  25. {
  26. // Nothing was active, so just return the first one (the list is sorted by priority, so the most
  27. // important one should be returned)
  28. if (activeView == null)
  29. {
  30. UM.Controller.setActiveView(viewModel.getItem(0).id)
  31. }
  32. }
  33. headerItem: Item
  34. {
  35. Label
  36. {
  37. id: title
  38. text: catalog.i18nc("@button", "View types")
  39. verticalAlignment: Text.AlignVCenter
  40. height: parent.height
  41. elide: Text.ElideRight
  42. font: UM.Theme.getFont("default")
  43. color: UM.Theme.getColor("text_medium")
  44. renderType: Text.NativeRendering
  45. }
  46. Label
  47. {
  48. text: viewSelector.activeView ? viewSelector.activeView.name : ""
  49. verticalAlignment: Text.AlignVCenter
  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("default")
  59. color: UM.Theme.getColor("text")
  60. renderType: Text.NativeRendering
  61. }
  62. }
  63. contentItem: Column
  64. {
  65. id: viewSelectorPopup
  66. width: viewSelector.width - 2 * viewSelector.contentPadding
  67. leftPadding: UM.Theme.getSize("default_lining").width
  68. rightPadding: UM.Theme.getSize("default_lining").width
  69. // For some reason the height/width of the column gets set to 0 if this is not set...
  70. Component.onCompleted:
  71. {
  72. height = implicitHeight
  73. width = viewSelector.width - 2 * viewSelector.contentPadding
  74. }
  75. Repeater
  76. {
  77. id: viewsList
  78. model: viewSelector.viewModel
  79. delegate: Button
  80. {
  81. id: viewsSelectorButton
  82. text: model.name
  83. width: parent.width - viewSelectorPopup.leftPadding - viewSelectorPopup.rightPadding
  84. height: UM.Theme.getSize("action_button").height
  85. leftPadding: UM.Theme.getSize("default_margin").width
  86. rightPadding: UM.Theme.getSize("default_margin").width
  87. checkable: true
  88. checked: viewSelector.activeView != null ? viewSelector.activeView.id == id : false
  89. contentItem: Label
  90. {
  91. id: buttonText
  92. text: viewsSelectorButton.text
  93. color: UM.Theme.getColor("text")
  94. font: UM.Theme.getFont("medium")
  95. renderType: Text.NativeRendering
  96. verticalAlignment: Text.AlignVCenter
  97. elide: Text.ElideRight
  98. }
  99. background: Rectangle
  100. {
  101. id: backgroundRect
  102. color: viewsSelectorButton.hovered ? UM.Theme.getColor("action_button_hovered") : "transparent"
  103. radius: UM.Theme.getSize("action_button_radius").width
  104. border.width: UM.Theme.getSize("default_lining").width
  105. border.color: viewsSelectorButton.checked ? UM.Theme.getColor("primary") : "transparent"
  106. }
  107. onClicked:
  108. {
  109. toggleContent()
  110. UM.Controller.setActiveView(id)
  111. }
  112. }
  113. }
  114. }
  115. }