Kirigami-addons

CategorizedSettings.qml
1// SPDX-FileCopyrightText: 2020 Tobias Fella <fella@posteo.de>
2// SPDX-FileCopyrightText: 2021 Carl Schwan <carl@carlschwan.eu>
3// SPDX-FileCopyrightText: 2021 Felipe Kinoshita <kinofhek@gmail.com>
4// SPDX-FileCopyrightText: 2021 Marco Martin <mart@kde.org>
5// SPDX-License-Identifier: LGPL-2.0-or-later
6
7import QtQml 2.15
8import QtQuick 2.15
9import QtQuick.Controls 2.15 as QQC2
10import QtQuick.Layouts 1.15
11import org.kde.kirigami 2.20 as Kirigami
12import org.kde.kirigamiaddons.delegates 1.0 as Delegates
13
14/**
15 * A container for setting actions showing them in a list view and displaying
16 * the actual page next to it.
17 *
18 * To open a setting page, you should use `PageRow::pushDialogLayers`
19 *
20 * @since KirigamiAddons 0.11.0
21 * @inherit kde::org::kirigami::PageRow
22 * @deprecated Since 1.3.0, use ConfigurationsView instead.
23 */
24Kirigami.PageRow {
25 id: root
26
27 /**
28 * @brief The default page that will be shown when opened.
29 *
30 * This only applies when the categorized settings object is wide enough to
31 * show multiple pages.
32 *
33 * @see actions
34 */
35 property string defaultPage
37 /**
38 * @brief The list of pages for the settings
39 */
40 property list<Kirigami.PagePoolAction> actions
41
42 property alias _stack: root
43 property Kirigami.PagePool _pool: Kirigami.PagePool {}
44
45 readonly property string title: root.depth < 2 ? i18ndc("kirigami-addons6", "@title:window", "Settings") :i18ndc("kirigami-addons6", "@title:window", "Settings — %1", root.get(1).title)
46
47 property bool completed: false
48
49 bottomPadding: 0
50 leftPadding: 0
51 rightPadding: 0
52 topPadding: 0
53
54 // Hack to not base all calculation based on main popup
55 function applicationWindow() {
56 return _fakeApplicationWindow;
57 }
58
59 readonly property QtObject _fakeApplicationWindow: QtObject {
60 readonly property Kirigami.PageRow pageStack: root
61 readonly property bool controlsVisible: true
62 readonly property QtObject globalDrawer: null
63 readonly property QtObject contextDrawer: null
64 readonly property double width: root.width
65 readonly property double height: root.height
66 readonly property var overlay: root
67 }
68
69 globalToolBar {
70 style: Kirigami.ApplicationHeaderStyle.ToolBar
71 showNavigationButtons: if (root.currentIndex > 0) {
72 Kirigami.ApplicationHeaderStyle.ShowBackButton
73 } else {
74 0
75 }
76 }
77
78 signal backRequested(var event)
79 onBackRequested: event => {
80 if (root.depth > 1 && !root.wideMode && root.currentIndex !== 0) {
81 event.accepted = true;
82 root.pop();
83 }
84 }
85
86 columnView.columnWidth: Kirigami.Units.gridUnit * 13
87
88 initialPage: Kirigami.ScrollablePage {
89 bottomPadding: 0
90 leftPadding: 0
91 rightPadding: 0
92 topPadding: 0
93
94 titleDelegate: RowLayout {
95 Layout.fillWidth: true
96
97 QQC2.ToolButton {
98 icon.name: "go-previous-view"
99 text: i18ndc("kirigami-addons6", "@action:intoolbar", "Go back")
100 display: QQC2.AbstractButton.IconOnly
101 onClicked: pageStack.layers.pop()
102 visible: pageStack.layers.depth > 1
103 }
104
106 Layout.fillWidth: true
107 onTextChanged: listview.filterText = text.toLowerCase();
108 }
109 }
110
111 ListView {
112 id: listview
113
114 property string filterText: ""
115 property bool initDone: false
116
117 currentIndex: -1
118 topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
119 bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2)
120
121 onWidthChanged: if (!initDone && root.width >= Kirigami.Units.gridUnit * 30) {
122 let defaultAction = getActionByName(defaultPage);
123 if (defaultAction) {
124 defaultAction.trigger();
125 listview.currentIndex = indexOfAction(defaultAction);
126 } else {
127 actions[0].trigger();
128 listview.currentIndex = 0;
129 if (root.currentItem.title.length === 0) {
130 root.currentItem.title = actions[0].text;
131 }
132 }
133 initDone = true;
134 }
135 model: {
136 const isFiltering = filterText.length !== 0;
137 let filteredActions = [];
138 for (let i in actions) {
139 const action = actions[i];
140 const actionPassesFilter = action.text.toLowerCase().includes(filterText);
141 if (action.visible && (isFiltering ? actionPassesFilter : true)) {
142 filteredActions.push(action);
143 }
144 }
145 return filteredActions;
146 }
147 delegate: Delegates.RoundedItemDelegate {
148 id: settingDelegate
149
150 required property int index
151 required property var modelData
152
153 action: modelData
154 checked: ListView.view.currentIndex === settingDelegate.index
155
156 onClicked: {
157 ListView.view.currentIndex = settingDelegate.index;
158 if (root.currentItem.title.length === 0) {
159 root.currentItem.title = text;
160 }
161 }
162 }
163 }
164 }
165
166 Component.onCompleted: {
167 root.completed = true;
168 }
169
170 function getActionByName(actionName) {
171 for (let i in actions) {
172 if (actions[i].actionName == actionName) {
173 return actions[i];
174 }
175 }
176 }
177
178 function indexOfAction(action) {
179 for (let i in actions) {
180 if (actions[i] == action) {
181 return i;
182 }
183 }
184 }
185}
186
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:05:53 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.