Toolbar.qml 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. forceActiveFocus() //First grab focus, so all the text fields are updated
  41. if(parent.checked)
  42. {
  43. UM.Controller.setActiveTool(null)
  44. }
  45. else
  46. {
  47. UM.Controller.setActiveTool(model.id);
  48. }
  49. }
  50. }
  51. }
  52. }
  53. }
  54. UM.PointingRectangle {
  55. id: panelBorder;
  56. anchors.left: parent.right;
  57. anchors.leftMargin: UM.Theme.getSize("default_margin").width;
  58. anchors.top: base.top;
  59. anchors.topMargin: base.activeY
  60. z: buttons.z -1
  61. target: Qt.point(parent.right, base.activeY + UM.Theme.getSize("button").height/2)
  62. arrowSize: UM.Theme.getSize("default_arrow").width
  63. width: {
  64. if (panel.item && panel.width > 0){
  65. return Math.max(panel.width + 2 * UM.Theme.getSize("default_margin").width)
  66. }
  67. else {
  68. return 0
  69. }
  70. }
  71. height: panel.item ? panel.height + 2 * UM.Theme.getSize("default_margin").height : 0;
  72. opacity: panel.item && panel.width > 0 ? 1 : 0
  73. Behavior on opacity { NumberAnimation { duration: 100 } }
  74. color: UM.Theme.getColor("lining");
  75. UM.PointingRectangle {
  76. id: panelBackground;
  77. color: UM.Theme.getColor("tool_panel_background");
  78. anchors.fill: parent
  79. anchors.margins: UM.Theme.getSize("default_lining").width
  80. target: Qt.point(-UM.Theme.getSize("default_margin").width, UM.Theme.getSize("button").height/2)
  81. arrowSize: parent.arrowSize
  82. MouseArea //Catch all mouse events (so scene doesnt handle them)
  83. {
  84. anchors.fill: parent
  85. }
  86. }
  87. Loader {
  88. id: panel
  89. x: UM.Theme.getSize("default_margin").width;
  90. y: UM.Theme.getSize("default_margin").height;
  91. source: UM.ActiveTool.valid ? UM.ActiveTool.activeToolPanel : "";
  92. enabled: UM.Controller.toolsEnabled;
  93. }
  94. }
  95. Rectangle
  96. {
  97. x: -base.x + base.mouseX + UM.Theme.getSize("default_margin").width
  98. y: -base.y + base.mouseY + UM.Theme.getSize("default_margin").height
  99. width: toolHint.width + UM.Theme.getSize("default_margin").width
  100. height: toolHint.height;
  101. color: UM.Theme.getColor("tooltip")
  102. Label
  103. {
  104. id: toolHint
  105. text: UM.ActiveTool.properties.getValue("ToolHint") != undefined ? UM.ActiveTool.properties.getValue("ToolHint") : ""
  106. color: UM.Theme.getColor("tooltip_text")
  107. font: UM.Theme.getFont("default")
  108. anchors.horizontalCenter: parent.horizontalCenter
  109. }
  110. visible: toolHint.text != "";
  111. }
  112. }