PrintSetupTooltip.qml 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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
  12. color: UM.Theme.getColor("tooltip")
  13. arrowSize: UM.Theme.getSize("default_arrow").width
  14. opacity: 0
  15. // This should be disabled when invisible, otherwise it will catch mouse events.
  16. enabled: opacity > 0
  17. Behavior on opacity
  18. {
  19. NumberAnimation { duration: 200; }
  20. }
  21. property alias text: label.text
  22. function show(position)
  23. {
  24. if(position.y + base.height > parent.height)
  25. {
  26. x = position.x - base.width;
  27. y = parent.height - base.height;
  28. } else
  29. {
  30. var new_x = x = position.x - base.width
  31. // If the tooltip would fall out of the screen, display it on the other side.
  32. if(new_x < 0)
  33. {
  34. new_x = x + sourceWidth + base.width
  35. }
  36. x = new_x
  37. y = position.y - UM.Theme.getSize("tooltip_arrow_margins").height;
  38. if(y < 0)
  39. {
  40. position.y += -y;
  41. y = 0;
  42. }
  43. }
  44. base.opacity = 1;
  45. target = Qt.point(position.x + 1, position.y + Math.round(UM.Theme.getSize("tooltip_arrow_margins").height / 2))
  46. }
  47. function hide()
  48. {
  49. base.opacity = 0;
  50. }
  51. ScrollView
  52. {
  53. id: textScroll
  54. width: parent.width
  55. height: Math.min(label.height + UM.Theme.getSize("tooltip_margins").height, base.parent.height)
  56. ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
  57. ScrollBar.vertical.policy: ScrollBar.AsNeeded
  58. hoverEnabled: parent.opacity > 0
  59. onHoveredChanged:
  60. {
  61. if(hovered && base.opacity > 0)
  62. {
  63. base.show(Qt.point(target.x - 1, target.y - UM.Theme.getSize("tooltip_arrow_margins").height / 2)); //Same arrow position as before.
  64. }
  65. else
  66. {
  67. base.hide();
  68. }
  69. }
  70. UM.Label
  71. {
  72. id: label
  73. x: UM.Theme.getSize("tooltip_margins").width
  74. y: UM.Theme.getSize("tooltip_margins").height
  75. width: textScroll.width - 2 * UM.Theme.getSize("tooltip_margins").width
  76. textFormat: Text.RichText
  77. color: UM.Theme.getColor("tooltip_text")
  78. }
  79. }
  80. }