SidebarTooltip.qml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. if(y < 0)
  25. {
  26. position.y += -y;
  27. y = 0;
  28. }
  29. }
  30. base.opacity = 1;
  31. target = Qt.point(40 , position.y + UM.Theme.getSize("tooltip_arrow_margins").height / 2)
  32. }
  33. function hide() {
  34. base.opacity = 0;
  35. }
  36. Text {
  37. id: label;
  38. anchors {
  39. top: parent.top;
  40. topMargin: UM.Theme.getSize("tooltip_margins").height;
  41. left: parent.left;
  42. leftMargin: UM.Theme.getSize("tooltip_margins").width;
  43. right: parent.right;
  44. rightMargin: UM.Theme.getSize("tooltip_margins").width;
  45. }
  46. wrapMode: Text.Wrap;
  47. font: UM.Theme.getFont("default");
  48. color: UM.Theme.getColor("tooltip_text");
  49. }
  50. }