Kirigami2

controls/templates/AbstractListItem.qml
1 /*
2  * SPDX-FileCopyrightText: 2010 Marco Martin <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 import QtQuick 2.1
8 import QtQuick.Layouts 1.0
9 import org.kde.kirigami 2.4 as Kirigami
10 // TODO KF6: This must stay at 2.2 until KF6 due to retrocompatibility of the "icon" property
11 import QtQuick.Templates 2.2 as T2
12 import QtQuick.Templates 2.4 as QQC2
13 
14 /**
15  * @brief An item delegate for the primitive ListView component.
16  *
17  * It's intended to make all listviews look coherent.
18  *
19  * @inherit QtQuick.Controls.ItemDelegate
20  */
21 T2.ItemDelegate {
22  id: listItem
23 
24 //BEGIN properties
25  /**
26  * @brief This property sets whether the item should emit signals related to mouse interaction.
27  *
28  * default: ``true``
29  *
30  * @deprecated This will be removed in KF6.
31  */
32  property bool supportsMouseEvents: hoverEnabled
33 
34  /**
35  * @brief This property specifies whether the cursor is currently hovering over the item.
36  *
37  * On mobile touch devices, this will be @c true only when pressed.
38  *
39  * @see QtQuick.Templates.ItemDelegate.hovered
40  * @deprecated This will be removed in KF6; use the ``hovered`` property instead.
41  * @property bool containsMouse
42  */
43  property alias containsMouse: listItem.hovered
44 
45  /**
46  * @brief This property sets whether instances of this list item will alternate
47  * between two colors, helping readability.
48  *
49  * It is suggested to use this only when implementing a view with multiple columns.
50  *
51  * default: ``false``
52  *
53  * @since org.kde.kirigami 2.7
54  */
55  property bool alternatingBackground: false
56 
57  /**
58  * @brief This property sets whether this item is a section delegate.
59  *
60  * Setting this to @c true will make the list item look like a "title" for items under it.
61  *
62  * default: ``false``
63  *
64  * @see kirigami::ListSectionHeader
65  */
66  property bool sectionDelegate: false
67 
68  /**
69  * @brief This property sets whether the separator is visible.
70  *
71  * The separator is a line between this and the item under it.
72  *
73  * default: ``false``
74  */
75  property bool separatorVisible: false
76 
77  /**
78  * @brief This property holds list item's background color.
79  *
80  * It is advised to use the default value.
81  *
82  * default: ``"transparent"``
83  */
84  property color backgroundColor: "transparent"
85 
86  /**
87  * @brief This property holds the background color to be used when
88  * background alternating is enabled.
89  *
90  * It is advised to use the default value.
91  *
92  * default: @link Kirigami.PlatformTheme.alternateBackgroundColor Kirigami.Theme.alternateBackgroundColor @endlink
93  *
94  * @since org.kde.kirigami 2.7
95  */
96  property color alternateBackgroundColor: Kirigami.Theme.alternateBackgroundColor
97 
98  /**
99  * @brief This property holds the color of the background
100  * when the item is pressed or selected.
101  *
102  * It is advised to use the default value.
103  *
104  * default: @link Kirigami.PlatformTheme.highlightColor Kirigami.Theme.highlightColor @endlink
105  */
106  property color activeBackgroundColor: Kirigami.Theme.highlightColor
107 
108  /**
109  * @brief This property holds the color of the text in the item.
110  *
111  * It is advised to use the default value.
112  *
113  * default: @link Kirigami.PlatformTheme.textColor Kirigami.Theme.textColor @endlink
114  *
115  * If custom text elements are inserted in an AbstractListItem,
116  * their color will have to be manually set with this property.
117  */
118  property color textColor: Kirigami.Theme.textColor
119 
120  /**
121  * @brief This property holds the color of the text when the item is pressed or selected.
122  *
123  * It is advised to use the default value.
124  *
125  * default: @link Kirigami.PlatformTheme.highlightedTextColor Kirigami.Theme.highlightedTextColor @endlink
126  *
127  * If custom text elements are inserted in an AbstractListItem,
128  * their color will have to be manually set with this property.
129  */
130  property color activeTextColor: Kirigami.Theme.highlightedTextColor
131 
132  /** @internal */
133  default property alias _default: listItem.contentItem
134 
135  // NOTE: Overrides action property of newer import versions which we can't use
136  /**
137  * @brief This property holds the item action.
138  * @property QtQuick.Controls.Action action
139  */
140  property QQC2.Action action
141 //END properties
142 
143  activeFocusOnTab: ListView.view ? false : true
144 
145  text: action ? action.text : undefined
146  checked: action ? action.checked : false
147  checkable: action ? action.checkable : false
148  onClicked: {
149  if (ListView.view && typeof index !== "undefined") {
150  ListView.view.currentIndex = index;
151  }
152  if (!action) {
153  return;
154  }
155 
156  action.trigger();
157  checked = Qt.binding(function() { return action.checked });
158  }
159  //Theme.inherit: false
160  //Theme.colorSet: Kirigami.Theme.View
161 
162  padding: Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
163 
164  leftPadding: padding * 2
165  topPadding: padding
166 
167  rightPadding: padding * 2
168  bottomPadding: padding
169 
170  implicitWidth: contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : Kirigami.Units.gridUnit * 12
171 
172  implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
173 
174  width: parent && parent.width > 0 ? parent.width : implicitWidth
175  Layout.fillWidth: true
176 
177  opacity: enabled ? 1 : 0.6
178 
179  height: implicitHeight
180 
181  onVisibleChanged: {
182  if (visible) {
183  height = Qt.binding(() => implicitHeight);
184  } else {
185  if (ListView.view && ListView.view.visible) {
186  height = 0;
187  }
188  }
189  }
190 
191  hoverEnabled: true
192 
193  Accessible.role: Accessible.ListItem
194  highlighted: focus && ListView.isCurrentItem && ListView.view && ListView.view.keyNavigationEnabled
195 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 3 2023 04:02:12 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.