CheckBoxWithTooltip.qml 1.8 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.1
  5. import UM 1.3 as UM
  6. CheckBox
  7. {
  8. id: checkbox
  9. hoverEnabled: true
  10. property alias tooltip: tooltip.text
  11. indicator: Rectangle
  12. {
  13. implicitWidth: UM.Theme.getSize("checkbox").width
  14. implicitHeight: UM.Theme.getSize("checkbox").height
  15. x: 0
  16. anchors.verticalCenter: parent.verticalCenter
  17. color: UM.Theme.getColor("main_background")
  18. radius: UM.Theme.getSize("checkbox_radius").width
  19. border.width: UM.Theme.getSize("default_lining").width
  20. border.color: checkbox.hovered ? UM.Theme.getColor("checkbox_border_hover") : UM.Theme.getColor("checkbox_border")
  21. UM.RecolorImage
  22. {
  23. anchors.verticalCenter: parent.verticalCenter
  24. anchors.horizontalCenter: parent.horizontalCenter
  25. width: Math.round(parent.width / 2.5)
  26. height: Math.round(parent.height / 2.5)
  27. sourceSize.height: width
  28. color: UM.Theme.getColor("checkbox_mark")
  29. source: UM.Theme.getIcon("check")
  30. opacity: checkbox.checked
  31. Behavior on opacity { NumberAnimation { duration: 100; } }
  32. }
  33. }
  34. contentItem: Label
  35. {
  36. anchors
  37. {
  38. left: checkbox.indicator.right
  39. leftMargin: UM.Theme.getSize("narrow_margin").width
  40. }
  41. text: checkbox.text
  42. color: UM.Theme.getColor("checkbox_text")
  43. font: UM.Theme.getFont("default")
  44. renderType: Text.NativeRendering
  45. elide: Text.ElideRight
  46. verticalAlignment: Text.AlignVCenter
  47. }
  48. ToolTip
  49. {
  50. id: tooltip
  51. text: ""
  52. delay: 500
  53. visible: text != "" && checkbox.hovered
  54. }
  55. }