From 42e957de863d06d70fc4a4741ee8ae6d02926527 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 14 Feb 2026 16:43:11 +0200 Subject: [PATCH] Extracted the calendar grid component Extracted the calendar grid component from the UserConfiguration dialog so that it can later be moved to a different dialog of its own, for better flexibility --- src/Project-Orion/CalendarGrid.qml | 24 ++++++++++----- src/Project-Orion/Main.qml | 2 +- src/Project-Orion/UserConfiguration.qml | 41 +++++++++++++++---------- src/Project-Orion/serialization.cpp | 10 ++++-- 4 files changed, 50 insertions(+), 27 deletions(-) diff --git a/src/Project-Orion/CalendarGrid.qml b/src/Project-Orion/CalendarGrid.qml index d1adc9c..9fac591 100644 --- a/src/Project-Orion/CalendarGrid.qml +++ b/src/Project-Orion/CalendarGrid.qml @@ -4,10 +4,14 @@ import QtQuick.Controls import QtQml Flickable { - id: flickable + id: flickableRoot width: 200 height: 200 + required property date currentDate + required property SystemPalette calendarActivePalette; + required property color disabledTextColor; + GridLayout { columns: 1 @@ -26,19 +30,27 @@ Flickable { Layout.fillWidth: true Layout.fillHeight: true delegate: Rectangle { - color: model.today ? activePalette.dark: activePalette.light - border.color: model.date === currentDate ? "green": "transparent" + color: flickableRoot.calendarActivePalette ? flickableRoot.calendarActivePalette.light : "black" + border.color: model.day === currentDate.getDay() ? "green": "transparent" border.width: 3 width: 30 height: 20 + MouseArea { + anchors.fill: parent + onClicked: { + if (model.day === 11) + console.log(model.day) + } + } + Text { anchors.centerIn: parent font.pixelSize: 12 horizontalAlignment: Text.AlignHCenter verticalAlignment: Text.AlignVCenter text: model.day - color: model.month === currentDate.getMonth() ? activePalette.text : disabledTextColor + color: model.month === currentDate.getMonth() ? calendarActivePalette.text : disabledTextColor } required property var model @@ -47,8 +59,4 @@ Flickable { property date currentlySelectedDate: currentDate; } } - - required property date currentDate - required property SystemPalette activePalette; - required property color disabledTextColor; } diff --git a/src/Project-Orion/Main.qml b/src/Project-Orion/Main.qml index 05034c5..2252c32 100644 --- a/src/Project-Orion/Main.qml +++ b/src/Project-Orion/Main.qml @@ -22,7 +22,7 @@ Window { } color: myPalette.window - id: name + id: root Appheader { diff --git a/src/Project-Orion/UserConfiguration.qml b/src/Project-Orion/UserConfiguration.qml index 6f63af2..a8f6df7 100644 --- a/src/Project-Orion/UserConfiguration.qml +++ b/src/Project-Orion/UserConfiguration.qml @@ -1,6 +1,6 @@ import QtQuick import QtQuick.Controls - +import QtQuick.Layouts Dialog { id: userDialog modal: true @@ -8,9 +8,10 @@ Dialog { width: 600 height: 400 - Row { - id: usernameRow - spacing: 100 + GridLayout { + id: userInformationGrid + columns: 2 + columnSpacing: 100 Label { id: nameFieldLabel @@ -19,27 +20,35 @@ Dialog { TextField { id: nameField + Layout.minimumWidth: 300; color: configActivePalette.text - width: 400 placeholderText: "Enter the new user's username" } - } - - Row { - id: dateOfBirthRow - anchors.top: usernameRow.bottom - spacing: 100 Label { id: dateOfBirthLabel text: qsTr("Date of birth:") } - CalendarGrid { - id: dateOfBirthGrid - currentDate: dateOfBirth - activePalette: configActivePalette; - disabledTextColor: configDisabledTextColor; + TextField { + id: dateOfBirthField + Layout.minimumWidth: 300; + readOnly: true + color: configActivePalette.text + placeholderText: "" + } + + Label { + id: dateOfDeathLabel + text: qsTr("Estimated date of death:") + } + + TextField { + id: dateOfDeathField + Layout.minimumWidth: 300; + readOnly: true + color: configActivePalette.text + placeholderText: "" } } diff --git a/src/Project-Orion/serialization.cpp b/src/Project-Orion/serialization.cpp index 2341ed4..990fbbf 100644 --- a/src/Project-Orion/serialization.cpp +++ b/src/Project-Orion/serialization.cpp @@ -8,7 +8,10 @@ UserList loadUserList(const QString &file) { QFile doc{std::filesystem::path{file.toStdString()}}; - doc.open(QFile::ReadOnly); + if (!doc.open(QFile::ReadOnly)) + { + throw std::runtime_error{"Could not open save file for reading"}; + } QString fileContents = doc.readAll(); @@ -41,7 +44,10 @@ UserList loadUserList(const QString &file) void saveUserList(const UserList &list, const QString &file) { QFile doc{std::filesystem::path{file.toStdString()}}; - doc.open(QFile::WriteOnly); + if(!doc.open(QFile::WriteOnly)) + { + throw std::runtime_error{"Could not open the save file for writing"}; + } QJsonArray container;