ToolTip.qml 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // This property indicates when the tooltip has to show, for instance when a button is hovered
  15. property bool show: false
  16. // Defines the alignment of the content, by default to the left
  17. property int contentAlignment: Cura.ToolTip.ContentAlignment.AlignRight
  18. property alias tooltipText: tooltip.text
  19. property var targetPoint: Qt.point(parent.x, y + Math.round(height/2))
  20. id: tooltip
  21. text: ""
  22. delay: 500
  23. visible: text != "" && show
  24. font: UM.Theme.getFont("default")
  25. x:
  26. {
  27. if (contentAlignment == Cura.ToolTip.ContentAlignment.AlignLeft)
  28. {
  29. return (label.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2) + padding * 2) * -1
  30. }
  31. return parent.width + Math.round(UM.Theme.getSize("default_arrow").width * 1.2 + padding)
  32. }
  33. y: Math.round(parent.height / 2 - label.height / 2 ) - padding
  34. padding: 2
  35. background: UM.PointingRectangle
  36. {
  37. id: backgroundRect
  38. color: UM.Theme.getColor("tooltip")
  39. target: Qt.point(targetPoint.x - tooltip.x, targetPoint.y - tooltip.y)
  40. arrowSize: UM.Theme.getSize("default_arrow").width
  41. }
  42. contentItem: Label
  43. {
  44. id: label
  45. text: tooltip.text
  46. font: tooltip.font
  47. wrapMode: Text.Wrap
  48. textFormat: Text.RichText
  49. color: UM.Theme.getColor("tooltip_text")
  50. renderType: Text.NativeRendering
  51. }
  52. }