Warning, /network/neochat/src/qml/SonnetConfigPage.qml is written in an unsupported language. File is not indexed.
0001 // SPDX-FileCopyrightText: 2021 Carl Schwan <carlschwan@kde.org>
0002 // SPDX-License-Identifier: LGPL-2.1-or-later
0003
0004 import QtQml
0005 import QtQuick
0006 import QtQuick.Controls as QQC2
0007 import QtQuick.Layouts
0008 import org.kde.kirigami as Kirigami
0009 import org.kde.sonnet as Sonnet
0010 import org.kde.kirigamiaddons.formcard as FormCard
0011 import org.kde.kirigamiaddons.delegates as Delegates
0012
0013 Kirigami.ScrollablePage {
0014 id: root
0015
0016 FormCard.FormHeader {
0017 title: i18nc("@title", "Spellchecking")
0018 }
0019 FormCard.FormCard {
0020 id: card
0021 property Sonnet.Settings settings: Sonnet.Settings {
0022 id: settings
0023 }
0024 FormCard.FormCheckDelegate {
0025 id: enable
0026 checked: settings.checkerEnabledByDefault
0027 text: i18n("Enable automatic spell checking")
0028 onCheckedChanged: {
0029 settings.checkerEnabledByDefault = checked;
0030 settings.save();
0031 }
0032 }
0033
0034 FormCard.FormDelegateSeparator { below: enable; above: skipUppercase }
0035
0036 FormCard.FormCheckDelegate {
0037 id: skipUppercase
0038 checked: settings.skipUppercase
0039 text: i18n("Ignore uppercase words")
0040 onCheckedChanged: {
0041 settings.skipUppercase = checked;
0042 settings.save();
0043 }
0044 }
0045
0046 FormCard.FormDelegateSeparator { below: skipUppercase; above: skipRunTogether }
0047
0048 FormCard.FormCheckDelegate {
0049 id: skipRunTogether
0050 checked: settings.skipRunTogether
0051 text: i18n("Ignore hyphenated words")
0052 onCheckedChanged: {
0053 settings.skipRunTogether = checked;
0054 settings.save();
0055 }
0056 }
0057
0058 FormCard.FormDelegateSeparator { below: skipRunTogether; above: autodetectLanguageCheckbox }
0059
0060 FormCard.FormCheckDelegate {
0061 id: autodetectLanguageCheckbox
0062 checked: settings.autodetectLanguage
0063 text: i18n("Detect language automatically")
0064 onCheckedChanged: {
0065 settings.autodetectLanguage = checked;
0066 settings.save();
0067 }
0068 }
0069
0070 FormCard.FormDelegateSeparator { below: autodetectLanguageCheckbox; above: selectedDefaultLanguage }
0071
0072 FormCard.FormComboBoxDelegate {
0073 id: selectedDefaultLanguage
0074 text: i18n("Selected default language:")
0075 model: isEmpty ? [{"display": i18n("None")}] : settings.dictionaryModel
0076 textRole: "display"
0077 displayMode: Kirigami.Settings.isMobile ? FormCard.FormComboBoxDelegate.Dialog : FormCard.FormComboBoxDelegate.Page
0078 valueRole: "languageCode"
0079 property bool isEmpty: false
0080 Component.onCompleted: {
0081 if (settings.dictionaryModel.rowCount() === 0) {
0082 isEmpty = true;
0083 } else {
0084 currentIndex = indexOfValue(settings.defaultLanguage);
0085 }
0086 }
0087 onActivated: settings.defaultLanguage = currentValue;
0088 }
0089
0090 FormCard.FormDelegateSeparator { below: selectedDefaultLanguage; above: spellCheckingLanguage }
0091
0092 FormCard.FormButtonDelegate {
0093 id: spellCheckingLanguage
0094 text: i18n("Additional spell checking languages")
0095 description: i18n("%1 will provide spell checking and suggestions for the languages listed here when autodetection is enabled.", Qt.application.displayName)
0096 enabled: autodetectLanguageCheckbox.checked
0097 onClicked: pageStack.pushDialogLayer(spellCheckingLanguageList, {}, {
0098 width: pageStack.width - Kirigami.Units.gridUnit * 5,
0099 height: pageStack.height - Kirigami.Units.gridUnit * 5,
0100 })
0101 }
0102
0103 FormCard.FormDelegateSeparator { below: spellCheckingLanguageList; above: personalDictionary }
0104
0105 FormCard.FormButtonDelegate {
0106 id: personalDictionary
0107 text: i18n("Open Personal Dictionary")
0108 onClicked: pageStack.pushDialogLayer(dictionaryPage, {}, {
0109 width: pageStack.width - Kirigami.Units.gridUnit * 5,
0110 height: pageStack.height - Kirigami.Units.gridUnit * 5,
0111 })
0112 }
0113
0114 property Component spellCheckingLanguageList: Component {
0115 id: spellCheckingLanguageList
0116 Kirigami.ScrollablePage {
0117 id: scroll
0118 title: i18nc("@title:window", "Spell checking languages")
0119 ListView {
0120 clip: true
0121 model: settings.dictionaryModel
0122 delegate: QQC2.CheckDelegate {
0123 onClicked: model.checked = checked
0124 Accessible.description: model.isDefault ? i18n("Default Language") : ''
0125 checked: model.checked
0126 width: scroll.width
0127 contentItem: RowLayout {
0128 QQC2.Label {
0129 Layout.fillWidth: true
0130 id: label
0131 text: model.display
0132 }
0133 Kirigami.Icon {
0134 source: "favorite"
0135 Layout.rightMargin: Kirigami.Units.largeSpacing * 2
0136 visible: model.isDefault
0137 HoverHandler {
0138 id: hover
0139 }
0140 QQC2.ToolTip {
0141 visible: hover.hovered
0142 text: i18n("Default Language")
0143 }
0144 }
0145 }
0146 }
0147 }
0148 }
0149 }
0150 }
0151
0152 Component {
0153 id: dictionaryPage
0154 Kirigami.ScrollablePage {
0155 title: i18n("Spell checking dictionary")
0156 footer: QQC2.ToolBar {
0157 contentItem: RowLayout {
0158 QQC2.TextField {
0159 id: dictionaryField
0160 Layout.fillWidth: true
0161 Accessible.name: placeholderText
0162 placeholderText: i18n("Add a new word to your personal dictionary…")
0163 }
0164 QQC2.Button {
0165 text: i18nc("@action:button", "Add word")
0166 icon.name: "list-add"
0167 enabled: dictionaryField.text.length > 0
0168 onClicked: {
0169 add(dictionaryField.text);
0170 dictionaryField.clear();
0171 if (instantApply) {
0172 settings.save();
0173 }
0174 }
0175 Layout.rightMargin: Kirigami.Units.largeSpacing
0176 }
0177 }
0178 }
0179 ListView {
0180 topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
0181 bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2)
0182
0183 model: settings.currentIgnoreList
0184 delegate: Delegates.RoundedItemDelegate {
0185 id: wordDelegate
0186
0187 required property var modelData
0188
0189 text: modelData
0190
0191 contentItem: RowLayout {
0192 spacing: Kirigami.Units.smallSpacing
0193
0194 Delegates.DefaultContentItem {
0195 itemDelegate: wordDelegate
0196 Layout.fillWidth: true
0197 }
0198
0199 QQC2.ToolButton {
0200 text: i18nc("@action:button", "Delete word")
0201 icon.name: "delete"
0202 display: QQC2.ToolButton.IconOnly
0203 onClicked: {
0204 remove(wordDelegate.modelData);
0205 if (instantApply) {
0206 settings.save();
0207 }
0208 }
0209
0210 QQC2.ToolTip.text: text
0211 QQC2.ToolTip.visible: hovered
0212 QQC2.ToolTip.delay: Kirigami.ToolTip.toolTipDelay
0213 }
0214 }
0215 }
0216 }
0217 }
0218 }
0219
0220 function add(word: string) {
0221 const dictionary = settings.currentIgnoreList;
0222 dictionary.push(word);
0223 settings.currentIgnoreList = dictionary;
0224 }
0225
0226 function remove(word: string) {
0227 settings.currentIgnoreList = settings.currentIgnoreList.filter((value, _, _) => {
0228 return value !== word;
0229 });
0230 }
0231 }