Kirigami-addons

IndicatorItemDelegate.qml
1// SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3
4import QtQuick
5import QtQuick.Layouts
6import org.kde.kirigami as Kirigami
7import QtQuick.Controls as QQC2
8import QtQuick.Templates as T
9
10/**
11 * @warning This component is expected to be used as a ListView.delegate.
12 * If this is not the case, make sure to set index and listView
13 */
14T.ItemDelegate {
15 id: root
16
17 required property int index
18 required property bool unread
19
20 /**
21 * The listview associated with this item delegate.
22 */
23 property ListView listView: ListView.view
25 readonly property bool showSeparator: root.index !== listView.count
26
27 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
28 implicitContentWidth + leftPadding + rightPadding,
29 implicitIndicatorWidth + leftPadding + rightPadding)
30 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
31 implicitContentHeight + topPadding + bottomPadding,
32 implicitIndicatorHeight + topPadding + bottomPadding,
33 Kirigami.Units.gridUnit * 2)
34
35 width: listView ? listView.width : implicitWidth
36 highlighted: ListView.isCurrentItem
37
38 padding: Kirigami.Units.largeSpacing
39
40 horizontalPadding: padding
41 leftPadding: horizontalPadding
42 rightPadding: horizontalPadding
43
44 verticalPadding: padding
45 topPadding: verticalPadding
46 bottomPadding: verticalPadding
47
48 hoverEnabled: true
49
50 icon {
51 width: if (contentItem instanceof SubtitleContentItem) {
52 Kirigami.Units.iconSizes.large
53 } else {
54 Kirigami.Units.iconSizes.medium
55 }
56
57 height: if (contentItem instanceof SubtitleContentItem) {
58 Kirigami.Units.iconSizes.large
59 } else {
60 Kirigami.Units.iconSizes.medium
61 }
62 }
63
64 Accessible.description: if (contentItem instanceof SubtitleContentItem) {
65 contentItem.subtitle
66 } else {
67 ""
68 }
69
70 background: Rectangle {
71 color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
72 const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
73 if (root.hovered) {
74 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
75 } else {
76 highlight
77 }
78 } else if (root.hovered) {
79 Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
80 } else {
81 Kirigami.Theme.backgroundColor
82 }
83
84 // indicator rectangle
85 Rectangle {
86 anchors {
87 left: parent.left
88 top: parent.top
89 topMargin: 1
90 bottom: parent.bottom
91 bottomMargin: 1
92 }
93
94 width: 4
95 visible: root.unread
96 color: Kirigami.Theme.highlightColor
97 }
98
99 Kirigami.Separator {
100 anchors {
101 bottom: parent.bottom
102 left: parent.left
103 right: parent.right
104 leftMargin: root.leftPadding
105 rightMargin: root.rightPadding
106 }
107 visible: root.showSeparator && !root.hovered
108 opacity: 0.5
109 }
110 }
111
112 contentItem: DefaultContentItem {
113 itemDelegate: root
114 }
115}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.