you can now add countdowns to the list

This commit is contained in:
Fries 2023-06-27 23:05:49 -07:00
parent f1dfd94f06
commit f241ad0f09

View file

@ -3,23 +3,38 @@ import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.15 import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami import org.kde.kirigami 2.20 as Kirigami
Kirigami.ApplicationWindow { Kirigami.ApplicationWindow {
id: root id: root
title: i18nc("@title:window", "HelloWorld") 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 { ListModel {
id: kountdownModel id: kountdownModel
ListElement {
name: "Meow"
description: "Meowy!"
date: 420
}
} }
Component { Component {
id: kountdownDelegate id: kountdownDelegate
Kirigami.AbstractCard { Kirigami.AbstractCard {
contentItem: Item { contentItem: Item {
GridLayout { GridLayout {
id: delegateLayout id: delegateLayout
anchors { anchors {
@ -34,7 +49,7 @@ Kirigami.ApplicationWindow {
Kirigami.Heading { Kirigami.Heading {
Layout.fillHeight: true Layout.fillHeight: true
level: 1 level: 1
text: (date < 100000) ? date : i18n("%1 days", Math.round((date-Date.now()/86400000))) text: getDate(date)
} }
ColumnLayout { ColumnLayout {
@ -61,39 +76,72 @@ Kirigami.ApplicationWindow {
text: i18n("Edit") text: i18n("Edit")
} }
} }
implicitWidth: delegateLayout.implicitWidth implicitWidth: delegateLayout.implicitWidth
implicitHeight: delegateLayout.implicitHeight 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 { 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 { Kirigami.CardsListView {
id: cardsView id: cardsView
model: kountdownModel model: kountdownModel
delegate: kountdownDelegate 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()
}
]
} }
} }