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     implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
0014                             implicitContentWidth + leftPadding + rightPadding,
0015                             implicitIndicatorWidth + leftPadding + rightPadding)
0016     implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
0017                              implicitContentHeight + topPadding + bottomPadding,
0018                              implicitIndicatorHeight + topPadding + bottomPadding)
0019 
0020     width: if (ListView.view) {
0021         ListView.view.width
0022     } else if (GridView.view) {
0023         GridView.view.cellWidth
0024     } else {
0025         implicitWidth
0026     }
0027 
0028     height: if (GridView.view) {
0029         GridView.view.cellHeight
0030     } else {
0031         implicitHeight
0032     }
0033     highlighted: ListView.isCurrentItem || GridView.isCurrentItem
0034 
0035     spacing: Kirigami.Units.mediumSpacing
0036 
0037     padding: Kirigami.Units.mediumSpacing
0038 
0039     horizontalPadding: padding + Math.round(Kirigami.Units.smallSpacing / 2)
0040     leftPadding: horizontalPadding
0041     rightPadding: horizontalPadding
0042 
0043     verticalPadding: padding
0044     topPadding: verticalPadding
0045     bottomPadding: verticalPadding
0046 
0047     topInset: if (root.index !== undefined && index === 0 && ListView.view && ListView.view.topMargin === 0) {
0048         Kirigami.Units.smallSpacing;
0049     } else {
0050         Math.round(Kirigami.Units.smallSpacing / 2);
0051     }
0052     bottomInset: if (root.index !== undefined && ListView.view && index === ListView.view.count - 1 && ListView.view.bottomMargin === 0) {
0053         Kirigami.Units.smallSpacing;
0054     } else {
0055         Math.round(Kirigami.Units.smallSpacing / 2)
0056     }
0057     rightInset: Kirigami.Units.smallSpacing
0058     leftInset: Kirigami.Units.smallSpacing
0059 
0060     icon {
0061         width: if (contentItem instanceof SubtitleContentItem) {
0062             Kirigami.Units.iconSizes.large
0063         } else {
0064             Kirigami.Units.iconSizes.sizeForLabels
0065         }
0066 
0067         height: if (contentItem instanceof SubtitleContentItem) {
0068             Kirigami.Units.iconSizes.large
0069         } else {
0070             Kirigami.Units.iconSizes.sizeForLabels
0071         }
0072     }
0073 
0074     Accessible.description: if (contentItem instanceof SubtitleContentItem) {
0075         contentItem.subtitle
0076     } else {
0077         ""
0078     }
0079 
0080     background: Rectangle {
0081         radius: Kirigami.Units.smallSpacing
0082 
0083         color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
0084             const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
0085             if (root.hovered) {
0086                 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
0087             } else {
0088                 highlight
0089             }
0090         } else if (root.hovered) {
0091             Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
0092         } else {
0093            Kirigami.Theme.backgroundColor
0094         }
0095 
0096         border {
0097             color: Kirigami.Theme.highlightColor
0098             width: root.visualFocus || root.activeFocus ? 1 : 0
0099         }
0100 
0101         Behavior on color {
0102             ColorAnimation {
0103                 duration: Kirigami.Units.shortDuration
0104             }
0105         }
0106     }
0107 
0108     contentItem: DefaultContentItem {
0109         itemDelegate: root
0110     }
0111 }