Support multiple files

This commit is contained in:
Vyn 2024-04-14 14:11:41 +02:00
parent f8f49233dc
commit 689eea07a7
22 changed files with 528 additions and 131 deletions

27
src/qml/AppComboBox.qml Normal file
View file

@ -0,0 +1,27 @@
/*
* 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.Controls
import Mirai
ComboBox {
id: control
contentItem: AppText {
anchors.fill: parent
text: control.currentText
verticalAlignment: Text.AlignVCenter
leftPadding: 10
}
background: Rectangle {
implicitWidth: 200
implicitHeight: 32
color: MiraiColorPalette.fieldBackground
radius: 4
}
}

View file

@ -28,6 +28,11 @@ Window {
property QtObject selected: MiraiColorPalette
}
function openSettings() {
filesForm.reset()
filesFormPopup.open()
}
function newTask() {
taskForm.taskToEdit = undefined
taskForm.taskToEditIndex = -1
@ -118,6 +123,25 @@ Window {
Layout.fillHeight: true
}
Popup {
id: filesFormPopup
width: parent.width * 0.75
implicitHeight: filesForm.height + padding * 2
x: Math.round((parent.width - width) / 2)
y: Math.round((parent.height * 0.4) / 2)
padding: 8
background: Rectangle {
border.color: colorPalette.selected.modalBorder
border.width: 2
color: colorPalette.selected.pane
radius: 4
}
FilesForm {
id: filesForm
width: parent.width
}
}
Popup {
id: taskFormPopup
width: parent.width * 0.75

View file

@ -11,6 +11,45 @@ import Mirai
ColumnLayout {
AppText {
text: "Files"
font.pixelSize: 32
}
Item { Layout.preferredHeight: 16 }
Repeater {
model: backend.files
Rectangle {
Layout.preferredHeight: childrenRect.height
Layout.fillWidth: true
color: backend.activeFilesFilter.includes(modelData.name) ? MiraiColorPalette.filterSelected : mouse.hovered ? MiraiColorPalette.filterHovered : "transparent"
radius: 4
AppText {
text: modelData.name
padding: 4
}
MouseArea {
anchors.fill: parent
onClicked: {
if (backend.activeFilesFilter.includes(modelData.name)) {
backend.removeFileFilter(modelData.name)
} else {
backend.addFileFilter(modelData.name)
}
}
HoverHandler {
id: mouse
acceptedDevices: PointerDevice.Mouse | PointerDevice.TouchPad
cursorShape: Qt.PointingHandCursor
}
}
}
}
Item { Layout.preferredHeight: 16 }
AppText {
text: "Tags"
font.pixelSize: 32
@ -58,4 +97,11 @@ ColumnLayout {
backend.hideCompletedTasks(!backend.shouldHideCompletedTasks)
}
}
/*AppButton {
text: `Settings`
onClicked: {
root.openSettings()
}
}*/
}

View file

@ -0,0 +1,52 @@
/*
* 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
// WIP
ColumnLayout {
id: form
spacing: 6
signal confirmed
function reset() {
internal.paths = backend.files.map(file => {
return {path: file.path, name: file.name}
})
}
QtObject {
id: internal
property var paths
}
Repeater {
model: internal.paths
ColumnLayout {
AppLineEdit {
text: modelData.name
}
AppLineEdit {
text: modelData.path
}
}
}
AppButton {
text: "Save"
onClicked: {
backend.
form.confirmed()
}
}
}

View file

@ -21,11 +21,32 @@ ColumnLayout {
newTodoContent.text = taskToEdit?.rawFormat ?? "- [ ] "
newTodoDate.text = taskToEdit?.date ?? ""
}
AppText {
text: "New task"
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
@ -39,17 +60,13 @@ ColumnLayout {
if (taskToEdit && taskToEditIndex !== undefined) {
backend.updateTodoFromRawFormat(taskToEditIndex, newTodoContent.text, newTodoDate.text)
} else {
backend.addTodoFromRawFormat(newTodoContent.text, newTodoDate.text)
backend.addTodoFromRawFormat(
file.currentValue,
newTodoContent.text,
newTodoDate.text
)
}
form.confirmed()
}
}
DateField {
id: newTodoDate
text: taskToEdit?.date ?? ""
textFieldComponent.placeholderText: "No date"
Layout.fillWidth: true
}
}