Sidebar.qml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the AGPLv3 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.1 as UM
  8. Rectangle
  9. {
  10. id: base;
  11. property Action addMachineAction;
  12. property Action configureMachinesAction;
  13. property Action manageProfilesAction;
  14. color: UM.Theme.colors.sidebar;
  15. UM.I18nCatalog { id: catalog; name:"cura"}
  16. function showTooltip(item, position, text)
  17. {
  18. tooltip.text = text;
  19. position = item.mapToItem(base, position.x, position.y / 2);
  20. tooltip.show(position);
  21. }
  22. function hideTooltip()
  23. {
  24. tooltip.hide();
  25. }
  26. MouseArea
  27. {
  28. anchors.fill: parent
  29. acceptedButtons: Qt.AllButtons;
  30. onWheel:
  31. {
  32. wheel.accepted = true;
  33. }
  34. }
  35. SidebarHeader {
  36. id: header
  37. width: parent.width
  38. height: totalHeightHeader
  39. addMachineAction: base.addMachineAction;
  40. configureMachinesAction: base.configureMachinesAction;
  41. modesModel: modesListModel;
  42. currentModeIndex:
  43. {
  44. var index = parseInt(UM.Preferences.getValue("cura/active_mode"))
  45. if(index)
  46. {
  47. return index;
  48. }
  49. return 0;
  50. }
  51. onCurrentModeIndexChanged: UM.Preferences.setValue("cura/active_mode", currentModeIndex);
  52. }
  53. ProfileSetup {
  54. id: profileItem
  55. manageProfilesAction: base.manageProfilesAction
  56. anchors.top: header.bottom
  57. width: parent.width
  58. height: totalHeightProfileSetup
  59. }
  60. Loader
  61. {
  62. id: sidebarContents;
  63. anchors.bottom: saveButton.top
  64. anchors.top: profileItem.bottom
  65. anchors.left: base.left
  66. anchors.right: base.right
  67. source: modesListModel.get(header.currentModeIndex).file;
  68. property Item sidebar: base;
  69. onLoaded:
  70. {
  71. if(item)
  72. {
  73. item.configureSettings = base.configureMachinesAction;
  74. if(item.onShowTooltip != undefined)
  75. {
  76. item.showTooltip.connect(base.showTooltip)
  77. }
  78. if(item.onHideTooltip != undefined)
  79. {
  80. item.hideTooltip.connect(base.hideTooltip)
  81. }
  82. }
  83. }
  84. }
  85. SaveButton
  86. {
  87. id: saveButton;
  88. implicitWidth: base.width
  89. implicitHeight: totalHeight
  90. anchors.bottom: parent.bottom
  91. }
  92. SidebarTooltip
  93. {
  94. id: tooltip;
  95. }
  96. ListModel
  97. {
  98. id: modesListModel;
  99. }
  100. Component.onCompleted:
  101. {
  102. modesListModel.append({ text: catalog.i18nc("@title:tab", "Simple"), file: "SidebarSimple.qml" })
  103. modesListModel.append({ text: catalog.i18nc("@title:tab", "Advanced"), file: "SidebarAdvanced.qml" })
  104. sidebarContents.setSource(modesListModel.get(header.currentModeIndex).file)
  105. }
  106. }