Warning, /libraries/kirigami-addons/src/treeview/qml/TreeViewDecoration.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.6
0008 import QtQuick.Layouts 1.4
0009 import QtQuick.Controls 2.2 as QQC2
0010 import QtQuick.Templates 2.2 as T2
0011 import org.kde.kitemmodels 1.0
0012 import org.kde.kirigami 2.14 as Kirigami
0013 
0014 /**
0015  * The tree expander decorator for item views.
0016  *
0017  * It will have a "> v" expander button graphics, and will have indentation on the left
0018  * depending on the level of the tree the item is in
0019  *
0020  * It is recommanded to directly use RoundedTreeDelegate instead of this component.
0021  */
0022 RowLayout {
0023     /**
0024      * This property holds the delegate there this decoration will live in.
0025      * It needs to be assigned explicitly by the developer.
0026      */
0027     required property T2.ItemDelegate parentDelegate
0028 
0029     /**
0030      * This property holds the KDescendantsProxyModel the view is showing.
0031      * It needs to be assigned explicitly by the developer.
0032      */
0033     required property KDescendantsProxyModel model
0034 
0035     /**
0036      * This property holds the color of the decoration highlight.
0037      */
0038     property color decorationHighlightColor
0039 
0040     /**
0041      * This property holds the index of the item.
0042      *
0043      * Provided by the model/ListView
0044      */
0045     required property int index
0046 
0047     /**
0048      * This property holds the descendant level of the item.
0049      *
0050      * Provided by the model/ListView
0051      */
0052     required property int kDescendantLevel
0053 
0054     /**
0055      * This property holds whether this item has siblings.
0056      *
0057      * Provided by the model/ListView
0058      */
0059     required property var kDescendantHasSiblings
0060 
0061     /**
0062      * This property holds whether the item is expandable.
0063      *
0064      * Provided by the model/ListView
0065      */
0066     required property bool kDescendantExpandable
0067 
0068     /**
0069      * This property holds whether the item is expanded.
0070      *
0071      * Provided by the model/ListView
0072      */
0073     required property bool kDescendantExpanded
0074 
0075     Layout.topMargin: -parentDelegate.topPadding
0076     Layout.bottomMargin: -parentDelegate.bottomPadding
0077     Repeater {
0078         model: kDescendantLevel - 1
0079         delegate: Item {
0080             Layout.preferredWidth: controlRoot.width
0081             Layout.fillHeight: true
0082 
0083             Rectangle {
0084                 anchors {
0085                     horizontalCenter: parent.horizontalCenter
0086                     top: parent.top
0087                     bottom: parent.bottom
0088                 }
0089                 visible: kDescendantHasSiblings[modelData]
0090                 color: Kirigami.Theme.textColor
0091                 opacity: 0.5
0092                 width: 1
0093             }
0094         }
0095     }
0096     T2.Button {
0097         id: controlRoot
0098         Layout.preferredWidth: Kirigami.Units.gridUnit
0099         Layout.fillHeight: true
0100         enabled: kDescendantExpandable
0101         onClicked: model.toggleChildren(parentDelegate.index)
0102         contentItem: Item {
0103             id: styleitem
0104             implicitWidth: Kirigami.Units.gridUnit
0105             Rectangle {
0106                 anchors {
0107                     horizontalCenter: parent.horizontalCenter
0108                     top: parent.top
0109                     bottom: expander.visible ? expander.top : parent.verticalCenter
0110                 }
0111                 color: Kirigami.Theme.textColor
0112                 opacity: 0.5
0113                 width: 1
0114             }
0115             Kirigami.Icon {
0116                 id: expander
0117                 anchors.centerIn: parent
0118                 width: Kirigami.Units.iconSizes.small
0119                 height: width
0120                 source: kDescendantExpanded ? "go-down-symbolic" : (Qt.application.layoutDirection == Qt.RightToLeft ? "go-previous-symbolic" : "go-next-symbolic")
0121                 isMask: true
0122                 color: controlRoot.hovered ? decorationLayout.decorationHighlightColor ? decorationLayout.decorationHighlightColor : Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
0123                 Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
0124                 Behavior on color { ColorAnimation { duration: Kirigami.Units.shortDuration; easing.type: Easing.InOutQuad } }
0125                 visible: kDescendantExpandable
0126             }
0127             Rectangle {
0128                 anchors {
0129                     horizontalCenter: parent.horizontalCenter
0130                     top: expander.visible ? expander.bottom : parent.verticalCenter
0131                     bottom: parent.bottom
0132                 }
0133                 visible: kDescendantHasSiblings[kDescendantHasSiblings.length - 1]
0134                 color: Kirigami.Theme.textColor
0135                 opacity: 0.5
0136                 width: 1
0137             }
0138             Rectangle {
0139                 anchors {
0140                     verticalCenter: parent.verticalCenter
0141                     left: expander.visible ? expander.right : parent.horizontalCenter
0142                     right: parent.right
0143                 }
0144                 color: Kirigami.Theme.textColor
0145                 opacity: 0.5
0146                 height: 1
0147             }
0148         }
0149         background: Item {}
0150     }
0151 }