Kirigami-addons

RoundedItemDelegate.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 2.15
5import QtQuick.Layouts 1.15
6import QtQuick.Controls 2.15 as QQC2
7import QtQuick.Templates 2.15 as T
8import org.kde.kirigami 2.20 as Kirigami
9
10T.ItemDelegate {
11 id: root
12
13 /**
14 * This property holds a ListView
15 *
16 * It is automatically set if the RoundedItemDelegate is the direct delegate
17 * of a ListView and must be set otherwise.
18 */
19 property var listView: ListView
20
21 /**
22 * This property holds a GridView
23 *
24 * It is automatically set if the RoundedItemDelegate is the direct delegate
25 * of a GridView and must be set otherwise.
26 */
27 property var gridView: GridView
28
29 implicitWidth: Math.max(implicitBackgroundWidth + leftInset + rightInset,
30 implicitContentWidth + leftPadding + rightPadding,
31 implicitIndicatorWidth + leftPadding + rightPadding)
32 implicitHeight: Math.max(implicitBackgroundHeight + topInset + bottomInset,
33 implicitContentHeight + topPadding + bottomPadding,
34 implicitIndicatorHeight + topPadding + bottomPadding,
35 Kirigami.Units.gridUnit * 2)
36
37 width: if (listView.view) {
38 return listView.view.width;
39 } else if (gridView.view) {
40 return gridView.view.cellWidth;
41 } else {
42 implicitWidth
43 }
44
45 height: if (gridView.view) {
46 return gridView.view.cellHeight;
47 } else {
48 return implicitHeight;
49 }
50 highlighted: listView.isCurrentItem || gridView.isCurrentItem
51
52 spacing: Kirigami.Units.mediumSpacing
53
54 padding: Kirigami.Units.mediumSpacing
55
56 horizontalPadding: padding + Math.round(Kirigami.Units.smallSpacing / 2)
57 leftPadding: horizontalPadding
58 rightPadding: horizontalPadding
59
60 verticalPadding: padding
61 topPadding: verticalPadding
62 bottomPadding: verticalPadding
63
64 topInset: if (root.index !== undefined && index === 0 && listView.view && listView.view.topMargin === 0) {
65 Kirigami.Units.smallSpacing;
66 } else {
67 Math.round(Kirigami.Units.smallSpacing / 2);
68 }
69 bottomInset: if (root.index !== undefined && listView.view && index === listView.view.count - 1 && listView.view.bottomMargin === 0) {
70 Kirigami.Units.smallSpacing;
71 } else {
72 Math.round(Kirigami.Units.smallSpacing / 2)
73 }
74 rightInset: Kirigami.Units.smallSpacing
75 leftInset: Kirigami.Units.smallSpacing
76
77 icon {
78 width: if (contentItem instanceof SubtitleContentItem) {
79 Kirigami.Units.iconSizes.large
80 } else {
81 Kirigami.Units.iconSizes.sizeForLabels
82 }
83
84 height: if (contentItem instanceof SubtitleContentItem) {
85 Kirigami.Units.iconSizes.large
86 } else {
87 Kirigami.Units.iconSizes.sizeForLabels
88 }
89 }
90
91 Accessible.description: if (contentItem instanceof SubtitleContentItem) {
92 contentItem.subtitle
93 } else {
94 ""
95 }
96
97 background: Rectangle {
98 radius: Kirigami.Units.cornerRadius
99
100 color: if (root.highlighted || root.checked || (root.down && !root.checked) || root.visualFocus) {
101 const highlight = Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.highlightColor, 0.3);
102 if (root.hovered) {
103 Kirigami.ColorUtils.tintWithAlpha(highlight, Kirigami.Theme.textColor, 0.10)
104 } else {
105 highlight
106 }
107 } else if (root.hovered) {
108 Kirigami.ColorUtils.tintWithAlpha(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.10)
109 } else {
110 Kirigami.Theme.backgroundColor
111 }
112
113 border {
114 color: Kirigami.Theme.highlightColor
115 width: root.visualFocus || root.activeFocus ? 1 : 0
116 }
117
118 Behavior on color {
119 ColorAnimation {
120 duration: Kirigami.Units.shortDuration
121 }
122 }
123 }
124
125 contentItem: DefaultContentItem {
126 itemDelegate: root
127 }
128}
Content item which is used by default in the RoundedItemDelegate and IndicatorItemDelegate.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:46:57 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.