AvatarImage.qml 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (c) 2018 Ultimaker B.V.
  2. // Cura is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.10
  4. import QtQuick.Controls 2.3
  5. import QtGraphicalEffects 1.0
  6. import UM 1.4 as UM
  7. Item
  8. {
  9. // This item shows the provided image while applying a round mask to it.
  10. // It also shows a round border around it. The color is defined by the outlineColor property.
  11. id: avatar
  12. property alias source: profileImage.source
  13. property alias outlineColor: profileImageOutline.color
  14. property bool hasAvatar: source != ""
  15. Image
  16. {
  17. id: profileImage
  18. anchors.fill: parent
  19. fillMode: Image.PreserveAspectCrop
  20. visible: false
  21. mipmap: true
  22. }
  23. Rectangle
  24. {
  25. id: profileImageMask
  26. anchors.fill: parent
  27. radius: width
  28. color: hasAvatar ? "white" : "transparent"
  29. }
  30. OpacityMask
  31. {
  32. anchors.fill: parent
  33. source: profileImage
  34. maskSource: profileImageMask
  35. visible: hasAvatar
  36. cached: true
  37. }
  38. UM.RecolorImage
  39. {
  40. id: profileImageOutline
  41. anchors.centerIn: parent
  42. // Make it a bit bigger than it has to, otherwise it sometimes shows a white border.
  43. width: parent.width + 2
  44. height: parent.height + 2
  45. visible: hasAvatar
  46. source: UM.Theme.getIcon("circle_outline")
  47. sourceSize: Qt.size(parent.width, parent.height)
  48. color: UM.Theme.getColor("account_widget_outline_active")
  49. }
  50. }