diff --git a/CMakeLists.txt b/CMakeLists.txt index fb2ebed..f794912 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ qt_add_qml_module(mirai src/qml/TaskItem.qml src/qml/forms/TaskForm.qml src/qml/components/TabSelector.qml + src/qml/components/Tag.qml src/qml/styles/MiraiColorPalette.qml src/qml/styles/CatppuccinFrappe.qml src/qml/views/ListView.qml diff --git a/src/Backend.cpp b/src/Backend.cpp index 59983ad..4db2813 100644 --- a/src/Backend.cpp +++ b/src/Backend.cpp @@ -123,9 +123,14 @@ void Backend::rebuildQMLTasksList() { lastDate = task.date; shouldShowDate = true; } + QList qStringTags; + for (auto& tag : task.getTags()) { + qStringTags.push_back(QString::fromStdString(tag)); + } QMLTasks.push_back({ .taskItem = &task, - .shouldShowDate = shouldShowDate + .shouldShowDate = shouldShowDate, + .tags = qStringTags }); } diff --git a/src/TaskItem.cpp b/src/TaskItem.cpp index 64c9ccb..3f0439a 100644 --- a/src/TaskItem.cpp +++ b/src/TaskItem.cpp @@ -23,6 +23,10 @@ QString QMLTaskItem::getDate() { return QString::fromStdString(taskItem->getDate()); } +QList QMLTaskItem::getTags() { + return tags; +} + bool QMLTaskItem::getShouldShowDate() { return shouldShowDate; } diff --git a/src/TaskItem.h b/src/TaskItem.h index 62e40d4..0687d84 100644 --- a/src/TaskItem.h +++ b/src/TaskItem.h @@ -21,6 +21,7 @@ struct QMLTaskItem { Q_PROPERTY(QString text READ getText) Q_PROPERTY(QString state READ getState) Q_PROPERTY(QString date READ getDate) + Q_PROPERTY(QList tags READ getTags) Q_PROPERTY(bool shouldShowDate READ getShouldShowDate) QML_VALUE_TYPE(taskItem) @@ -30,10 +31,12 @@ public: QString getRawFormat(); QString getState(); QString getDate(); + QList getTags(); bool getShouldShowDate(); mirai::TaskItem* taskItem; bool shouldShowDate = false; + QList tags; }; #endif diff --git a/src/qml/TaskItem.qml b/src/qml/TaskItem.qml index 8883c87..b41daa3 100644 --- a/src/qml/TaskItem.qml +++ b/src/qml/TaskItem.qml @@ -7,7 +7,6 @@ import QtQuick import QtQuick.Window import QtQuick.Layouts -import QtQuick.Controls import Mirai RowLayout { @@ -24,4 +23,16 @@ RowLayout { backend.updateTodo(index, modelData.state === 'DONE' ? "TODO" : "DONE", modelData.text, modelData.date) } } + + Repeater { + model: task.tags + Tag { + Layout.alignment: Qt.AlignVCenter + text: modelData + backgroundColor: colorPalette.selected.fieldBackground + textColor: colorPalette.selected.palette.sapphire + } + } + + } diff --git a/src/qml/components/Tag.qml b/src/qml/components/Tag.qml new file mode 100644 index 0000000..3d264ad --- /dev/null +++ b/src/qml/components/Tag.qml @@ -0,0 +1,28 @@ +/* + * 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 Mirai + +Rectangle { + id: control + property string text + property string backgroundColor + property string textColor + color: backgroundColor + implicitWidth: childrenRect.width + implicitHeight: childrenRect.height + radius: 8 + + AppText { + color: control.textColor + padding: 2 + leftPadding: 6 + rightPadding: 6 + text: control.text + } +}