9import QtQuick.Window 2.15
10import org.kde.kirigami 2.15 as Kirigami
11import org.kde.kirigamiaddons.components 1.0 as Components
22 AdaptiveImageOrInitals,
45 property alias source: avatarImage.source
56 property alias iconSource: avatarIcon.source
67 property int initialsMode: Avatar.InitialsMode.UseInitials
82 property int imageMode: Avatar.ImageMode.AdaptiveImageOrInitals
89 property alias cache: avatarImage.cache
96 property alias sourceSize: avatarImage.sourceSize
105 property color color: Components.NameUtils.colorsFromString(name)
115 property color initialsColor: defaultInitialsColor
124 readonly property alias defaultInitialsColor: root.__textColor
132 readonly property alias clippedContent: clippedContent
134 implicitWidth: Kirigami.Units.iconSizes.large
135 implicitHeight: Kirigami.Units.iconSizes.large
137 Accessible.role: Accessible.Graphic
138 Accessible.name: name
140 readonly property real __diameter: Math.min(root.width, root.height)
142 readonly property color __textColor: Kirigami.ColorUtils.brightnessForColor(root.color) === Kirigami.ColorUtils.Light
146 readonly
property bool __showImage: {
147 switch (root.imageMode) {
148 case Avatar.ImageMode.AlwaysShowImage:
150 case Avatar.ImageMode.AdaptiveImageOrInitals:
151 return avatarImage.status === Image.Ready;
152 case Avatar.ImageMode.AlwaysShowInitials:
161 anchors.centerIn: parent
163 width: root.__diameter
164 height: root.__diameter
169 visible: root.initialsMode ===
Avatar.InitialsMode.UseInitials &&
171 !Components.NameUtils.isStringUnsuitableForInitials(root.name) &&
172 root.width >
Kirigami.Units.gridUnit
174 text: Components.NameUtils.initialsFromString(root.name)
180 pixelSize: Math.round((root.height -
Kirigami.Units.largeSpacing) / 2)
182 fontSizeMode:
Text.Fit
183 verticalAlignment:
Text.AlignVCenter
184 horizontalAlignment:
Text.AlignHCenter
191 anchors.margins:
Kirigami.Units.largeSpacing
193 visible: !root.__showImage
194 && (root.initialsMode ===
Avatar.InitialsMode.UseIcon
195 || Components.NameUtils.isStringUnsuitableForInitials(root.name))
197 color: root.__textColor
206 visible: root.__showImage
208 fillMode: Image.PreserveAspectCrop
211 width: root.__diameter * root.Screen.devicePixelRatio
212 height: root.__diameter * root.Screen.devicePixelRatio
219 radius: root.__diameter
222 width: root.__showImage ? 0 : 1.25
226 color:
Kirigami.ColorUtils.tintWithAlpha(
Kirigami.Theme.backgroundColor, border.color, 0.07)
An element that represents a user, either with initials, an icon, or a profile image.