Warning, /office/klevernotes/src/contents/ui/sideBar/TreeView.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2022 Louis Schul <schul9louis@gmail.com>
0003 
0004 import QtQuick
0005 import QtQuick.Controls 2 as Controls
0006 
0007 import org.kde.kirigamiaddons.delegates 1 as Delegates
0008 import org.kde.kirigami 2.5 as Kirigami
0009 import org.kde.kitemmodels 1
0010 
0011 import org.kde.Klever 1.0
0012 
0013 Controls.ScrollView {
0014     id: scrollView
0015 
0016     property alias model: descendantsModel.model
0017     property alias currentItem: treeView.currentItem
0018     property alias currentIndex: treeView.currentIndex
0019     property alias descendantsModel: descendantsModel
0020 
0021     signal itemRightClicked(clickedItem: TreeItem)
0022 
0023     ListView {
0024         id: treeView
0025 
0026         model: KDescendantsProxyModel {
0027             id: descendantsModel
0028         } 
0029 
0030         delegate: TreeItem {
0031             id: treeItem
0032 
0033             onItemRightClicked: {
0034                 scrollView.itemRightClicked(treeItem)
0035             }
0036             onWantFocusChanged: if (wantFocus) {
0037                 clicked()
0038             }
0039             onWantExpandChanged: if (wantExpand) {
0040                 if (!kDescendantExpanded) {
0041                     descendantsModel.toggleChildren(index)
0042                 }
0043             }
0044             onClicked: {
0045                 descendantsModel.toggleChildren(index)
0046                 forceActiveFocus()
0047                 const mainWindow = applicationWindow()
0048                 if (mainWindow.isMainPage()) {
0049                     const mainPage = mainWindow.pageStack.currentItem
0050                     mainPage.currentlySelected = treeItem
0051                     treeView.currentIndex = index
0052                 }
0053             }
0054         }
0055     }
0056 
0057     function getModelIndex(rowIndex) {
0058         return descendantsModel.mapToSource(descendantsModel.index(rowIndex, 0))
0059     }
0060 }