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 readonly property bool showSeparator: root.index !== ListView.view.count
21
22 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
23 implicitContentWidth + leftPadding + rightPadding,
24 implicitIndicatorWidth + leftPadding + rightPadding)
25 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
26 implicitContentHeight + topPadding + bottomPadding,
27 implicitIndicatorHeight + topPadding + bottomPadding,
28 Kirigami.Units.gridUnit * 2)
29
30 width: ListView.view ? ListView.view.width : implicitWidth
31 highlighted: ListView.isCurrentItem
32
33 padding: Kirigami.Units.largeSpacing
34
35 horizontalPadding: padding
36 leftPadding: horizontalPadding
37 rightPadding: horizontalPadding
38
39 verticalPadding: padding
40 topPadding: verticalPadding
41 bottomPadding: verticalPadding
42
43 hoverEnabled: true
44
45 icon {
46 width: if (contentItem instanceof SubtitleContentItem) {
47 Kirigami.Units.iconSizes.large
48 } else {
49 Kirigami.Units.iconSizes.medium
50 }
51
52 height: if (contentItem instanceof SubtitleContentItem) {
53 Kirigami.Units.iconSizes.large
54 } else {
55 Kirigami.Units.iconSizes.medium
56 }
57 }
58
59 Accessible.description: if (contentItem instanceof SubtitleContentItem) {
60 contentItem.subtitle
61 } else {
62 ""
63 }
64
65 background: Rectangle {
66 color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
67 const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
68 if (root.hovered) {
69 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
70 } else {
71 highlight
72 }
73 } else if (root.hovered) {
74 Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
75 } else {
76 Kirigami.Theme.backgroundColor
77 }
78
79 // indicator rectangle
80 Rectangle {
81 anchors {
82 left: parent.left
83 top: parent.top
84 topMargin: 1
85 bottom: parent.bottom
86 bottomMargin: 1
87 }
88
89 width: 4
90 visible: root.unread
91 color: Kirigami.Theme.highlightColor
92 }
93
94 Kirigami.Separator {
95 anchors {
96 bottom: parent.bottom
97 left: parent.left
98 right: parent.right
99 leftMargin: root.leftPadding
100 rightMargin: root.rightPadding
101 }
102 visible: root.showSeparator && !root.hovered
103 opacity: 0.5
104 }
105 }
106
107 contentItem: DefaultContentItem {
108 itemDelegate: root
109 }
110}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:46:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.