PrintSetupTooltip.qml 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: 100; }
  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. MouseArea
  50. {
  51. enabled: parent.opacity > 0
  52. visible: enabled
  53. anchors.fill: parent
  54. acceptedButtons: Qt.NoButton
  55. hoverEnabled: true
  56. onHoveredChanged:
  57. {
  58. if(containsMouse && base.opacity > 0)
  59. {
  60. base.show(Qt.point(target.x - 1, target.y - UM.Theme.getSize("tooltip_arrow_margins").height / 2)); //Same arrow position as before.
  61. }
  62. else
  63. {
  64. base.hide();
  65. }
  66. }
  67. ScrollView
  68. {
  69. id: textScroll
  70. width: parent.width
  71. height: Math.min(label.height, base.parent.height)
  72. ScrollBar.horizontal: ScrollBar {
  73. active: false //Only allow vertical scrolling. We should grow vertically only, but due to how the label is positioned it allocates space in the ScrollView horizontally.
  74. }
  75. UM.Label
  76. {
  77. id: label
  78. x: UM.Theme.getSize("tooltip_margins").width
  79. y: UM.Theme.getSize("tooltip_margins").height
  80. width: base.width - UM.Theme.getSize("tooltip_margins").width * 2
  81. wrapMode: Text.Wrap
  82. textFormat: Text.RichText
  83. color: UM.Theme.getColor("tooltip_text")
  84. }
  85. }
  86. }
  87. }