SidebarTooltip.qml 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Copyright (c) 2015 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  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 + Math.round(UM.Theme.getSize("tooltip_arrow_margins").height / 2))
  32. }
  33. function hide() {
  34. base.opacity = 0;
  35. }
  36. Label {
  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. textFormat: Text.RichText
  48. font: UM.Theme.getFont("default");
  49. color: UM.Theme.getColor("tooltip_text");
  50. }
  51. }