mirai/src/qml/forms/TaskForm.qml

72 lines
1.6 KiB
QML

/*
* Mirai. Copyright (C) 2024 Vyn
* This file is licensed under version 3 of the GNU General Public License (GPL-3.0-only)
* The license can be found in the LICENSE file or at https://www.gnu.org/licenses/gpl-3.0.txt
*/
import QtQuick
import QtQuick.Window
import QtQuick.Controls
import QtQuick.Layouts
import Mirai
ColumnLayout {
id: form
property var taskToEdit
property int taskToEditIndex
spacing: 6
signal confirmed
onTaskToEditChanged: {
newTodoContent.text = taskToEdit?.rawFormat ?? "- [ ] "
newTodoDate.text = taskToEdit?.date ?? ""
}
AppText {
text: "New/Edit task"
}
AppComboBox {
id: file
textRole: "text"
valueRole: "value"
// Set the initial currentIndex to the value stored in the backend.
Component.onCompleted: currentIndex = 0
model: backend.files.map(file => (
{ value: file.path, text: qsTr(file.name) }
))
onActivated: {
console.log(currentValue)
}
}
DateField {
id: newTodoDate
text: taskToEdit?.date ?? ""
textFieldComponent.placeholderText: "No date"
Layout.fillWidth: true
}
AppLineEdit {
id: newTodoContent
Layout.fillWidth: true
placeholderText: "Enter your new task..."
text: taskToEdit?.rawFormat ?? ""
Keys.onReturnPressed: {
if (newTodoContent.text == "") {
return
}
if (taskToEdit && taskToEditIndex !== undefined) {
backend.updateTodoFromRawFormat(taskToEditIndex, newTodoContent.text, newTodoDate.text)
} else {
backend.addTodoFromRawFormat(
file.currentValue,
newTodoContent.text,
newTodoDate.text != "" ? newTodoDate.text : "No date"
)
}
form.confirmed()
}
}
}