Warning, /frameworks/qqc2-desktop-style/org.kde.desktop/TreeViewDelegate.qml is written in an unsupported language. File is not indexed.
0001 /* 0002 SPDX-FileCopyrightText: Copyright (C) 2022 The Qt Company Ltd. 0003 SPDX-FileCopyrightText: 2017 Marco Martin <mart@kde.org> 0004 SPDX-FileCopyrightText: 2023 ivan tkachenko <me@ratijas.tk> 0005 SPDX-FileCopyrightText: 2023 David Redondo <kde@david-redondo.de> 0006 SPDX-License-Identifier: LGPL-3.0-only OR GPL-2.0-or-later 0007 */ 0008 0009 import QtQuick 0010 import QtQuick.Layouts 0011 import QtQuick.Templates as T 0012 import org.kde.kirigami as Kirigami 0013 import org.kde.qqc2desktopstyle.private as StylePrivate 0014 import org.kde.desktop.private as Private 0015 0016 T.TreeViewDelegate { 0017 id: controlRoot 0018 0019 implicitWidth: leftMargin + __contentIndent + implicitContentWidth + rightMargin + (mirrored ? leftPadding : rightPadding) 0020 implicitHeight: Math.max(implicitBackgroundHeight, implicitContentHeight, implicitIndicatorHeight) + topPadding + bottomPadding 0021 0022 // This is the default size of the indicator when using Breeze aka pixelMetric("treeviewindentation") 0023 indentation: indicator ? indicator.width : 20 0024 0025 leftMargin: Kirigami.Units.smallSpacing 0026 rightMargin: Kirigami.Units.smallSpacing 0027 spacing: Kirigami.Units.smallSpacing 0028 0029 topPadding: Kirigami.Units.smallSpacing 0030 bottomPadding: Kirigami.Units.smallSpacing 0031 0032 Kirigami.Theme.colorSet: highlighted ? Kirigami.Theme.Selection : Kirigami.Theme.View 0033 Kirigami.Theme.inherit: false 0034 0035 leftPadding: !mirrored ? leftMargin + __contentIndent : 0 0036 rightPadding: mirrored ? leftMargin + __contentIndent : 0 0037 0038 highlighted: controlRoot.selected || controlRoot.current 0039 || ((controlRoot.treeView.selectionBehavior === TableView.SelectRows 0040 || controlRoot.treeView.selectionBehavior === TableView.SelectionDisabled) 0041 && controlRoot.row === controlRoot.treeView.currentRow) 0042 0043 0044 icon.width: Kirigami.Units.iconSizes.smallMedium 0045 icon.height: Kirigami.Units.iconSizes.smallMedium 0046 0047 T.ToolTip.visible: (Kirigami.Settings.tabletMode ? down : hovered) && (contentItem.truncated ?? false) 0048 T.ToolTip.text: controlRoot.model.display 0049 T.ToolTip.delay: Kirigami.Units.toolTipDelay 0050 0051 required property int row 0052 required property int column 0053 required property var model 0054 readonly property var modelIndex: treeView.index(row, column) 0055 readonly property real __contentIndent: !isTreeNode ? 0 : (depth * indentation) + (indicator ? indicator.width + spacing : 0) 0056 0057 // The indicator is only visible when the item has children, so this is only the closest branch indicator (+arrow) - the rest of the branch indicator lines are below 0058 indicator: StylePrivate.StyleItem { 0059 readonly property real __indicatorIndent: controlRoot.leftMargin + (controlRoot.depth * controlRoot.indentation) 0060 x: !controlRoot.mirrored ? __indicatorIndent : controlRoot.width - __indicatorIndent - width 0061 height: parent.height 0062 width: pixelMetric("treeviewindentation") 0063 hover: hover.hovered 0064 elementType: "itembranchindicator" 0065 on: controlRoot.expanded 0066 selected: controlRoot.highlighted || controlRoot.checked || (controlRoot.pressed && !controlRoot.checked) 0067 properties: { 0068 "isItem": true, 0069 "hasChildren": true, 0070 "hasSibling": controlRoot.treeView.model.rowCount(controlRoot.modelIndex.parent) > controlRoot.modelIndex.row + 1 0071 } 0072 HoverHandler { 0073 id: hover 0074 } 0075 } 0076 0077 // The rest of the branch indicators, this is outside of the background so consumers can freely 0078 // modify it without losing it 0079 StylePrivate.ItemBranchIndicators { 0080 visible: controlRoot.isTreeNode 0081 height: parent.height 0082 x: controlRoot.mirrored ? controlRoot.width - controlRoot.leftMargin - width : controlRoot.leftMargin 0083 modelIndex: controlRoot.modelIndex 0084 selected: controlRoot.highlighted || controlRoot.checked || (controlRoot.pressed && !controlRoot.checked) 0085 rootIndex: controlRoot.treeView.rootIndex 0086 } 0087 0088 background: Private.DefaultListItemBackground { 0089 Kirigami.Theme.colorSet: Kirigami.Theme.View 0090 Kirigami.Theme.inherit: false 0091 control: controlRoot 0092 } 0093 0094 contentItem: RowLayout { 0095 property alias truncated: textLabel.truncated 0096 spacing: Kirigami.Units.smallSpacing 0097 Kirigami.Icon { 0098 Layout.alignment: Qt.AlignVCenter 0099 visible: controlRoot.icon.name !== "" || controlRoot.icon.source.toString() !== "" || controlRoot.model.decoration !== undefined 0100 source: controlRoot.icon.name !== "" ? controlRoot.icon.name : controlRoot.icon.source.toString() !== "" ? controlRoot.icon.source : controlRoot.model.decoration 0101 Layout.preferredHeight: controlRoot.icon.height 0102 Layout.preferredWidth: controlRoot.icon.width 0103 selected: controlRoot.highlighted || controlRoot.checked || (controlRoot.pressed && !controlRoot.checked) 0104 } 0105 Label { 0106 id: textLabel 0107 text: controlRoot.model.display 0108 font: controlRoot.font 0109 color: controlRoot.highlighted || controlRoot.checked || (controlRoot.pressed && !controlRoot.checked) 0110 ? Kirigami.Theme.highlightedTextColor 0111 : (controlRoot.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor) 0112 elide: Text.ElideRight 0113 visible: text !== "" 0114 horizontalAlignment: Text.AlignLeft 0115 verticalAlignment: Text.AlignVCenter 0116 Layout.alignment: Qt.AlignLeft 0117 Layout.fillWidth: true 0118 } 0119 } 0120 }