Kirigami-addons

SonnetConfigPage.qml
1// SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4import QtQml
5import QtQuick
6import QtQuick.Controls as QQC2
7import QtQuick.Layouts
8import org.kde.kirigami as Kirigami
9import org.kde.kirigami.delegates as KirigamiDelegates
10import org.kde.sonnet as Sonnet
11import org.kde.kirigamiaddons.formcard as FormCard
12import org.kde.kirigamiaddons.delegates as Delegates
13
14FormCard.FormCardPage {
15 id: root
16
17 readonly property Sonnet.Settings settings: Sonnet.Settings {
18 id: settings
19 }
20
21 readonly property Kirigami.PageRow pageStack: QQC2.ApplicationWindow.window.pageStack
22
23 function add(word: string): void {
24 const dictionary = root.settings.currentIgnoreList;
25 dictionary.push(word);
26 root.settings.currentIgnoreList = dictionary;
27 }
28
29 function remove(word: string): void {
30 root.settings.currentIgnoreList = root.settings.currentIgnoreList.filter((value, _, _) => {
31 return value !== word;
32 });
33 }
34
35 FormCard.FormCard {
36 Layout.topMargin: Kirigami.Units.largeSpacing * 2
37
38 FormCard.FormCheckDelegate {
39 id: enable
40 checked: root.settings.checkerEnabledByDefault
41 text: i18ndc("kirigami-addons6", "@label:checkbox", "Enable automatic spell checking")
42 onCheckedChanged: {
43 root.settings.checkerEnabledByDefault = checked;
44 root.settings.save();
45 }
46 }
47
48 FormCard.FormDelegateSeparator {
49 below: enable; above: skipUppercase
50 }
51
52 FormCard.FormCheckDelegate {
53 id: skipUppercase
54 checked: root.settings.skipUppercase
55 text: i18ndc("kirigami-addons6", "@label:checkbox", "Ignore uppercase words")
56 onCheckedChanged: {
57 root.settings.skipUppercase = checked;
58 root.settings.save();
59 }
60 }
61
62 FormCard.FormDelegateSeparator {
63 below: skipUppercase; above: skipRunTogether
64 }
65
66 FormCard.FormCheckDelegate {
67 id: skipRunTogether
68 checked: root.settings.skipRunTogether
69 text: i18ndc("kirigami-addons6", "@label:checkbox", "Ignore hyphenated words")
70 onCheckedChanged: {
71 root.settings.skipRunTogether = checked;
72 root.settings.save();
73 }
74 }
75
76 FormCard.FormDelegateSeparator {
77 below: skipRunTogether; above: autodetectLanguageCheckbox
78 }
79
80 FormCard.FormCheckDelegate {
81 id: autodetectLanguageCheckbox
82 checked: root.settings.autodetectLanguage
83 text: i18ndc("kirigami-addons6", "@label:checkbox", "Detect language automatically")
84 onCheckedChanged: {
85 root.settings.autodetectLanguage = checked;
86 root.settings.save();
87 }
88 }
89
90 FormCard.FormDelegateSeparator {
91 below: autodetectLanguageCheckbox; above: selectedDefaultLanguage
92 }
93
94 FormCard.FormComboBoxDelegate {
95 id: selectedDefaultLanguage
96 text: i18ndc("kirigami-addons6", "@label:listbox", "Selected default language:")
97 model: isEmpty ? [{"display": i18ndc("kirigami-addons6", "No selected language", "None")}] : root.settings.dictionaryModel
98 textRole: "display"
99 valueRole: "languageCode"
100 property bool isEmpty: false
101 Component.onCompleted: {
102 if (root.settings.dictionaryModel.rowCount() === 0) {
103 isEmpty = true;
104 } else {
105 currentIndex = indexOfValue(root.settings.defaultLanguage);
106 }
107 }
108 onActivated: root.settings.defaultLanguage = currentValue;
109 }
110
111 FormCard.FormDelegateSeparator {
112 below: selectedDefaultLanguage; above: spellCheckingLanguage
113 }
114
115 FormCard.FormButtonDelegate {
116 id: spellCheckingLanguage
117 text: i18ndc("kirigami-addons6", "@label:listbox", "Additional Spell Checking Languages")
118 description: i18nd("kirigami-addons6", "%1 will provide spell checking and suggestions for the languages listed here when autodetection is enabled.", Qt.application.displayName)
119 onClicked: root.pageStack.pushDialogLayer(spellCheckingLanguageList, {}, {
120 width: root.pageStack.width - Kirigami.Units.gridUnit * 5,
121 height: root.pageStack.height - Kirigami.Units.gridUnit * 5,
122 })
123 }
124
125 FormCard.FormDelegateSeparator {
126 below: spellCheckingLanguage; above: personalDictionary
127 }
128
129 FormCard.FormButtonDelegate {
130 id: personalDictionary
131 text: i18ndc("kirigami-addons6", "@action:button", "Open Personal Dictionary")
132 onClicked: root.pageStack.pushDialogLayer(dictionaryPage, {}, {
133 width: root.pageStack.width - Kirigami.Units.gridUnit * 5,
134 height: root.pageStack.height - Kirigami.Units.gridUnit * 5,
135 })
136 }
137
138 data: [
139 Component {
140 id: spellCheckingLanguageList
141 Kirigami.ScrollablePage {
142 id: scroll
143 title: i18ndc("kirigami-addons6", "@title:window", "Spell checking languages")
144 enabled: autodetectLanguageCheckbox.checked
145 ListView {
146 clip: true
147 model: root.settings.dictionaryModel
148 delegate: KirigamiDelegates.CheckSubtitleDelegate {
149 width: ListView.view.width
150
151 text: model.display
152 action: Kirigami.Action {
153 onTriggered: model.checked = checked
154 }
155 Accessible.description: model.isDefault ? i18nd("kirigami-addons6", "Default Language") : ''
156 checked: model.checked
157
158 icon.source: model.isDefault ? "favorite" : undefined
159 }
160 }
161 }
162 },
163
164 Component {
165 id: dictionaryPage
167 title: i18ndc("kirigami-addons6", "@title:window", "Spell checking dictionary")
168 footer: QQC2.ToolBar {
169 contentItem: RowLayout {
170 QQC2.TextField {
171 id: dictionaryField
172 Layout.fillWidth: true
173 Accessible.name: placeholderText
174 placeholderText: i18ndc("kirigami-addons6", "Placeholder message", "Add a new word to your personal dictionary…")
175 }
176 QQC2.Button {
177 text: i18ndc("kirigami-addons6", "@action:button", "Add Word")
178 icon.name: "list-add"
179 enabled: dictionaryField.text.length > 0
180 onClicked: {
181 root.add(dictionaryField.text);
182 dictionaryField.clear();
183 if (instantApply) {
184 root.settings.save();
185 }
186 }
187 Layout.rightMargin: Kirigami.Units.largeSpacing
188 }
189 }
190 }
191 ListView {
192 topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
193 bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2)
194
195 model: root.settings.currentIgnoreList
196 delegate: Delegates.RoundedItemDelegate {
197 id: wordDelegate
198
199 required property string modelData
200
201 text: modelData
202
203 contentItem: RowLayout {
204 spacing: Kirigami.Units.smallSpacing
205
206 Delegates.DefaultContentItem {
207 itemDelegate: wordDelegate
208 Layout.fillWidth: true
209 }
210
211 QQC2.ToolButton {
212 text: i18ndc("kirigami-addons6", "@action:button", "Delete word")
213 icon.name: "delete"
214 display: QQC2.ToolButton.IconOnly
215 onClicked: {
216 root.remove(wordDelegate.modelData);
217 if (instantApply) {
218 root.settings.save();
219 }
220 }
221
222 QQC2.ToolTip.text: text
223 QQC2.ToolTip.visible: hovered
224 QQC2.ToolTip.delay: Kirigami.ToolTip.toolTipDelay
225 }
226 }
227 }
228 }
229 }
230 }
231 ]
232 }
233}
A single card that follows a form style.
Definition FormCard.qml:35
QString i18ndc(const char *domain, const char *context, const char *text, const TYPE &arg...)
QString i18nd(const char *domain, const char *text, const TYPE &arg...)
QString name(GameStandardAction id)
KGuiItem remove()
void clear()
QString & remove(QChar ch, Qt::CaseSensitivity cs)
QFuture< void > filter(QThreadPool *pool, Sequence &sequence, KeepFunctor &&filterFunction)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:54:39 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.