Toolbar.qml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.0 as UM
  8. Item {
  9. id: base;
  10. width: buttons.width;
  11. height: buttons.height
  12. property int activeY
  13. ColumnLayout {
  14. id: buttons;
  15. anchors.bottom: parent.bottom;
  16. anchors.left: parent.left;
  17. spacing: UM.Theme.getSize("button_lining").width
  18. Repeater {
  19. id: repeat
  20. model: UM.ToolModel { }
  21. Button {
  22. text: model.name
  23. iconSource: UM.Theme.getIcon(model.icon);
  24. checkable: true;
  25. checked: model.active;
  26. enabled: model.enabled && UM.Selection.hasSelection && UM.Controller.toolsEnabled;
  27. style: UM.Theme.styles.tool_button;
  28. onCheckedChanged:
  29. {
  30. if(checked)
  31. {
  32. base.activeY = y
  33. }
  34. }
  35. //Workaround since using ToolButton"s onClicked would break the binding of the checked property, instead
  36. //just catch the click so we do not trigger that behaviour.
  37. MouseArea {
  38. anchors.fill: parent;
  39. onClicked: {
  40. parent.checked ? UM.Controller.setActiveTool(null) : UM.Controller.setActiveTool(model.id);
  41. }
  42. }
  43. }
  44. }
  45. }
  46. UM.PointingRectangle {
  47. id: panelBorder;
  48. anchors.left: parent.right;
  49. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  50. anchors.top: base.top;
  51. anchors.topMargin: base.activeY
  52. z: buttons.z -1
  53. target: Qt.point(parent.right, base.activeY + UM.Theme.getSize("button").height/2)
  54. arrowSize: UM.Theme.getSize("default_arrow").width
  55. width: {
  56. if (panel.item && panel.width > 0){
  57. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  58. }
  59. else {
  60. return 0
  61. }
  62. }
  63. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0;
  64. opacity: panel.item && panel.width > 0 ? 1 : 0
  65. Behavior on opacity { NumberAnimation { duration: 100 } }
  66. color: UM.Theme.getColor("lining");
  67. //border.width: UM.Theme.getSize("default_lining").width
  68. //border.color: UM.Theme.getColor("lining")
  69. UM.PointingRectangle {
  70. id: panelBackground;
  71. color: UM.Theme.getColor("tool_panel_background");
  72. anchors.fill: parent
  73. anchors.margins: UM.Theme.getSize("default_lining").width
  74. target: Qt.point(-UM.Theme.getSize("default_margin").width, UM.Theme.getSize("button").height/2)
  75. arrowSize: parent.arrowSize
  76. MouseArea //Catch all mouse events (so scene doesnt handle them)
  77. {
  78. anchors.fill: parent
  79. }
  80. }
  81. Loader {
  82. id: panel
  83. x: UM.Theme.getSize("default_margin").width;
  84. y: UM.Theme.getSize("default_margin").height;
  85. source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : "";
  86. enabled: UM.Controller.toolsEnabled;
  87. }
  88. }
  89. Rectangle
  90. {
  91. x: -base.x + base.mouseX + UM.Theme.getSize("default_margin").width
  92. y: -base.y + base.mouseY + UM.Theme.getSize("default_margin").height
  93. width: toolHint.width + UM.Theme.getSize("default_margin").width
  94. height: toolHint.height;
  95. color: UM.Theme.getColor("tooltip")
  96. Label
  97. {
  98. id: toolHint
  99. text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
  100. color: UM.Theme.getColor("tooltip_text")
  101. font: UM.Theme.getFont("default")
  102. anchors.horizontalCenter: parent.horizontalCenter
  103. }
  104. visible: toolHint.text != "";
  105. }
  106. }