From f241ad0f092207e0eed6a916c1c03e3002a38e04 Mon Sep 17 00:00:00 2001 From: Fries Date: Tue, 27 Jun 2023 23:05:49 -0700 Subject: [PATCH] you can now add countdowns to the list --- src/KirigamiHelloWorld/ui/main.qml | 104 +++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 28 deletions(-) diff --git a/src/KirigamiHelloWorld/ui/main.qml b/src/KirigamiHelloWorld/ui/main.qml index feb0e84..2e6ecc9 100644 --- a/src/KirigamiHelloWorld/ui/main.qml +++ b/src/KirigamiHelloWorld/ui/main.qml @@ -3,23 +3,38 @@ import QtQuick.Controls 2.15 as Controls import QtQuick.Layouts 1.15 import org.kde.kirigami 2.20 as Kirigami + + + Kirigami.ApplicationWindow { id: root title: i18nc("@title:window", "HelloWorld") + function getDate(date) { + return i18n("%1 days", Math.round((date-Date.now())/86400000)) + } + + globalDrawer: Kirigami.GlobalDrawer { + isMenu: true + actions: [ + Kirigami.Action { + text: i18n("Quit") + icon.name: "gtk-quit" + shortcut: StandardKey.Quit + onTriggered: Qt.quit() + } + ] + } + ListModel { id: kountdownModel - ListElement { - name: "Meow" - description: "Meowy!" - date: 420 - } } Component { id: kountdownDelegate Kirigami.AbstractCard { contentItem: Item { + GridLayout { id: delegateLayout anchors { @@ -34,7 +49,7 @@ Kirigami.ApplicationWindow { Kirigami.Heading { Layout.fillHeight: true level: 1 - text: (date < 100000) ? date : i18n("%1 days", Math.round((date-Date.now()/86400000))) + text: getDate(date) } ColumnLayout { @@ -61,39 +76,72 @@ Kirigami.ApplicationWindow { text: i18n("Edit") } } + implicitWidth: delegateLayout.implicitWidth implicitHeight: delegateLayout.implicitHeight } } } + + Kirigami.OverlaySheet { + id: addSheet + header: Kirigami.Heading { + text: i18nc("@title:window", "Add meowdown") + } + Kirigami.FormLayout { + Controls.TextField { + id: nameField + Kirigami.FormData.label: i18nc("@label:textbox", "Name:") + placeholderText: i18n("Event Name (susquired)") + onAccepted: descriptionField.forceActiveFocus() + } + Controls.TextField { + id: descriptionField + Kirigami.FormData.label: i18nc("@label:textbox", "Description:") + placeholderText: i18n("Optional") + onAccepted: dateField.forceActiveFocus() + } + Controls.TextField { + id: dateField + Kirigami.FormData.label: i18nc("@label:textbox", "Date:") + placeholderText: i18n("YYYY-MM-DD") + inputMask: "0000-00-00" + } + Controls.Button { + id: doneButton + Layout.fillWidth: true + text: i18nc("@action:button", "Done") + enabled: nameField.text.length > 0 + onClicked: { + kountdownModel.append({ + name: nameField.text, + description: descriptionField.text, + date: Date.parse(dateField.text) + }) + nameField.text = "" + descriptionField.text = "" + dateField.text = "" + addSheet.close() + } + } + } + } + pageStack.initialPage: Kirigami.ScrollablePage { - title: i18nc("@title", "Kountdown") + title: i18nc("@title", "Meowdown") + + actions.main: Kirigami.Action { + id: addAction + icon.name: "list-add" + text: i18nc("@action:button", "add meowdown") + onTriggered: addSheet.open() + } + Kirigami.CardsListView { id: cardsView model: kountdownModel delegate: kountdownDelegate } - actions.main: Kirigami.Action { - id: addAction - icon.name: "list-add" - text: i18nc("@action:button", "Add meowdown") - onTriggered: kountdownModel.append({ - name: "Meowy", - description: "you just added a meowdown", - date: 21 - }) - } - } - globalDrawer: Kirigami.GlobalDrawer { - isMenu: true - actions: [ - Kirigami.Action { - text: i18n("Quit") - icon.name: "gtk-quit" - shortcut: StandardKey.Quit - onTriggered: Qt.quit() - } - ] } }