Warning, /libraries/kirigami-addons/src/delegates/IndicatorItemDelegate.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003
0004 import QtQuick 2.15
0005 import QtQuick.Layouts 1.15
0006 import org.kde.kirigami 2.20 as Kirigami
0007 import QtQuick.Controls 2.15 as QQC2
0008
0009 /**
0010 * @warning This component is expected to be used as a ListView.delegate.
0011 * If this is not the case, make sure to set index and listView
0012 */
0013 QQC2.ItemDelegate {
0014 id: root
0015
0016 required property int index
0017 required property bool unread
0018
0019 readonly property bool showSeparator: root.index !== ListView.view.count
0020
0021 width: ListView.view ? ListView.view.width : implicitWidth
0022 highlighted: ListView.isCurrentItem
0023
0024 padding: Kirigami.Units.largeSpacing
0025
0026 horizontalPadding: padding
0027 leftPadding: horizontalPadding
0028 rightPadding: horizontalPadding
0029
0030 verticalPadding: padding
0031 topPadding: verticalPadding
0032 bottomPadding: verticalPadding
0033
0034 hoverEnabled: true
0035
0036 icon {
0037 width: if (contentItem instanceof SubtitleContentItem) {
0038 Kirigami.Units.iconSizes.large
0039 } else {
0040 Kirigami.Units.iconSizes.medium
0041 }
0042
0043 height: if (contentItem instanceof SubtitleContentItem) {
0044 Kirigami.Units.iconSizes.large
0045 } else {
0046 Kirigami.Units.iconSizes.medium
0047 }
0048 }
0049
0050 Accessible.description: if (contentItem instanceof SubtitleContentItem) {
0051 contentItem.subtitle
0052 } else {
0053 ""
0054 }
0055
0056 background: Rectangle {
0057 color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
0058 const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
0059 if (root.hovered) {
0060 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
0061 } else {
0062 highlight
0063 }
0064 } else if (root.hovered) {
0065 Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
0066 } else {
0067 Kirigami.Theme.backgroundColor
0068 }
0069
0070 // indicator rectangle
0071 Rectangle {
0072 anchors {
0073 left: parent.left
0074 top: parent.top
0075 topMargin: 1
0076 bottom: parent.bottom
0077 bottomMargin: 1
0078 }
0079
0080 width: 4
0081 visible: root.unread
0082 color: Kirigami.Theme.highlightColor
0083 }
0084
0085 Kirigami.Separator {
0086 anchors {
0087 bottom: parent.bottom
0088 left: parent.left
0089 right: parent.right
0090 leftMargin: root.leftPadding
0091 rightMargin: root.rightPadding
0092 }
0093 visible: root.showSeparator && !root.hovered && (root.index === 0 || !root.ListView.view.itemAtIndex(root.index - 1))
0094 opacity: 0.5
0095 }
0096 }
0097
0098 contentItem: DefaultContentItem {
0099 itemDelegate: root
0100 }
0101 }