Warning, /libraries/kirigami-addons/src/settings/CategorizedSettings.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de> 0002 // SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu> 0003 // SPDX-FileCopyrightText: 2021 Felipe Kinoshita <kinofhek@gmail.com> 0004 // SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org> 0005 // SPDX-License-Identifier: LGPL-2.0-or-later 0006 0007 import QtQml 2.15 0008 import QtQuick 2.15 0009 import QtQuick.Controls 2.15 as QQC2 0010 import QtQuick.Layouts 1.15 0011 import org.kde.kirigami 2.20 as Kirigami 0012 import org.kde.kirigamiaddons.delegates 1.0 as Delegates 0013 0014 /** 0015 * A container for setting actions showing them in a list view and displaying 0016 * the actual page next to it. 0017 * 0018 * To open a setting page, you should use `PageRow::pushDialogLayers` 0019 * 0020 * @since KirigamiAddons 0.11.0 0021 * @inherit kde::org::kirigami::PageRow 0022 */ 0023 Kirigami.PageRow { 0024 id: root 0025 0026 /** 0027 * @brief The default page that will be shown when opened. 0028 * 0029 * This only applies when the categorized settings object is wide enough to 0030 * show multiple pages. 0031 * 0032 * @see actions 0033 */ 0034 property string defaultPage 0035 0036 /** 0037 * @brief The list of pages for the settings 0038 */ 0039 property list<Kirigami.PagePoolAction> actions 0040 0041 property alias _stack: root 0042 property Kirigami.PagePool _pool: Kirigami.PagePool {} 0043 0044 readonly property string title: root.depth < 2 ? i18ndc("kirigami-addons", "@title:window", "Settings") :i18ndc("kirigami-addons", "@title:window", "Settings — %1", root.get(1).title) 0045 0046 property bool completed: false 0047 0048 bottomPadding: 0 0049 leftPadding: 0 0050 rightPadding: 0 0051 topPadding: 0 0052 0053 // Hack to not base all calculation based on main popup 0054 function applicationWindow() { 0055 return _fakeApplicationWindow; 0056 } 0057 0058 readonly property QtObject _fakeApplicationWindow: QtObject { 0059 readonly property Kirigami.PageRow pageStack: root 0060 readonly property bool controlsVisible: true 0061 readonly property QtObject globalDrawer: null 0062 readonly property QtObject contextDrawer: null 0063 readonly property double width: root.width 0064 readonly property double height: root.height 0065 readonly property var overlay: root 0066 } 0067 0068 globalToolBar { 0069 style: Kirigami.ApplicationHeaderStyle.ToolBar 0070 showNavigationButtons: if (root.currentIndex > 0) { 0071 Kirigami.ApplicationHeaderStyle.ShowBackButton 0072 } else { 0073 0 0074 } 0075 } 0076 0077 signal backRequested(var event) 0078 onBackRequested: event => { 0079 if (root.depth > 1 && !root.wideMode && root.currentIndex !== 0) { 0080 event.accepted = true; 0081 root.pop(); 0082 } 0083 } 0084 0085 columnView.columnWidth: Kirigami.Units.gridUnit * 13 0086 0087 initialPage: Kirigami.ScrollablePage { 0088 bottomPadding: 0 0089 leftPadding: 0 0090 rightPadding: 0 0091 topPadding: 0 0092 0093 titleDelegate: Kirigami.SearchField { 0094 Layout.fillWidth: true 0095 onTextChanged: listview.filterText = text.toLowerCase(); 0096 } 0097 0098 ListView { 0099 id: listview 0100 0101 property string filterText: "" 0102 property bool initDone: false 0103 0104 currentIndex: -1 0105 topMargin: Math.round(Kirigami.Units.smallSpacing / 2) 0106 bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2) 0107 0108 onWidthChanged: if (!initDone && root.width >= columnView.columnWidth) { 0109 let defaultAction = getActionByName(defaultPage); 0110 if (defaultAction) { 0111 defaultAction.trigger(); 0112 listview.currentIndex = indexOfAction(defaultAction); 0113 } else { 0114 actions[0].trigger(); 0115 listview.currentIndex = 0; 0116 if (root.currentItem.title.length === 0) { 0117 root.currentItem.title = actions[0].text; 0118 } 0119 } 0120 initDone = true; 0121 } 0122 model: { 0123 const isFiltering = filterText.length !== 0; 0124 let filteredActions = []; 0125 for (let i in actions) { 0126 const action = actions[i]; 0127 const actionPassesFilter = action.text.toLowerCase().includes(filterText); 0128 if (action.visible && (isFiltering ? actionPassesFilter : true)) { 0129 filteredActions.push(action); 0130 } 0131 } 0132 return filteredActions; 0133 } 0134 delegate: Delegates.RoundedItemDelegate { 0135 id: settingDelegate 0136 0137 required property int index 0138 required property var modelData 0139 0140 action: modelData 0141 checked: ListView.view.currentIndex === settingDelegate.index 0142 0143 onClicked: { 0144 ListView.view.currentIndex = settingDelegate.index; 0145 if (root.currentItem.title.length === 0) { 0146 root.currentItem.title = text; 0147 } 0148 } 0149 } 0150 } 0151 } 0152 0153 Component.onCompleted: { 0154 root.completed = true; 0155 } 0156 0157 function getActionByName(actionName) { 0158 for (let i in actions) { 0159 if (actions[i].actionName == actionName) { 0160 return actions[i]; 0161 } 0162 } 0163 } 0164 0165 function indexOfAction(action) { 0166 for (let i in actions) { 0167 if (actions[i] == action) { 0168 return i; 0169 } 0170 } 0171 } 0172 } 0173