ToolTip.qml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 var targetPoint: Qt.point(parent.x, y + Math.round(height/2))
  18. id: tooltip
  19. text: ""
  20. delay: 500
  21. font: UM.Theme.getFont("default")
  22. // If the text is not set, just set the height to 0 to prevent it from showing
  23. height: text != "" ? label.contentHeight + 2 * UM.Theme.getSize("thin_margin").width: 0
  24. x:
  25. {
  26. if (contentAlignment == Cura.ToolTip.ContentAlignment.AlignLeft)
  27. {
  28. return (label.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2) + padding * 2) * -1
  29. }
  30. return parent.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2 + padding)
  31. }
  32. y: Math.round(parent.height / 2 - label.height / 2 ) - padding
  33. padding: UM.Theme.getSize("thin_margin").width
  34. background: UM.PointingRectangle
  35. {
  36. id: backgroundRect
  37. color: UM.Theme.getColor("tooltip")
  38. target: Qt.point(targetPoint.x - tooltip.x, targetPoint.y - tooltip.y)
  39. arrowSize: UM.Theme.getSize("default_arrow").width
  40. }
  41. contentItem: Label
  42. {
  43. id: label
  44. text: tooltip.text
  45. font: tooltip.font
  46. wrapMode: Text.Wrap
  47. textFormat: Text.RichText
  48. color: UM.Theme.getColor("tooltip_text")
  49. renderType: Text.NativeRendering
  50. }
  51. }