// 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 org.kde.kirigami as Kirigami import koutnet.app // in-memory only for now - the sheets and the Markdown preview work client-side, but // nothing is wired to HistoryManager yet, so sheets are lost on restart. The sheet // tabs used to be Rectangles with a hand-written radius and a MouseArea each; a // TabBar is the same thing with keyboard navigation and a focus ring. Kirigami.Page { id: root // The page is one of the surfaces the theme's tone is painted on: with a // wallpaper behind the window, this is what stands between it and the // conversation, and a scheme grey here is the grey the theme was picked to // get rid of. A plain Rectangle for the same reason ChatPage has one - Kirigami // draws a gradient behind a page, and a gradient over a photograph is a // second wash on top of the scrim. background: Rectangle { color: ThemePalette.surface } property int currentSheet: 0 title: i18nc("@title notes tab", "Notes") padding: 0 // one plural msgid rather than a word with a digit stuck on the end. function sheetName(number) { return i18ncp("@item note sheet name", "Sheet %1", "Sheet %1", number) } function sheetBody() { return sheetsModel.count > root.currentSheet ? sheetsModel.get(root.currentSheet).body : "" } ListModel { id: sheetsModel ListElement { title: ""; body: "" } Component.onCompleted: { if (count > 0 && get(0).title === "") setProperty(0, "title", root.sheetName(1)) } } actions: [ Kirigami.Action { text: previewToggle.checked ? i18nc("@action:button", "Editor") : i18nc("@action:button", "Preview") icon.name: previewToggle.checked ? "document-edit" : "view-preview" onTriggered: previewToggle.checked = !previewToggle.checked }, Kirigami.Action { text: i18nc("@action:button add a note sheet", "New sheet") icon.name: "list-add" onTriggered: { sheetsModel.append({ title: root.sheetName(sheetsModel.count + 1), body: "" }) root.currentSheet = sheetsModel.count - 1 } }, Kirigami.Action { text: i18nc("@action:button remove the current note sheet", "Delete sheet") icon.name: "edit-delete" enabled: sheetsModel.count > 1 onTriggered: { sheetsModel.remove(root.currentSheet) root.currentSheet = Math.max(0, root.currentSheet - 1) } } ] // not a control the user sees; it remembers what the action last asked for. QtObject { id: previewToggle property bool checked: false } header: QQC2.TabBar { currentIndex: root.currentSheet onCurrentIndexChanged: root.currentSheet = currentIndex Repeater { model: sheetsModel delegate: QQC2.TabButton { required property string title text: title } } } QQC2.ScrollView { anchors.fill: parent visible: !previewToggle.checked QQC2.TextArea { id: notesArea placeholderText: i18nc("@info:placeholder", "Write something") wrapMode: TextArea.Wrap text: root.sheetBody() onTextChanged: { if (sheetsModel.count > root.currentSheet) sheetsModel.setProperty(root.currentSheet, "body", text) } } } QQC2.ScrollView { anchors.fill: parent visible: previewToggle.checked Kirigami.SelectableLabel { width: root.width - Kirigami.Units.largeSpacing * 2 padding: Kirigami.Units.largeSpacing wrapMode: Text.Wrap textFormat: Text.MarkdownText text: root.sheetBody() } } }