SidebarTooltip.qml 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. UM.PointingRectangle {
  9. id: base;
  10. width: UM.Theme.getSize("tooltip").width;
  11. height: label.height + UM.Theme.getSize("tooltip_margins").height * 2;
  12. color: UM.Theme.getColor("tooltip");
  13. arrowSize: UM.Theme.getSize("default_arrow").width
  14. opacity: 0;
  15. Behavior on opacity { NumberAnimation { duration: 100; } }
  16. property alias text: label.text;
  17. function show(position) {
  18. if(position.y + base.height > parent.height) {
  19. x = position.x - base.width;
  20. y = parent.height - base.height;
  21. } else {
  22. x = position.x - base.width;
  23. y = position.y - UM.Theme.getSize("tooltip_arrow_margins").height;
  24. }
  25. base.opacity = 1;
  26. target = Qt.point(40 , position.y + UM.Theme.getSize("tooltip_arrow_margins").height / 2)
  27. }
  28. function hide() {
  29. base.opacity = 0;
  30. }
  31. Label {
  32. id: label;
  33. anchors {
  34. top: parent.top;
  35. topMargin: UM.Theme.getSize("tooltip_margins").height;
  36. left: parent.left;
  37. leftMargin: UM.Theme.getSize("tooltip_margins").width;
  38. right: parent.right;
  39. rightMargin: UM.Theme.getSize("tooltip_margins").width;
  40. }
  41. wrapMode: Text.Wrap;
  42. font: UM.Theme.getFont("default");
  43. color: UM.Theme.getColor("tooltip_text");
  44. }
  45. }