Kirigami2

Chip.qml
1// SPDX-FileCopyrightText: 2022 Felipe Kinoshita <kinofhek@gmail.com>
2// SPDX-License-Identifier: LGPL-2.0-or-later
3
4import QtQuick
5import QtQuick.Controls as QQC2
6import QtQuick.Layouts
7import org.kde.kirigami as Kirigami
8
9import "templates" as KT
10import "private" as P
11
12/**
13 * @brief A compact element that represents an attribute, action, or filter.
14 *
15 * Should be used in a group of multiple elements. e.g when displaying tags in a image viewer.
16 *
17 * Example usage:
18 * * @code
19 * import org.kde.kirigami as Kirigami
20 *
21 * Flow {
22 * Repeater {
23 * model: chipsModel
24 *
25 * Kirigami.Chip {
26 * text: model.text
27 * icon.name: "tag-symbolic"
28 * closable: model.closable
29 * onClicked: {
30 * [...]
31 * }
32 * onRemoved: {
33 * [...]
34 * }
35 * }
36 * }
37 * }
38 * @endcode
39 *
40 * @since 2.19
41 */
42KT.Chip {
43 id: chip
44
45 implicitWidth: layout.implicitWidth
46 implicitHeight: toolButton.implicitHeight
48 checkable: !closable
49 hoverEnabled: true
50
51 /**
52 * @brief This property holds the label item; used for accessing the usual Text properties.
53 * @property QtQuick.Controls.Label labelItem
54 */
55 property alias labelItem: label
56
57 contentItem: RowLayout {
58 id: layout
59 spacing: 0
60
61 Kirigami.Icon {
62 id: icon
63 visible: icon.valid
64 Layout.preferredWidth: Kirigami.Units.iconSizes.small
65 Layout.preferredHeight: Kirigami.Units.iconSizes.small
66 Layout.leftMargin: Kirigami.Units.smallSpacing
67 color: chip.icon.color
68 isMask: chip.iconMask
69 source: chip.icon.name || chip.icon.source
70 }
71 QQC2.Label {
72 id: label
73 Layout.fillWidth: true
74 Layout.minimumWidth: Kirigami.Units.gridUnit * 1.5
75 Layout.leftMargin: icon.visible ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing
76 Layout.rightMargin: chip.closable ? Kirigami.Units.smallSpacing : Kirigami.Units.largeSpacing
77 verticalAlignment: Text.AlignVCenter
78 horizontalAlignment: Text.AlignHCenter
79 text: chip.text
80 color: Kirigami.Theme.textColor
81 elide: Text.ElideRight
82 }
83 QQC2.ToolButton {
84 id: toolButton
85 visible: chip.closable
86 text: qsTr("Remove Tag")
87 icon.name: "edit-delete-remove"
88 icon.width: Kirigami.Units.iconSizes.sizeForLabels
89 icon.height: Kirigami.Units.iconSizes.sizeForLabels
90 display: QQC2.AbstractButton.IconOnly
91 onClicked: chip.removed()
92 }
93 }
94
95 background: P.DefaultChipBackground {}
96}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:52 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.