Kirigami-addons

AvatarButton.qml
1// SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4import QtQuick 2.15
5import QtQuick.Controls 2.15 as QQC2
6import org.kde.kirigami 2.15 as Kirigami
7
8/**
9 * @brief An button that represents a user, either with initials, an icon, or a profile image.
10 */
11QQC2.AbstractButton {
12 id: root
13
14 /**
15 * @brief This property holds the given name of a user.
16 * @see org:kde::kirigamiaddons::components::Avatar::source
17 */
18 property alias name: avatar.name
19
20 /**
21 * @brief This property holds avatar's icon source.
22 * @see org:kde::kirigamiaddons::components::Avatar::source
23 */
24 property alias source: avatar.source
26 /**
27 * @brief This property holds how the button should represent the user when no user-set image is available.
28 * @see org:kde::kirigamiaddons::components::Avatar::initialsMode
29 */
30 property alias initialsMode: avatar.initialsMode
31
32 /**
33 * @brief This property holds how the avatar should be shown.
34 * @see org:kde::kirigamiaddons::components::Avatar::imageMode
35 */
36 property alias imageMode: avatar.imageMode
37
38 /**
39 * @brief This property sets whether the provided image should be cached.
40 * @see QtQuick.Image::cache
41 */
42 property alias cache: avatar.cache
43
44 /**
45 * @brief Load the image asynchronously.
46 * @see QtQuick.Image::asynchronous
47 * @property bool asynchronous
48 * @since 1.7.0
49 */
50 property alias asynchronous: avatar.asynchronous
51
52 /**
53 * @brief This property holds the source size of the user's profile picture.
54 */
55 property alias sourceSize: avatar.sourceSize
56
57 /**
58 * @brief This property holds the color to use for this avatar.
59 */
60 property alias color: avatar.color
61
62 /**
63 * @brief This property holds the color of the avatar's initials.
64 */
65 property alias initialsColor: avatar.initialsColor
66
67 /**
68 * @brief This property holds the default color of the avatar's initials.
69 */
70 readonly property alias defaultInitialsColor: avatar.defaultInitialsColor
71
72 /**
73 * @brief This item holds the parent item on the clipped circle.
74 *
75 * Implementations may add custom graphics which will be clipped along with
76 * the rest of the avatar content.
77 */
78 readonly property alias clippedContent: avatar.clippedContent
79
80 Kirigami.Theme.colorSet: Kirigami.Theme.Button
81 Kirigami.Theme.inherit: false
82
83 text: name
84
85 padding: 1
86
87 hoverEnabled: true // so the tooltip works
88
89 contentItem: Avatar {
90 id: avatar
91 }
92
93 background: Rectangle {
94 radius: height
95 color: Kirigami.Theme.focusColor
96 visible: root.visualFocus || root.down
97 }
98
99 HoverHandler {
100 cursorShape: Qt.PointingHandCursor
101 }
102
103 QQC2.ToolTip.visible: hovered && text.length > 0
104 QQC2.ToolTip.text: text
105 QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
106}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 3 2025 11:46:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.