ToolTip.qml 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2018 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. import Cura 1.0 as Cura
  7. ToolTip
  8. {
  9. enum ContentAlignment
  10. {
  11. AlignLeft,
  12. AlignRight
  13. }
  14. // Defines the alignment of the content, by default to the left
  15. property int contentAlignment: Cura.ToolTip.ContentAlignment.AlignRight
  16. property alias tooltipText: tooltip.text
  17. property alias arrowSize: backgroundRect.arrowSize
  18. property var targetPoint: Qt.point(parent.x, y + Math.round(height/2))
  19. id: tooltip
  20. text: ""
  21. delay: 500
  22. font: UM.Theme.getFont("default")
  23. visible: opacity != 0.0
  24. opacity: 0.0 // initially hidden
  25. Behavior on opacity
  26. {
  27. NumberAnimation { duration: 100; }
  28. }
  29. // If the text is not set, just set the height to 0 to prevent it from showing
  30. height: text != "" ? label.contentHeight + 2 * UM.Theme.getSize("thin_margin").width: 0
  31. x:
  32. {
  33. if (contentAlignment == Cura.ToolTip.ContentAlignment.AlignLeft)
  34. {
  35. return (label.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2) + padding * 2) * -1
  36. }
  37. return parent.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2 + padding)
  38. }
  39. y: Math.round(parent.height / 2 - label.height / 2 ) - padding
  40. padding: UM.Theme.getSize("thin_margin").width
  41. background: UM.PointingRectangle
  42. {
  43. id: backgroundRect
  44. color: UM.Theme.getColor("tooltip")
  45. target: Qt.point(targetPoint.x - tooltip.x, targetPoint.y - tooltip.y)
  46. arrowSize: UM.Theme.getSize("default_arrow").width
  47. }
  48. contentItem: Label
  49. {
  50. id: label
  51. text: tooltip.text
  52. font: tooltip.font
  53. wrapMode: Text.Wrap
  54. textFormat: Text.RichText
  55. color: UM.Theme.getColor("tooltip_text")
  56. renderType: Text.NativeRendering
  57. }
  58. function show() {
  59. opacity = 1
  60. }
  61. function hide() {
  62. opacity = 0
  63. }
  64. }