ApplicationViews.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.2
  4. import QtQuick.Controls 1.1
  5. import QtQuick.Controls.Styles 1.1
  6. import QtQuick.Layouts 1.1
  7. import UM 1.4 as UM
  8. import Cura 1.0 as Cura
  9. // This item contains the views selector, a combobox that is dynamically created from
  10. // the list of available Views (packages that create different visualizations of the
  11. // scene). Aside from the selector, there is a row of buttons that change the orientation of the view.
  12. Item
  13. {
  14. id: applicationViewsSelector
  15. height: UM.Theme.getSize("views_selector").height
  16. ComboBox
  17. {
  18. id: viewModeButton
  19. anchors
  20. {
  21. verticalCenter: parent.verticalCenter
  22. right: parent.right
  23. rightMargin: UM.Theme.getSize("default_margin").width
  24. }
  25. style: UM.Theme.styles.combobox
  26. model: UM.ViewModel { }
  27. textRole: "name"
  28. // update the model's active index
  29. function updateItemActiveFlags ()
  30. {
  31. currentIndex = getActiveIndex()
  32. for (var i = 0; i < model.rowCount(); i++)
  33. {
  34. model.getItem(i).active = (i == currentIndex)
  35. }
  36. }
  37. // get the index of the active model item on start
  38. function getActiveIndex ()
  39. {
  40. for (var i = 0; i < model.rowCount(); i++)
  41. {
  42. if (model.getItem(i).active)
  43. {
  44. return i;
  45. }
  46. }
  47. return 0
  48. }
  49. // set the active index
  50. function setActiveIndex(index)
  51. {
  52. UM.Controller.setActiveView(index)
  53. // the connection to UM.ActiveView will trigger update so there is no reason to call it manually here
  54. }
  55. onCurrentIndexChanged:
  56. {
  57. if (model.getItem(currentIndex).id != undefined)
  58. {
  59. viewModeButton.setActiveIndex(model.getItem(currentIndex).id)
  60. }
  61. }
  62. currentIndex: getActiveIndex()
  63. // watch the active view proxy for changes made from the menu item
  64. Connections
  65. {
  66. target: UM.ActiveView
  67. onActiveViewChanged: viewModeButton.updateItemActiveFlags()
  68. }
  69. }
  70. Loader
  71. {
  72. id: viewPanel
  73. anchors.top: viewModeButton.bottom
  74. anchors.topMargin: UM.Theme.getSize("default_margin").height
  75. anchors.right: viewModeButton.right
  76. property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2))
  77. height: childrenRect.height
  78. width: childrenRect.width
  79. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : ""
  80. }
  81. }