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
97 property alias asynchronous: avatarImage.asynchronous
104 property alias sourceSize: avatarImage.sourceSize
113 property color color: Components.NameUtils.colorsFromString(name)
123 property color initialsColor: defaultInitialsColor
132 readonly property alias defaultInitialsColor: root.__textColor
140 readonly property alias clippedContent: clippedContent
142 implicitWidth: Kirigami.Units.iconSizes.large
143 implicitHeight: Kirigami.Units.iconSizes.large
145 Accessible.role: Accessible.Graphic
146 Accessible.name: name
148 readonly property real __diameter: Math.min(root.width, root.height)
150 readonly property color __textColor: Kirigami.ColorUtils.brightnessForColor(root.color) === Kirigami.ColorUtils.Light
154 readonly
property bool __showImage: {
155 switch (root.imageMode) {
156 case Avatar.ImageMode.AlwaysShowImage:
158 case Avatar.ImageMode.AdaptiveImageOrInitals:
159 return avatarImage.status === Image.Ready;
160 case Avatar.ImageMode.AlwaysShowInitials:
166 readonly
property bool __unsuitableForInitials: Components.NameUtils.isStringUnsuitableForInitials(root.name)
171 anchors.centerIn: parent
173 width: root.__diameter
174 height: root.__diameter
179 visible: root.initialsMode ===
Avatar.InitialsMode.UseInitials &&
181 !root.__unsuitableForInitials &&
182 root.width >
Kirigami.Units.gridUnit
184 text: Components.NameUtils.initialsFromString(root.name)
185 textFormat: Text.PlainText
191 pixelSize: Math.round((root.height -
Kirigami.Units.largeSpacing) / 2)
193 fontSizeMode:
Text.Fit
194 verticalAlignment:
Text.AlignVCenter
195 horizontalAlignment:
Text.AlignHCenter
202 anchors.margins:
Kirigami.Units.largeSpacing
204 visible: !root.__showImage
205 && (root.initialsMode ===
Avatar.InitialsMode.UseIcon
206 || root.__unsuitableForInitials)
208 color: root.__textColor
217 visible: root.__showImage
219 fillMode: Image.PreserveAspectCrop
222 width: root.__diameter * root.Screen.devicePixelRatio
223 height: root.__diameter * root.Screen.devicePixelRatio
230 radius: root.__diameter
233 width: root.__showImage ? 0 : 1.25
An element that represents a user, either with initials, an icon, or a profile image.