ApplicationViews.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. import "components"
  10. // This item contains the views selector, a combobox that is dinamically created from
  11. // the list of available Views (packages that create different visualizactions of the
  12. // scene. Aside the selector, there is a row of buttons that change the orientation of the view.
  13. Item
  14. {
  15. id: applicationViewsSelector
  16. height: UM.Theme.getSize("views_selector").height
  17. OrientationViews
  18. {
  19. id: orientationViews
  20. anchors {
  21. verticalCenter: parent.verticalCenter
  22. right: viewModeButton.left
  23. rightMargin: UM.Theme.getSize("default_margin").width
  24. }
  25. }
  26. ComboBox
  27. {
  28. id: viewModeButton
  29. anchors {
  30. verticalCenter: parent.verticalCenter
  31. right: parent.right
  32. rightMargin: UM.Theme.getSize("default_margin").width
  33. }
  34. style: UM.Theme.styles.combobox
  35. model: UM.ViewModel { }
  36. textRole: "name"
  37. // update the model's active index
  38. function updateItemActiveFlags ()
  39. {
  40. currentIndex = getActiveIndex()
  41. for (var i = 0; i < model.rowCount(); i++)
  42. {
  43. model.getItem(i).active = (i == currentIndex)
  44. }
  45. }
  46. // get the index of the active model item on start
  47. function getActiveIndex ()
  48. {
  49. for (var i = 0; i < model.rowCount(); i++)
  50. {
  51. if (model.getItem(i).active) {
  52. return i
  53. }
  54. }
  55. return 0
  56. }
  57. // set the active index
  58. function setActiveIndex (index)
  59. {
  60. UM.Controller.setActiveView(index)
  61. // the connection to UM.ActiveView will trigger update so there is no reason to call it manually here
  62. }
  63. onCurrentIndexChanged:
  64. {
  65. if (model.getItem(currentIndex).id != undefined)
  66. {
  67. viewModeButton.setActiveIndex(model.getItem(currentIndex).id)
  68. }
  69. }
  70. currentIndex: getActiveIndex()
  71. // watch the active view proxy for changes made from the menu item
  72. Connections
  73. {
  74. target: UM.ActiveView
  75. onActiveViewChanged: viewModeButton.updateItemActiveFlags()
  76. }
  77. }
  78. Loader
  79. {
  80. id: viewPanel
  81. anchors.top: viewModeButton.bottom
  82. anchors.topMargin: UM.Theme.getSize("default_margin").height
  83. anchors.right: viewModeButton.right
  84. property var buttonTarget: Qt.point(viewModeButton.x + Math.round(viewModeButton.width / 2), viewModeButton.y + Math.round(viewModeButton.height / 2))
  85. height: childrenRect.height
  86. width: childrenRect.width
  87. source: UM.ActiveView.valid ? UM.ActiveView.activeViewPanel : ""
  88. }
  89. }