163 lines
5.2 KiB
QML
163 lines
5.2 KiB
QML
// Includes relevant modules used by the QML
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import QtQuick.Controls as Controls
|
|
import org.kde.kirigami as Kirigami
|
|
|
|
// Provides basic features needed for all kirigami applications
|
|
Kirigami.ApplicationWindow {
|
|
// Unique identifier to reference this object
|
|
id: root
|
|
|
|
width: 600
|
|
height: 400
|
|
|
|
// Window title
|
|
// i18nc() makes a string translatable
|
|
// and provides additional context for the translators
|
|
title: i18nc("@title:window", "Day countdown")
|
|
|
|
globalDrawer: Kirigami.GlobalDrawer {
|
|
isMenu: true
|
|
actions: [
|
|
Kirigami.Action {
|
|
text: i18n("Quit")
|
|
icon.name: "application-exit-symbolic"
|
|
shortcut: StandardKey.Quit
|
|
onTriggered: Qt.quit()
|
|
}
|
|
]
|
|
}
|
|
|
|
// Set the first page that will be loaded when the app opens
|
|
// This can also be set to an id of a Kirigami.Page
|
|
pageStack.initialPage: Kirigami.ScrollablePage {
|
|
title: i18nc("@title", "Countdown")
|
|
actions: [
|
|
Kirigami.Action {
|
|
id: addAction
|
|
icon.name: "list-add-symbolic"
|
|
text: i18nc("@action:button", "Add countdown")
|
|
onTriggered: addDialog.open()
|
|
}
|
|
]
|
|
Kirigami.CardsListView {
|
|
id: cardsView
|
|
model: countdownModel
|
|
delegate: countdownDelegate
|
|
}
|
|
}
|
|
|
|
ListModel {
|
|
id: countdownModel
|
|
}
|
|
|
|
Component {
|
|
id: countdownDelegate
|
|
Kirigami.AbstractCard {
|
|
contentItem: Item {
|
|
implicitWidth: delegateLayout.implicitWidth
|
|
implicitHeight: delegateLayout.implicitHeight
|
|
GridLayout {
|
|
id: delegateLayout
|
|
anchors {
|
|
left: parent.left
|
|
top: parent.top
|
|
right: parent.right
|
|
}
|
|
rowSpacing: Kirigami.Units.largeSpacing
|
|
columnSpacing: Kirigami.Units.largeSpacing
|
|
columns: root.wideScreen ? 4 : 2
|
|
|
|
Kirigami.Heading {
|
|
Layout.fillWidth: true
|
|
level: 1
|
|
text: date
|
|
}
|
|
ColumnLayout {
|
|
Kirigami.Heading {
|
|
Layout.fillWidth: true
|
|
text: name
|
|
}
|
|
Kirigami.Separator {
|
|
Layout.fillWidth: true
|
|
visible: description.length > 0
|
|
}
|
|
Controls.Label {
|
|
Layout.fillWidth: true
|
|
wrapMode: Text.WordWrap
|
|
text: description
|
|
visible: description.length > 0
|
|
}
|
|
}
|
|
Controls.Button {
|
|
Layout.alignment: Qt.AlignRight
|
|
Layout.columnSpan: 2
|
|
text: i18n("Edit")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Kirigami.Dialog {
|
|
id: addDialog
|
|
title: i18nc("@title:window", "Add countdown")
|
|
standardButtons: Kirigami.Dialog.Ok | Kirigami.Dialog.Cancel
|
|
padding: Kirigami.Units.largeSpacing
|
|
preferredWidth: Kirigami.Units.gridUnit * 20
|
|
|
|
Kirigami.FormLayout {
|
|
Controls.TextField {
|
|
id: nameField
|
|
Kirigami.FormData.label: i18nc("@label:textbox", "Name*:")
|
|
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", "ISO Date*:")
|
|
inputMask: "D999-99-99"
|
|
onAccepted: addDialog.onAccepted()
|
|
}
|
|
Controls.Label {
|
|
text: "* = required fields"
|
|
}
|
|
}
|
|
|
|
Component.onCompleted: {
|
|
const button = standardButton(Kirigami.Dialog.Ok);
|
|
button.enabled = Qt.binding(() => requiredFieldsFilled());
|
|
}
|
|
|
|
function requiredFieldsFilled() {
|
|
return (nameField.text !== "" && dateField.acceptableInput);
|
|
}
|
|
|
|
function appendDataToModel() {
|
|
countdownModel.append({
|
|
name: nameField.text,
|
|
description: descriptionField.text,
|
|
date: new Date(dateField.text)
|
|
});
|
|
}
|
|
function clearFieldsAndClose() {
|
|
nameField.text = "";
|
|
descriptionField.text = "";
|
|
dateField.text = "";
|
|
addDialog.close();
|
|
}
|
|
|
|
onAccepted: {
|
|
if (!addDialog.requiredFieldsFilled())
|
|
return;
|
|
appendDataToModel();
|
|
clearFieldsAndClose();
|
|
}
|
|
}
|
|
}
|