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 {
0035             below: enable
0036             above: skipUppercase
0037         }
0038 
0039         FormCard.FormCheckDelegate {
0040             id: skipUppercase
0041             checked: settings.skipUppercase
0042             text: i18n("Ignore uppercase words")
0043             onCheckedChanged: {
0044                 settings.skipUppercase = checked;
0045                 settings.save();
0046             }
0047         }
0048 
0049         FormCard.FormDelegateSeparator {
0050             below: skipUppercase
0051             above: skipRunTogether
0052         }
0053 
0054         FormCard.FormCheckDelegate {
0055             id: skipRunTogether
0056             checked: settings.skipRunTogether
0057             text: i18n("Ignore hyphenated words")
0058             onCheckedChanged: {
0059                 settings.skipRunTogether = checked;
0060                 settings.save();
0061             }
0062         }
0063 
0064         FormCard.FormDelegateSeparator {
0065             below: skipRunTogether
0066             above: autodetectLanguageCheckbox
0067         }
0068 
0069         FormCard.FormCheckDelegate {
0070             id: autodetectLanguageCheckbox
0071             checked: settings.autodetectLanguage
0072             text: i18n("Detect language automatically")
0073             onCheckedChanged: {
0074                 settings.autodetectLanguage = checked;
0075                 settings.save();
0076             }
0077         }
0078 
0079         FormCard.FormDelegateSeparator {
0080             below: autodetectLanguageCheckbox
0081             above: selectedDefaultLanguage
0082         }
0083 
0084         FormCard.FormComboBoxDelegate {
0085             id: selectedDefaultLanguage
0086             text: i18n("Selected default language:")
0087             model: isEmpty ? [
0088                 {
0089                     "display": i18n("None")
0090                 }
0091             ] : settings.dictionaryModel
0092             textRole: "display"
0093             displayMode: Kirigami.Settings.isMobile ? FormCard.FormComboBoxDelegate.Dialog : FormCard.FormComboBoxDelegate.Page
0094             valueRole: "languageCode"
0095             property bool isEmpty: false
0096             Component.onCompleted: {
0097                 if (settings.dictionaryModel.rowCount() === 0) {
0098                     isEmpty = true;
0099                 } else {
0100                     currentIndex = indexOfValue(settings.defaultLanguage);
0101                 }
0102             }
0103             onActivated: settings.defaultLanguage = currentValue
0104         }
0105 
0106         FormCard.FormDelegateSeparator {
0107             below: selectedDefaultLanguage
0108             above: spellCheckingLanguage
0109         }
0110 
0111         FormCard.FormButtonDelegate {
0112             id: spellCheckingLanguage
0113             text: i18n("Additional spell checking languages")
0114             description: i18n("%1 will provide spell checking and suggestions for the languages listed here when autodetection is enabled.", Qt.application.displayName)
0115             enabled: autodetectLanguageCheckbox.checked
0116             onClicked: pageStack.pushDialogLayer(spellCheckingLanguageList, {}, {
0117                 width: pageStack.width - Kirigami.Units.gridUnit * 5,
0118                 height: pageStack.height - Kirigami.Units.gridUnit * 5
0119             })
0120         }
0121 
0122         FormCard.FormDelegateSeparator {
0123             below: spellCheckingLanguageList
0124             above: personalDictionary
0125         }
0126 
0127         FormCard.FormButtonDelegate {
0128             id: personalDictionary
0129             text: i18n("Open Personal Dictionary")
0130             onClicked: pageStack.pushDialogLayer(dictionaryPage, {}, {
0131                 width: pageStack.width - Kirigami.Units.gridUnit * 5,
0132                 height: pageStack.height - Kirigami.Units.gridUnit * 5
0133             })
0134         }
0135 
0136         property Component spellCheckingLanguageList: Component {
0137             id: spellCheckingLanguageList
0138             Kirigami.ScrollablePage {
0139                 id: scroll
0140                 title: i18nc("@title:window", "Spell checking languages")
0141                 ListView {
0142                     clip: true
0143                     model: settings.dictionaryModel
0144                     delegate: QQC2.CheckDelegate {
0145                         onClicked: model.checked = checked
0146                         Accessible.description: model.isDefault ? i18n("Default Language") : ''
0147                         checked: model.checked
0148                         width: scroll.width
0149                         contentItem: RowLayout {
0150                             QQC2.Label {
0151                                 id: label
0152                                 Layout.fillWidth: true
0153                                 text: model.display
0154                             }
0155                             Kirigami.Icon {
0156                                 source: "favorite"
0157                                 Layout.rightMargin: Kirigami.Units.largeSpacing * 2
0158                                 visible: model.isDefault
0159                                 HoverHandler {
0160                                     id: hover
0161                                 }
0162                                 QQC2.ToolTip {
0163                                     visible: hover.hovered
0164                                     text: i18n("Default Language")
0165                                 }
0166                             }
0167                         }
0168                     }
0169                 }
0170             }
0171         }
0172     }
0173 
0174     Component {
0175         id: dictionaryPage
0176         Kirigami.ScrollablePage {
0177             title: i18n("Spell checking dictionary")
0178             footer: QQC2.ToolBar {
0179                 contentItem: RowLayout {
0180                     QQC2.TextField {
0181                         id: dictionaryField
0182                         Layout.fillWidth: true
0183                         Accessible.name: placeholderText
0184                         placeholderText: i18n("Add a new word to your personal dictionary…")
0185                     }
0186                     QQC2.Button {
0187                         text: i18nc("@action:button", "Add word")
0188                         icon.name: "list-add"
0189                         enabled: dictionaryField.text.length > 0
0190                         onClicked: {
0191                             add(dictionaryField.text);
0192                             dictionaryField.clear();
0193                             if (instantApply) {
0194                                 settings.save();
0195                             }
0196                         }
0197                         Layout.rightMargin: Kirigami.Units.largeSpacing
0198                     }
0199                 }
0200             }
0201             ListView {
0202                 topMargin: Math.round(Kirigami.Units.smallSpacing / 2)
0203                 bottomMargin: Math.round(Kirigami.Units.smallSpacing / 2)
0204 
0205                 model: settings.currentIgnoreList
0206                 delegate: Delegates.RoundedItemDelegate {
0207                     id: wordDelegate
0208 
0209                     required property var modelData
0210 
0211                     text: modelData
0212 
0213                     contentItem: RowLayout {
0214                         spacing: Kirigami.Units.smallSpacing
0215 
0216                         Delegates.DefaultContentItem {
0217                             itemDelegate: wordDelegate
0218                             Layout.fillWidth: true
0219                         }
0220 
0221                         QQC2.ToolButton {
0222                             text: i18nc("@action:button", "Delete word")
0223                             icon.name: "delete"
0224                             display: QQC2.ToolButton.IconOnly
0225                             onClicked: {
0226                                 remove(wordDelegate.modelData);
0227                                 if (instantApply) {
0228                                     settings.save();
0229                                 }
0230                             }
0231 
0232                             QQC2.ToolTip.text: text
0233                             QQC2.ToolTip.visible: hovered
0234                             QQC2.ToolTip.delay: Kirigami.ToolTip.toolTipDelay
0235                         }
0236                     }
0237                 }
0238             }
0239         }
0240     }
0241 
0242     function add(word: string) {
0243         const dictionary = settings.currentIgnoreList;
0244         dictionary.push(word);
0245         settings.currentIgnoreList = dictionary;
0246     }
0247 
0248     function remove(word: string) {
0249         settings.currentIgnoreList = settings.currentIgnoreList.filter((value, _, _) => {
0250             return value !== word;
0251         });
0252     }
0253 }