Warning, /libraries/kirigami-addons/src/treeview/qml/AbstractTreeItem.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 import QtQuick 2.12 0008 import QtQuick.Layouts 1.4 0009 import QtQuick.Controls 2.2 as QQC2 0010 import org.kde.kirigami 2.13 as Kirigami 0011 import org.kde.kitemmodels 1.0 0012 import org.kde.kirigamiaddons.treeview 1.0 as TreeView 0013 0014 /** 0015 * An item delegate for the TreeListView and TreeTableView components. 0016 * 0017 * It has the tree expander decoration but no content otherwise, 0018 * which has to be set as contentItem 0019 * 0020 */ 0021 QQC2.ItemDelegate { 0022 id: delegate 0023 0024 property alias decoration: decoration 0025 0026 /** 0027 * This propery holds the color for the text in the item. 0028 * It is advised to leave the default value (Kirigami.Theme.textColor) 0029 * 0030 * @Note If custom text elements are inserted in an AbstractListItem, 0031 * their color property will have to be manually bound with this property 0032 * 0033 * @since org.kde.kirigamiaddons.treeview 1.0 0034 */ 0035 property color textColor: Kirigami.Theme.textColor 0036 0037 /** 0038 * This property holds the color for the background of the item. 0039 * It is advised to leave the default value ("transparent"). 0040 * 0041 * @since org.kde.kirigamiaddons.treeview 1.0 0042 */ 0043 property color backgroundColor: "transparent" 0044 0045 /** 0046 * This property holds the background color to use if alternatingBackground is true. 0047 * It is advised to leave the default. 0048 * 0049 * @since org.kde.kirigamiaddons.treeview 1.0 0050 */ 0051 property color alternateBackgroundColor: Kirigami.Theme.alternateBackgroundColor 0052 0053 /** 0054 * This property holds the color for the text in the item when pressed or 0055 * selected. It is advised to leave the default value (Kirigami.Theme.highlightedTextColor). 0056 * 0057 * @note If custom text elements are inserted in an AbstractListItem, 0058 * their color property will have to be manually bound with this property. 0059 */ 0060 property color activeTextColor: Kirigami.Theme.highlightedTextColor 0061 0062 /** 0063 * This property holds the color for the background of the item when pressed or 0064 * selected. It is advised to leave the default value (Kirigami.Theme.highlightColor). 0065 */ 0066 property color activeBackgroundColor: Kirigami.Theme.highlightColor 0067 0068 width: parent && parent.width > 0 ? parent.width : implicitWidth 0069 0070 padding: Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing 0071 Accessible.role: Accessible.ListItem 0072 hoverEnabled: true 0073 height: visible ? implicitHeight : 0 0074 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding 0075 implicitWidth: contentItem ? contentItem.implicitWidth + leftPadding + rightPadding : Kirigami.Units.gridUnit * 12 0076 Layout.fillWidth: true 0077 0078 data: [ 0079 TreeView.TreeViewDecoration { 0080 id: decoration 0081 anchors { 0082 left: parent.left 0083 top:parent.top 0084 bottom: parent.bottom 0085 leftMargin: delegate.padding 0086 } 0087 parent: delegate 0088 parentDelegate: delegate 0089 model: delegate.ListView.view ? delegate.ListView.view.descendantsModel : 0090 (delegate.TableView.view ? delegate.TableView.view.descendantsModel : null) 0091 } 0092 ] 0093 0094 Keys.onLeftPressed: if (kDescendantExpandable && kDescendantExpanded) { 0095 decoration.model.collapseChildren(index); 0096 } else if (!kDescendantExpandable && kDescendantLevel > 0) { 0097 if (delegate.ListView.view) { 0098 const sourceIndex = decoration.model.mapToSource(decoration.model.index(index, 0)); 0099 const newIndex = decoration.model.mapFromSource(sourceIndex.parent); 0100 delegate.ListView.view.currentIndex = newIndex.row; 0101 } 0102 } 0103 0104 Keys.onRightPressed: if (kDescendantExpandable && delegate.ListView.view) { 0105 if (kDescendantExpanded) { 0106 ListView.view.incrementCurrentIndex(); 0107 } else { 0108 decoration.model.expandChildren(index); 0109 } 0110 } 0111 0112 activeFocusOnTab: ListView.view ? false : true 0113 0114 text: action ? action.text : undefined 0115 checked: action ? action.checked : false 0116 checkable: action ? action.checkable : false 0117 0118 onClicked: { 0119 if (ListView.view && typeof index !== "undefined") { 0120 ListView.view.currentIndex = index; 0121 } 0122 if (!action) { 0123 return; 0124 } 0125 0126 action.trigger(); 0127 checked = Qt.binding(function() { return action.checked }); 0128 } 0129 0130 onDoubleClicked: if (kDescendantExpandable) { 0131 decoration.model.toggleChildren(index); 0132 } 0133 0134 leftInset: Qt.application.layoutDirection !== Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0 0135 leftPadding: Qt.application.layoutDirection !== Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0 0136 0137 rightPadding: Qt.application.layoutDirection === Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0 0138 rightInset: Qt.application.layoutDirection === Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0 0139 0140 opacity: enabled ? 1 : 0.6 0141 0142 onVisibleChanged: { 0143 if (visible) { 0144 height = Qt.binding(() => { return implicitHeight; }) 0145 } else { 0146 if (ListView.view && ListView.view.visible) { 0147 height = 0; 0148 } 0149 } 0150 } 0151 0152 QtObject { 0153 id: internal 0154 property Flickable view: listItem.ListView.view || (listItem.parent ? listItem.parent.ListView.view : null) 0155 property bool indicateActiveFocus: listItem.pressed || Kirigami.Settings.tabletMode || listItem.activeFocus || (view ? view.activeFocus : false) 0156 } 0157 0158 highlighted: focus && ListView.isCurrentItem && ListView.view && ListView.view.keyNavigationEnabled 0159 }