// SPDX-FileCopyrightText: 2026 Matvey Shcherbinin // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL import QtQuick import QtQuick.Layouts import QtQuick.Controls as QQC2 import QtQuick.Dialogs import org.kde.kirigami as Kirigami import org.kde.kirigamiaddons.formcard as FormCard import koutnet.app // Everything the window is painted with, in one place: the colour scheme, the // font, the icons, the controls style and the wallpaper. // // It is a component rather than a page of its own because the first-start // wizard shows the same section, one step of its own, and a settings page that // is also a wizard step is the reason it is written once here. What it changes // is read and written through the four singletons main.cpp hands the window - // appSettings for the wallpaper, and ColorSchemeSelector, fontSelector, // iconThemeSelector and styleSelector for the rest - so nothing in here holds // a copy of a setting that another part of the window could disagree with. // // The one thing it cannot do under a running window is the controls style: Qt // reads a style as the first control is made and not after, so picking one here // writes it down for the next launch and the row says so. ColumnLayout { id: root // Handed in by whoever shows it, so the cards line up with the rest of the // settings page rather than starting at the window edge. property real contentWidth: Kirigami.Units.gridUnit * 30 // Played by the theme in force, so a colour scheme pick can be seen against // the interface it is about rather than in the abstract. spacing: 0 FileDialog { id: wallpaperDialog title: i18nc("@title:window", "Choose a wallpaper") nameFilters: [i18nc("@item:inlistbox file dialog filter, keep the glob patterns", "Images (*.png *.jpg *.jpeg *.webp *.bmp *.gif)")] onAccepted: appSettings.wallpaperPath = selectedFile } // The fonts installed for this user, read once: the list does not change // while the page is up, and scanning every family on each open is wasted. readonly property var interfaceFonts: fontSelector.families() readonly property var fixedFonts: fontSelector.fixedFamilies() readonly property var iconThemes: iconThemeSelector.availableThemes() readonly property var controlStyles: styleSelector.availableStyles() // "Follow the desktop" is the first entry of both font lists and is not a // name, so an empty setting is that entry and anything else is the family. // The chooser is handed both lists rather than each row building its own. readonly property string followDesktopFont: i18nc("@item:inlistbox font", "Follow the desktop") // "Follow the desktop" is an entry of the icon theme and style lists too: // an unset setting is index zero, anything else is one past its place. function choiceIndex(names, current) { const at = names.indexOf(current) return at < 0 ? 0 : at + 1 } // A font row is a button, not a combo box, and that is performance, not // preference. A combo box builds its whole menu on creation and sorts on // every insertion, so two thousand families cost ten seconds per open. // A list view builds only what it draws. component FontChooser: Kirigami.Dialog { id: chooser // what is being chosen for, so the dialog says which of the two fonts it // is changing rather than asking the same question twice. property string purpose: "" // the list to choose from, and the family that is chosen now. property var families: [] property string current: "" // what the dialog hands back. It is the family already set until a row // is clicked, so accepting an untouched dialog leaves the setting alone. property string picked: chooser.current // the names after what has been typed: a plain list, so the view can draw // a few rows of it rather than every row of the whole thing. readonly property var matching: { const needle = chooser.filter.toLowerCase() if (needle.length === 0) return chooser.families return chooser.families.filter((family) => family.toLowerCase().includes(needle)) } title: chooser.purpose // what has been typed into the search field, which narrows the list // rather than setting anything: a chooser opens empty every time. property string filter: "" standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel onOpened: chooser.picked = chooser.current onAccepted: chooser.close() onRejected: chooser.close() width: Math.min(parent ? parent.width - Kirigami.Units.gridUnit * 2 : 400, Kirigami.Units.gridUnit * 30) height: Math.min(parent ? parent.height - Kirigami.Units.gridUnit * 2 : 400, Kirigami.Units.gridUnit * 24) contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.TextField { id: filterField Layout.fillWidth: true placeholderText: i18nc("@info:placeholder", "Search fonts") // a family is picked by typing the first letters of it, so the // field takes the keyboard focus the dialog opens with. focus: true selectByMouse: true onTextChanged: chooser.filter = text } QQC2.ScrollView { Layout.fillWidth: true Layout.fillHeight: true background: null ListView { id: familyList clip: true model: chooser.matching boundsBehavior: Flickable.StopAtBounds // the list opens on the family already set rather than at // its top, which with two thousand names is nowhere near. currentIndex: Math.max(0, chooser.matching.indexOf(chooser.picked)) onCurrentIndexChanged: familyList.positionViewAtIndex(currentIndex, ListView.Contain) delegate: QQC2.ItemDelegate { required property int index required property string modelData width: familyList.width text: modelData highlighted: familyList.currentIndex === index onClicked: { familyList.currentIndex = index chooser.picked = modelData } } Keys.onReturnPressed: { if (currentIndex >= 0 && currentIndex < count) chooser.picked = chooser.matching[currentIndex] } } } } } // The row a chooser is opened from: what the setting is called, what it is // set to now, and a button that opens the list. component FontRow: FormCard.AbstractFormDelegate { id: row // written to by the row that opens the chooser and by what is picked in // it, so the row and the setting between them hold no copy of the value. property string value: "" // what the setting does, said under it the way the form delegates with a // description of their own say it. property string description: "" signal accepted() background: null contentItem: RowLayout { spacing: Kirigami.Units.largeSpacing ColumnLayout { Layout.fillWidth: true spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: row.text color: AppPalette.text wrapMode: Text.Wrap } QQC2.Label { Layout.fillWidth: true text: row.description color: AppPalette.disabledText wrapMode: Text.Wrap maximumLineCount: 2 elide: Text.ElideRight } } QQC2.Button { Layout.alignment: Qt.AlignRight | Qt.AlignVCenter text: row.value.length > 0 ? row.value : root.followDesktopFont icon.name: "font-select" onClicked: row.accepted() } } } // A percentage a reader judges by looking, so a slider rather than a // spinner. One row keeps the wallpaper section's four questions alike. component PercentSlider: FormCard.AbstractFormDelegate { id: percentRow property string label: "" // the sentence shown over the number, when the value needs one. property string hint: "" property real percent: 0 signal moved(real value) background: null contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: percentRow.label } RowLayout { Layout.fillWidth: true spacing: Kirigami.Units.largeSpacing QQC2.Slider { id: percentSlider Layout.fillWidth: true from: 0 to: 100 stepSize: 1 value: percentRow.percent // moved rather than valueChanged: the latter also fires while // the binding settles, rewriting the setting on every open. onMoved: percentRow.moved(Math.round(percentSlider.value)) } QQC2.Label { text: i18nc("@info:status a percentage, %1 is a number", "%1%", Math.round(percentRow.percent)) color: AppPalette.disabledText QQC2.ToolTip.visible: percentRow.hint.length > 0 && hintHover.hovered QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay QQC2.ToolTip.text: percentRow.hint HoverHandler { id: hintHover } } } } } ThemedFormHeader { maximumWidth: root.contentWidth title: i18nc("@title:group", "Colour scheme") } ThemedFormCard { maximumWidth: root.contentWidth FormCard.FormComboBoxDelegate { id: schemeCombo text: i18nc("@label:listbox", "Colour scheme") description: i18nc("@info:whatsthis", "Every colour the wallpaper does not set comes from the desktop's own scheme.") // Index order matches ColorSchemeSelector.Mode, so no lookup table. model: [ i18nc("@item:inlistbox colour scheme", "Follow the system"), i18nc("@item:inlistbox colour scheme", "Light"), i18nc("@item:inlistbox colour scheme", "Dark"), ] currentIndex: ColorSchemeSelector.mode onActivated: (index) => ColorSchemeSelector.mode = index } } // Both choosers, opened by the rows that say what they change. FontChooser { id: fontChooser purpose: i18nc("@title:window", "Interface font") families: [root.followDesktopFont].concat(root.interfaceFonts) current: fontSelector.family.length > 0 ? fontSelector.family : root.followDesktopFont onAccepted: fontSelector.family = fontChooser.picked === root.followDesktopFont ? "" : fontChooser.picked } FontChooser { id: fixedFontChooser purpose: i18nc("@title:window", "Monospaced font") families: [root.followDesktopFont].concat(root.fixedFonts) current: fontSelector.fixedFamily.length > 0 ? fontSelector.fixedFamily : root.followDesktopFont onAccepted: fontSelector.fixedFamily = fixedFontChooser.picked === root.followDesktopFont ? "" : fixedFontChooser.picked } ThemedFormHeader { maximumWidth: root.contentWidth title: i18nc("@title:group", "Font") } ThemedFormCard { maximumWidth: root.contentWidth FontRow { id: fontRow text: i18nc("@label:listbox", "Interface font") description: i18nc("@info:whatsthis", "The font the window is drawn in. Follow the desktop unless a face is picked here.") value: fontSelector.family onAccepted: { fontChooser.filter = "" fontChooser.open() } } FormCard.FormDelegateSeparator { above: fontRow; below: sizeDelegate } // A slider's sibling: AbstractFormDelegate is what this version of the // form delegates has for a row that is not one of its own kinds. FormCard.AbstractFormDelegate { id: sizeDelegate background: null contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: i18nc("@label:spinbox the size the interface font is drawn at", "Font size") } RowLayout { Layout.fillWidth: true spacing: Kirigami.Units.largeSpacing QQC2.SpinBox { id: sizeSpin Layout.fillWidth: true from: 0 to: 40 value: fontSelector.pointSize // moved rather than valueChanged: the latter fires while // the binding settles and rewrites the setting on every open. onValueModified: fontSelector.pointSize = value } } QQC2.Label { Layout.fillWidth: true text: i18nc("@info:whatsthis left of the point size spinbox", "Zero follows the desktop's own size.") color: AppPalette.disabledText wrapMode: Text.Wrap } } } FormCard.FormDelegateSeparator { above: sizeDelegate; below: fixedFontRow } FontRow { id: fixedFontRow text: i18nc("@label:listbox the font for code and quoted text", "Monospaced font") description: i18nc("@info:whatsthis", "Used for code and quoted text, so a fixed-width face can be chosen without setting the whole window in one.") value: fontSelector.fixedFamily onAccepted: { fixedFontChooser.filter = "" fixedFontChooser.open() } } FormCard.FormDelegateSeparator { above: fixedFontRow; below: resetFontButton } FormCard.FormButtonDelegate { id: resetFontButton text: i18nc("@action:button", "Reset the font to the desktop's") icon.name: "edit-undo" enabled: fontSelector.customised onClicked: fontSelector.resetToSystem() } } ThemedFormHeader { maximumWidth: root.contentWidth title: i18nc("@title:group", "Icons") } ThemedFormCard { maximumWidth: root.contentWidth FormCard.FormComboBoxDelegate { id: iconCombo text: i18nc("@label:listbox", "Icon theme") description: i18nc("@info:whatsthis", "The icons the window is drawn with. Follow the desktop unless a theme is picked here.") model: [i18nc("@item:inlistbox icon theme", "Follow the desktop")].concat(root.iconThemes) currentIndex: root.choiceIndex(root.iconThemes, iconThemeSelector.theme) onActivated: (index) => iconThemeSelector.theme = index === 0 ? "" : root.iconThemes[index - 1] } FormCard.FormDelegateSeparator { above: iconCombo; below: resetIconButton } FormCard.FormButtonDelegate { id: resetIconButton text: i18nc("@action:button", "Reset the icons to the desktop's") icon.name: "edit-undo" enabled: iconThemeSelector.customised onClicked: iconThemeSelector.resetToSystem() } } ThemedFormHeader { maximumWidth: root.contentWidth title: i18nc("@title:group", "Style") } ThemedFormCard { maximumWidth: root.contentWidth FormCard.FormComboBoxDelegate { id: styleCombo text: i18nc("@label:listbox the Qt Quick Controls style", "Widget style") description: styleSelector.runningStyle() === styleSelector.style ? i18nc("@info:whatsthis", "The style the window is built out of.") : i18nc("@info:whatsthis", "Takes effect the next time KOutNet starts.") model: root.controlStyles currentIndex: Math.max(0, root.controlStyles.indexOf(styleSelector.style)) onActivated: (index) => styleSelector.style = root.controlStyles[index] } } ThemedFormHeader { maximumWidth: root.contentWidth title: i18nc("@title:group", "Wallpaper") } ThemedFormCard { maximumWidth: root.contentWidth // Said here as well as in the kcfg because a user of an encrypted messenger // is entitled to know the picture never goes on the wire. FormCard.FormButtonDelegate { id: wallpaperButton text: i18nc("@action:button", "Wallpaper") description: appSettings.wallpaperPath.length > 0 ? appSettings.wallpaperPath : i18nc("@info:whatsthis", "A picture behind the interface. Stays on this device and is never sent to anyone.") icon.name: "preferences-desktop-wallpaper" onClicked: wallpaperDialog.open() } FormCard.FormDelegateSeparator { above: wallpaperButton; below: wallpaperModeCombo } // All the ways a picture can be drawn over the window, in the order the // kcfg stores and Main.qml reads: stretched, fitted, cover, tiled, own size. FormCard.FormComboBoxDelegate { id: wallpaperModeCombo enabled: appSettings.wallpaperPath.length > 0 text: i18nc("@label:listbox how the wallpaper is drawn over the window", "Wallpaper display") textRole: "label" valueRole: "mode" model: [ { label: i18nc("@item:inlistbox the picture stretched over the whole window", "Stretch"), mode: 0 }, { label: i18nc("@item:inlistbox the picture scaled until it fits, edges left over", "Fit (whole image)"), mode: 1 }, { label: i18nc("@item:inlistbox the picture scaled until it covers, edges cut off", "Fill (crop edges)"), mode: 2 }, { label: i18nc("@item:inlistbox the picture repeated in both directions", "Tile (mosaic)"), mode: 3 }, { label: i18nc("@item:inlistbox the picture repeated downwards", "Tile vertically"), mode: 4 }, { label: i18nc("@item:inlistbox the picture repeated sideways", "Tile horizontally"), mode: 5 }, { label: i18nc("@item:inlistbox the picture unscaled, larger parts clipped", "Original size"), mode: 6 } ] // the stored mode and the list position are the same number. currentIndex: Math.max(0, Math.min(6, appSettings.wallpaperFillMode)) onActivated: appSettings.wallpaperFillMode = wallpaperModeCombo.currentValue } FormCard.FormDelegateSeparator { above: wallpaperModeCombo; below: wallpaperOpacityDelegate } // A slider because this value is judged by looking at the result. PercentSlider { id: wallpaperOpacityDelegate enabled: appSettings.wallpaperPath.length > 0 label: i18nc("@label:slider how much of the wallpaper shows through", "Wallpaper opacity") // the veil that keeps the text legible never reaches zero. hint: i18nc("@info:tooltip", "A veil over the picture keeps the interface readable even at the top of the range.") percent: appSettings.wallpaperOpacity onMoved: (value) => appSettings.wallpaperOpacity = value } FormCard.FormDelegateSeparator { above: wallpaperOpacityDelegate; below: wallpaperBlurDelegate } // Zero is the picture as it is. PercentSlider { id: wallpaperBlurDelegate enabled: appSettings.wallpaperPath.length > 0 label: i18nc("@label:slider how much the wallpaper is blurred", "Wallpaper blur") percent: appSettings.wallpaperBlur onMoved: (value) => appSettings.wallpaperBlur = value } FormCard.FormDelegateSeparator { above: wallpaperBlurDelegate; below: panelTransparencyDelegate } // The conversation list's column, judged as the interface the wallpaper's // blur and transparency are seen on: its own copy of the picture, // blurred and veiled by its own numbers, so the list can be misty alone. PercentSlider { id: panelTransparencyDelegate enabled: appSettings.wallpaperPath.length > 0 label: i18nc("@label:slider how transparent the conversation list's column is", "Chat list transparency") hint: i18nc("@info:tooltip", "Zero is the solid column the application has always drawn. A veil over the picture keeps the rows readable even at the top of the range.") percent: appSettings.panelTransparency onMoved: (value) => appSettings.panelTransparency = value } FormCard.FormDelegateSeparator { above: panelTransparencyDelegate; below: panelBlurDelegate } PercentSlider { id: panelBlurDelegate enabled: appSettings.wallpaperPath.length > 0 label: i18nc("@label:slider how much the picture behind the conversation list is blurred", "Chat list blur") hint: i18nc("@info:tooltip", "This blurs only behind the chat list, apart from the wallpaper blur above.") percent: appSettings.panelWallpaperBlur onMoved: (value) => appSettings.panelWallpaperBlur = value } FormCard.FormDelegateSeparator { above: panelBlurDelegate; below: profileBarBlurToggle } // Off is the plain toolbar the window draws with no wallpaper, so the // profile row can opt out of the picture entirely while the list keeps it. FormCard.FormSwitchDelegate { id: profileBarBlurToggle text: i18nc("@option:check", "Blur the profile bar") description: i18nc("@info:whatsthis", "When off, the profile row uses the normal toolbar background instead of the wallpaper.") checked: appSettings.profileBarBlurEnabled onToggled: appSettings.profileBarBlurEnabled = checked } FormCard.FormDelegateSeparator { above: profileBarBlurToggle; below: profileBarBlurDelegate } // The profile row wears the list's veil; only its blur is its own, so // it can stay sharp while the rows above are misty. PercentSlider { id: profileBarBlurDelegate enabled: appSettings.profileBarBlurEnabled && appSettings.wallpaperPath.length > 0 label: i18nc("@label:slider how much the picture behind the profile row is blurred", "Profile bar blur") hint: i18nc("@info:tooltip", "This blurs only behind the profile row, apart from the chat list's own blur above.") percent: appSettings.profileBarWallpaperBlur onMoved: (value) => appSettings.profileBarWallpaperBlur = value } FormCard.FormDelegateSeparator { above: profileBarBlurDelegate; below: clearWallpaperButton } FormCard.FormButtonDelegate { id: clearWallpaperButton text: i18nc("@action:button", "Remove wallpaper") icon.name: "edit-clear" enabled: appSettings.wallpaperPath.length > 0 onClicked: appSettings.wallpaperPath = "" } } ThemedFormHeader { maximumWidth: root.contentWidth title: i18nc("@title:group", "Colours") } ThemedFormCard { maximumWidth: root.contentWidth // Both picks work with a wallpaper and without one: a picked colour is // asked before the picture wherever the theme reads its colours, so it // stands in for the washed tone or the scheme's grey. The lightness // stays the scheme's, so every line keeps its contrast. ColorDialog { id: accentColorDialog title: i18nc("@title:window", "Choose an accent colour") selectedColor: appSettings.accentColor.length > 0 ? appSettings.accentColor : AppPalette.highlight onAccepted: appSettings.accentColor = accentColorDialog.selectedColor.toString() } ColorDialog { id: surfaceColorDialog title: i18nc("@title:window", "Choose a background colour") selectedColor: appSettings.surfaceColor.length > 0 ? appSettings.surfaceColor : AppPalette.background onAccepted: appSettings.surfaceColor = surfaceColorDialog.selectedColor.toString() } FormCard.FormColorDelegate { id: accentColorDelegate text: i18nc("@label:listbox the colour the interface marks things with", "Accent colour") // the swatch is what the accent paints right now - a picked colour // as washed, or the wallpaper's own - so row and window agree. color: ThemePalette.accent onClicked: accentColorDialog.open() } FormCard.FormDelegateSeparator { above: accentColorDelegate; below: surfaceColorDelegate } FormCard.FormColorDelegate { id: surfaceColorDelegate text: i18nc("@label:listbox the colour the surfaces of the interface are painted in", "Background colour") color: ThemePalette.surface onClicked: surfaceColorDialog.open() } FormCard.FormDelegateSeparator { above: surfaceColorDelegate; below: resetColoursButton } FormCard.FormButtonDelegate { id: resetColoursButton text: i18nc("@action:button", "Follow the wallpaper or colour scheme") icon.name: "edit-clear" // with neither pick made this row would answer nothing, so it // stands down rather than lying about what it would undo. enabled: appSettings.accentColor.length > 0 || appSettings.surfaceColor.length > 0 onClicked: { appSettings.accentColor = "" appSettings.surfaceColor = "" } } } ThemedFormCard { maximumWidth: root.contentWidth FormCard.AbstractFormDelegate { id: sizeLimitDelegate background: null contentItem: ColumnLayout { spacing: Kirigami.Units.smallSpacing QQC2.Label { Layout.fillWidth: true text: i18nc("@label:spinbox the largest file that may be sent", "Maximum attachment size") } QQC2.SpinBox { Layout.fillWidth: true from: 0 to: 4096 stepSize: 10 value: appSettings.maxAttachmentSizeMb onValueModified: appSettings.maxAttachmentSizeMb = value } QQC2.Label { Layout.fillWidth: true text: i18nc("@info:whatsthis left of the size spinbox", "In megabytes. Zero leaves the limit to the server, which will refuse a large file after it has been uploaded.") color: AppPalette.disabledText wrapMode: Text.Wrap } } } } }