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

KDE's Doxygen guidelines are available online.