Warning, /libraries/kirigami-addons/src/delegates/RoundedItemDelegate.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 QtQuick.Controls 2.15 as QQC2
0007 import QtQuick.Templates 2.15 as T
0008 import org.kde.kirigami 2.20 as Kirigami
0009
0010 T.ItemDelegate {
0011 id: root
0012
0013 /**
0014 * This property holds a ListView
0015 *
0016 * It is automatically set if the RoundedItemDelegate is the direct delegate
0017 * of a ListView and must be set otherwise.
0018 */
0019 property var listView: ListView
0020
0021 /**
0022 * This property holds a GridView
0023 *
0024 * It is automatically set if the RoundedItemDelegate is the direct delegate
0025 * of a GridView and must be set otherwise.
0026 */
0027 property var gridView: GridView
0028
0029 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0030 implicitContentWidth + leftPadding + rightPadding,
0031 implicitIndicatorWidth + leftPadding + rightPadding)
0032 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0033 implicitContentHeight + topPadding + bottomPadding,
0034 implicitIndicatorHeight + topPadding + bottomPadding,
0035 Kirigami.Units.gridUnit * 2)
0036
0037 width: if (listView.view) {
0038 return listView.view.width;
0039 } else if (gridView.view) {
0040 return gridView.view.cellWidth;
0041 } else {
0042 implicitWidth
0043 }
0044
0045 height: if (gridView.view) {
0046 return gridView.view.cellHeight;
0047 } else {
0048 return implicitHeight;
0049 }
0050 highlighted: listView.isCurrentItem || gridView.isCurrentItem
0051
0052 spacing: Kirigami.Units.mediumSpacing
0053
0054 padding: Kirigami.Units.mediumSpacing
0055
0056 horizontalPadding: padding + Math.round(Kirigami.Units.smallSpacing / 2)
0057 leftPadding: horizontalPadding
0058 rightPadding: horizontalPadding
0059
0060 verticalPadding: padding
0061 topPadding: verticalPadding
0062 bottomPadding: verticalPadding
0063
0064 topInset: if (root.index !== undefined && index === 0 && listView.view && listView.view.topMargin === 0) {
0065 Kirigami.Units.smallSpacing;
0066 } else {
0067 Math.round(Kirigami.Units.smallSpacing / 2);
0068 }
0069 bottomInset: if (root.index !== undefined && listView.view && index === listView.view.count - 1 && listView.view.bottomMargin === 0) {
0070 Kirigami.Units.smallSpacing;
0071 } else {
0072 Math.round(Kirigami.Units.smallSpacing / 2)
0073 }
0074 rightInset: Kirigami.Units.smallSpacing
0075 leftInset: Kirigami.Units.smallSpacing
0076
0077 icon {
0078 width: if (contentItem instanceof SubtitleContentItem) {
0079 Kirigami.Units.iconSizes.large
0080 } else {
0081 Kirigami.Units.iconSizes.sizeForLabels
0082 }
0083
0084 height: if (contentItem instanceof SubtitleContentItem) {
0085 Kirigami.Units.iconSizes.large
0086 } else {
0087 Kirigami.Units.iconSizes.sizeForLabels
0088 }
0089 }
0090
0091 Accessible.description: if (contentItem instanceof SubtitleContentItem) {
0092 contentItem.subtitle
0093 } else {
0094 ""
0095 }
0096
0097 background: Rectangle {
0098 radius: Kirigami.Units.smallSpacing
0099
0100 color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
0101 const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
0102 if (root.hovered) {
0103 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
0104 } else {
0105 highlight
0106 }
0107 } else if (root.hovered) {
0108 Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
0109 } else {
0110 Kirigami.Theme.backgroundColor
0111 }
0112
0113 border {
0114 color: Kirigami.Theme.highlightColor
0115 width: root.visualFocus || root.activeFocus ? 1 : 0
0116 }
0117
0118 Behavior on color {
0119 ColorAnimation {
0120 duration: Kirigami.Units.shortDuration
0121 }
0122 }
0123 }
0124
0125 contentItem: DefaultContentItem {
0126 itemDelegate: root
0127 }
0128 }