PrintSetupTooltip.qml 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright (c) 2020 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.7
  4. import QtQuick.Controls 2.3
  5. import UM 1.5 as UM
  6. UM.PointingRectangle
  7. {
  8. id: base
  9. property real sourceWidth: 0
  10. width: UM.Theme.getSize("tooltip").width
  11. height: textScroll.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
  16. {
  17. NumberAnimation { duration: 200; }
  18. }
  19. property alias text: label.text
  20. function show(position)
  21. {
  22. if(position.y + base.height > parent.height)
  23. {
  24. x = position.x - base.width;
  25. y = parent.height - base.height;
  26. } else
  27. {
  28. var new_x = x = position.x - base.width
  29. // If the tooltip would fall out of the screen, display it on the other side.
  30. if(new_x < 0)
  31. {
  32. new_x = x + sourceWidth + base.width
  33. }
  34. x = new_x
  35. y = position.y - UM.Theme.getSize("tooltip_arrow_margins").height;
  36. if(y < 0)
  37. {
  38. position.y += -y;
  39. y = 0;
  40. }
  41. }
  42. base.opacity = 1;
  43. target = Qt.point(position.x + 1, position.y + Math.round(UM.Theme.getSize("tooltip_arrow_margins").height / 2))
  44. }
  45. function hide()
  46. {
  47. base.opacity = 0;
  48. }
  49. ScrollView
  50. {
  51. id: textScroll
  52. width: parent.width
  53. height: Math.min(label.height + UM.Theme.getSize("tooltip_margins").height, base.parent.height)
  54. ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
  55. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  56. hoverEnabled: parent.opacity > 0
  57. onHoveredChanged:
  58. {
  59. if(hovered && base.opacity > 0)
  60. {
  61. base.show(Qt.point(target.x - 1, target.y - UM.Theme.getSize("tooltip_arrow_margins").height / 2)); //Same arrow position as before.
  62. }
  63. else
  64. {
  65. base.hide();
  66. }
  67. }
  68. UM.Label
  69. {
  70. id: label
  71. x: UM.Theme.getSize("tooltip_margins").width
  72. y: UM.Theme.getSize("tooltip_margins").height
  73. width: textScroll.width - 2 * UM.Theme.getSize("tooltip_margins").width
  74. wrapMode: Text.Wrap
  75. textFormat: Text.RichText
  76. color: UM.Theme.getColor("tooltip_text")
  77. }
  78. }
  79. }