PreviewMenu.qml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import QtQuick 2.7
  2. import QtQuick.Controls 1.4
  3. import UM 1.3 as UM
  4. import Cura 1.1 as Cura
  5. Item
  6. {
  7. id: previewMenu
  8. // This widget doesn't show tooltips by itself. Instead it emits signals so others can do something with it.
  9. signal showTooltip(Item item, point location, string text)
  10. signal hideTooltip()
  11. UM.I18nCatalog
  12. {
  13. id: catalog
  14. name: "cura"
  15. }
  16. Row
  17. {
  18. anchors.horizontalCenter: parent.horizontalCenter
  19. spacing: UM.Theme.getSize("default_margin").width
  20. ComboBox
  21. {
  22. // This item contains the views selector, a combobox that is dynamically created from
  23. // the list of available Views (packages that create different visualizations of the
  24. // scene).
  25. id: viewModeButton
  26. style: UM.Theme.styles.combobox
  27. model: UM.ViewModel { }
  28. textRole: "name"
  29. // update the model's active index
  30. function updateItemActiveFlags()
  31. {
  32. currentIndex = getActiveIndex()
  33. for (var i = 0; i < model.rowCount(); i++)
  34. {
  35. model.getItem(i).active = (i == currentIndex)
  36. }
  37. }
  38. // get the index of the active model item on start
  39. function getActiveIndex()
  40. {
  41. for (var i = 0; i < model.rowCount(); i++)
  42. {
  43. if (model.getItem(i).active)
  44. {
  45. return i;
  46. }
  47. }
  48. return 0
  49. }
  50. onCurrentIndexChanged:
  51. {
  52. if (model.getItem(currentIndex).id != undefined)
  53. {
  54. UM.Controller.setActiveView(model.getItem(currentIndex).id)
  55. }
  56. }
  57. currentIndex: getActiveIndex()
  58. }
  59. Loader
  60. {
  61. // TODO: Make this panel collapsable and ensure it has a standardised background.
  62. id: viewPanel
  63. property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2))
  64. height: childrenRect.height
  65. width: childrenRect.width
  66. source: UM.Controller.activeView != null && UM.Controller.activeView.stageMenuComponent != null ? UM.Controller.activeView.stageMenuComponent : ""
  67. }
  68. Cura.PrintSetupSelector
  69. {
  70. width: UM.Theme.getSize("print_setup_widget").width
  71. onShowTooltip: previewMenu.showTooltip(item, location, text)
  72. onHideTooltip: previewMenu.hideTooltip()
  73. }
  74. }
  75. }