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 // NOTE: 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 tells whether the cursor is currently hovering over the item.
36  *
37  * On mobile touch devices, this will be 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 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 true will make the list item look like a "title" for items under it.
61  *
62  * default: ``false``
63  *
64  * @see 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  * default: ``"transparent"``
82  */
83  property color backgroundColor: "transparent"
84 
85  /**
86  * @brief This property holds the background color to be used when
87  * background alternating is enabled.
88  *
89  * It is advised to use the default value.
90  * default: ``Kirigami.Theme.alternateBackgroundColor``
91  *
92  * @since 2.7
93  */
94  property color alternateBackgroundColor: Kirigami.Theme.alternateBackgroundColor
95 
96  /**
97  * @brief This property holds the color of the background
98  * when the item is pressed or selected.
99  *
100  * It is advised to use the default value.
101  * default: ``Kirigami.Theme.highlightColor``
102  */
103  property color activeBackgroundColor: Kirigami.Theme.highlightColor
104 
105  /**
106  * @brief This property holds the color of the text in the item.
107  *
108  * It is advised to use the default value.
109  * default: ``Kirigami.Theme.textColor``
110  *
111  * If custom text elements are inserted in an AbstractListItem,
112  * their color will have to be manually set with this property.
113  */
114  property color textColor: Kirigami.Theme.textColor
115 
116  /**
117  * @brief This property holds the color of the text when the item is pressed or selected.
118  *
119  * It is advised to use the default value.
120  * default: ``Kirigami.Theme.highlightedTextColor``
121  *
122  * If custom text elements are inserted in an AbstractListItem,
123  * their color will have to be manually set with this property.
124  */
125  property color activeTextColor: Kirigami.Theme.highlightedTextColor
126 
127  default property alias _default: listItem.contentItem
128 
129  // NOTE: Overrides action property of newer import versions which we can't use
130  /**
131  * @brief This property holds the item action.
132  * @property QtQuick.Controls.Action action
133  */
134  property QQC2.Action action
135 //END properties
136 
137  activeFocusOnTab: ListView.view ? false : true
138 
139  text: action ? action.text : undefined
140  checked: action ? action.checked : false
141  checkable: action ? action.checkable : false
142  onClicked: {
143  if (ListView.view && typeof index !== "undefined") {
144  ListView.view.currentIndex = index;
145  }
146  if (!action) {
147  return;
148  }
149 
150  action.trigger();
151  checked = Qt.binding(function() { return action.checked });
152  }
153  //Theme.inherit: false
154  //Theme.colorSet: Kirigami.Theme.View
155 
156  padding: Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
157 
158  leftPadding: padding * 2
159  topPadding: padding
160 
161  rightPadding: padding * 2
162  bottomPadding: padding
163 
164  implicitWidth: contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : Kirigami.Units.gridUnit * 12
165 
166  implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
167 
168  width: parent && parent.width > 0 ? parent.width : implicitWidth
169  Layout.fillWidth: true
170 
171  opacity: enabled ? 1 : 0.6
172 
173  height: implicitHeight
174 
175  onVisibleChanged: {
176  if (visible) {
177  height = Qt.binding(() => implicitHeight);
178  } else {
179  if (ListView.view && ListView.view.visible) {
180  height = 0;
181  }
182  }
183  }
184 
185  hoverEnabled: true
186 
187  Accessible.role: Accessible.ListItem
188  highlighted: focus && ListView.isCurrentItem && ListView.view && ListView.view.keyNavigationEnabled
189 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.