PreviewMenu.qml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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.4
  5. import UM 1.3 as UM
  6. import Cura 1.1 as Cura
  7. Item
  8. {
  9. id: previewMenu
  10. // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
  11. signal showTooltip(Item item, point location, string text)
  12. signal hideTooltip()
  13. property real itemHeight: height - 2 * UM.Theme.getSize("default_lining").width
  14. UM.I18nCatalog
  15. {
  16. id: catalog
  17. name: "cura"
  18. }
  19. Rectangle
  20. {
  21. anchors.fill: stageMenu
  22. anchors.leftMargin: -radius
  23. radius: UM.Theme.getSize("default_radius").width
  24. color: UM.Theme.getColor("toolbar_background")
  25. }
  26. Item
  27. {
  28. id: stageMenu
  29. height: parent.height
  30. width: childrenRect.width + UM.Theme.getSize("default_margin").width
  31. anchors.horizontalCenter: parent.horizontalCenter
  32. Row
  33. {
  34. anchors.centerIn: parent
  35. //spacing: UM.Theme.getSize("default_margin").width
  36. height: parent.height
  37. Cura.ExpandableComponent
  38. {
  39. id: viewSelector
  40. iconSource: expanded ? UM.Theme.getIcon("arrow_bottom") : UM.Theme.getIcon("arrow_left")
  41. height: parent.height
  42. property var viewModel: UM.ViewModel { }
  43. property var activeView:
  44. {
  45. for (var i = 0; i < viewModel.rowCount(); i++)
  46. {
  47. if(viewModel.getItem(i).active)
  48. {
  49. return viewModel.getItem(i)
  50. }
  51. }
  52. // Nothing was active, so just return the first one (the list is sorted by priority, so the most
  53. // important one sshould be returned)
  54. return viewModel.getItem(0)
  55. }
  56. // Ensure that the controller is synced with whatever happend here.
  57. onActiveViewChanged: UM.Controller.setActiveView(activeView.id)
  58. headerItem: Label
  59. {
  60. text: viewSelector.activeView.name
  61. verticalAlignment: Text.AlignVCenter
  62. height: parent.height
  63. elide: Text.ElideRight
  64. font: UM.Theme.getFont("default")
  65. }
  66. popupItem: Column
  67. {
  68. id: column
  69. width: viewSelector.width - 2 * UM.Theme.getSize("default_margin").width
  70. // For some reason the height of the column gets set to 0 if this is not set...
  71. Component.onCompleted: height = implicitHeight
  72. Repeater
  73. {
  74. id: networkedPrinters
  75. model: viewSelector.viewModel
  76. RoundButton
  77. {
  78. text: name
  79. radius: UM.Theme.getSize("default_radius").width
  80. checkable: true
  81. checked: active
  82. onClicked: UM.Controller.setActiveView(id)
  83. }
  84. }
  85. }
  86. }
  87. // Separator line
  88. Rectangle
  89. {
  90. height: parent.height
  91. // If there is no viewPanel, we only need a single spacer, so hide this one.
  92. visible: viewPanel.source != ""
  93. width: visible ? UM.Theme.getSize("default_lining").width : 0
  94. color: UM.Theme.getColor("lining")
  95. }
  96. Loader
  97. {
  98. // TODO: Make this panel collapsable and ensure it has a standardised background.
  99. id: viewPanel
  100. //property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2))
  101. height: parent.height
  102. width: childrenRect.width
  103. source: UM.Controller.activeView != null && UM.Controller.activeView.stageMenuComponent != null ? UM.Controller.activeView.stageMenuComponent : ""
  104. }
  105. // Separator line
  106. Rectangle
  107. {
  108. height: parent.height
  109. width: UM.Theme.getSize("default_lining").width
  110. color: UM.Theme.getColor("lining")
  111. }
  112. Cura.PrintSetupSelector
  113. {
  114. width: UM.Theme.getSize("print_setup_widget").width
  115. height: parent.height
  116. onShowTooltip: previewMenu.showTooltip(item, location, text)
  117. onHideTooltip: previewMenu.hideTooltip()
  118. }
  119. }
  120. }
  121. }