PrintSetupTooltip.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Copyright (c) 2019 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.0 as UM
  6. UM.PointingRectangle
  7. {
  8. id: base
  9. property real sourceWidth: 0
  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
  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. Label
  50. {
  51. id: label;
  52. anchors
  53. {
  54. top: parent.top;
  55. topMargin: UM.Theme.getSize("tooltip_margins").height;
  56. left: parent.left;
  57. leftMargin: UM.Theme.getSize("tooltip_margins").width;
  58. right: parent.right;
  59. rightMargin: UM.Theme.getSize("tooltip_margins").width;
  60. }
  61. wrapMode: Text.Wrap;
  62. textFormat: Text.RichText
  63. font: UM.Theme.getFont("default");
  64. color: UM.Theme.getColor("tooltip_text");
  65. renderType: Text.NativeRendering
  66. }
  67. }