Warning, /graphics/okular/mobile/app/package/contents/ui/TreeItem.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.15
0008 import QtQuick.Layouts 1.15
0009 import QtQuick.Controls 2.15 as QQC2
0010 import org.kde.kirigami 2.17 as Kirigami
0011 import org.kde.kitemmodels 1.0
0012
0013 /**
0014 * An item delegate for the TreeListView and TreeTableView components.
0015 *
0016 * It has the tree expander decoration but no content otherwise,
0017 * which has to be set as contentItem
0018 *
0019 */
0020 QQC2.ItemDelegate {
0021 id: listItem
0022
0023 property alias decoration: decoration
0024
0025 width: ListView.view.width
0026
0027 data: [
0028 TreeViewDecoration {
0029 id: decoration
0030 anchors {
0031 left: parent.left
0032 top:parent.top
0033 bottom: parent.bottom
0034 leftMargin: listItem.padding
0035 }
0036 parent: listItem
0037 parentDelegate: listItem
0038 model: listItem.ListView.view ? listItem.ListView.view.model :null
0039 }
0040 ]
0041
0042 Keys.onLeftPressed: if (kDescendantExpandable && kDescendantExpanded) {
0043 decoration.model.collapseChildren(index);
0044 } else if (!kDescendantExpandable && kDescendantLevel > 0) {
0045 if (listItem.ListView.view) {
0046 const sourceIndex = decoration.model.mapToSource(decoration.model.index(index, 0));
0047 const newIndex = decoration.model.mapFromSource(sourceIndex.parent);
0048 listItem.listItem.ListView.view.currentIndex = newIndex.row;
0049 }
0050 }
0051
0052 Keys.onRightPressed: if (kDescendantExpandable) {
0053 if (kDescendantExpanded && listItem.ListView.view) {
0054 ListView.view.incrementCurrentIndex();
0055 } else {
0056 decoration.model.expandChildren(index);
0057 }
0058 }
0059
0060 onDoubleClicked: if (kDescendantExpandable) {
0061 decoration.model.toggleChildren(index);
0062 }
0063
0064 contentItem: Kirigami.Heading {
0065 wrapMode: Text.Wrap
0066 text: listItem.text
0067 level: 5
0068 width: listItem.ListView.view.width - (decoration.width + listItem.padding * 3 + Kirigami.Units.smallSpacing)
0069 }
0070
0071 leftInset: Qt.application.layoutDirection !== Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
0072 leftPadding: Qt.application.layoutDirection !== Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
0073
0074 rightPadding: Qt.application.layoutDirection === Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
0075 rightInset: Qt.application.layoutDirection === Qt.RightToLeft ? decoration.width + listItem.padding * 2 : 0
0076 }
0077