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
8
9/**
10 * @warning This component is expected to be used as a ListView.delegate.
11 * If this is not the case, make sure to set index and listView
12 */
13QQC2.ItemDelegate {
14 id: root
15
16 required property int index
17 required property bool unread
18
19 readonly property bool showSeparator: root.index !== ListView.view.count
20
21 width: ListView.view ? ListView.view.width : implicitWidth
22 highlighted: ListView.isCurrentItem
23
24 padding: Kirigami.Units.largeSpacing
25
26 horizontalPadding: padding
27 leftPadding: horizontalPadding
28 rightPadding: horizontalPadding
29
30 verticalPadding: padding
31 topPadding: verticalPadding
32 bottomPadding: verticalPadding
33
34 hoverEnabled: true
35
36 icon {
37 width: if (contentItem instanceof SubtitleContentItem) {
38 Kirigami.Units.iconSizes.large
39 } else {
40 Kirigami.Units.iconSizes.medium
41 }
42
43 height: if (contentItem instanceof SubtitleContentItem) {
44 Kirigami.Units.iconSizes.large
45 } else {
46 Kirigami.Units.iconSizes.medium
47 }
48 }
49
50 Accessible.description: if (contentItem instanceof SubtitleContentItem) {
51 contentItem.subtitle
52 } else {
53 ""
54 }
55
56 background: Rectangle {
57 color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
58 const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
59 if (root.hovered) {
60 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
61 } else {
62 highlight
63 }
64 } else if (root.hovered) {
65 Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
66 } else {
67 Kirigami.Theme.backgroundColor
68 }
69
70 // indicator rectangle
71 Rectangle {
72 anchors {
73 left: parent.left
74 top: parent.top
75 topMargin: 1
76 bottom: parent.bottom
77 bottomMargin: 1
78 }
79
80 width: 4
81 visible: root.unread
82 color: Kirigami.Theme.highlightColor
83 }
84
85 Kirigami.Separator {
86 anchors {
87 bottom: parent.bottom
88 left: parent.left
89 right: parent.right
90 leftMargin: root.leftPadding
91 rightMargin: root.rightPadding
92 }
93 visible: root.showSeparator && !root.hovered && (root.index === 0 || !root.ListView.view.itemAtIndex(root.index - 1))
94 opacity: 0.5
95 }
96 }
97
98 contentItem: DefaultContentItem {
99 itemDelegate: root
100 }
101}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.