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
This commit is contained in:
2026-02-14 16:43:11 +02:00
parent adc6dd35dd
commit 42e957de86
4 changed files with 50 additions and 27 deletions

View File

@@ -4,10 +4,14 @@ import QtQuick.Controls
import QtQml import QtQml
Flickable { Flickable {
id: flickable id: flickableRoot
width: 200 width: 200
height: 200 height: 200
required property date currentDate
required property SystemPalette calendarActivePalette;
required property color disabledTextColor;
GridLayout { GridLayout {
columns: 1 columns: 1
@@ -26,19 +30,27 @@ Flickable {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true Layout.fillHeight: true
delegate: Rectangle { delegate: Rectangle {
color: model.today ? activePalette.dark: activePalette.light color: flickableRoot.calendarActivePalette ? flickableRoot.calendarActivePalette.light : "black"
border.color: model.date === currentDate ? "green": "transparent" border.color: model.day === currentDate.getDay() ? "green": "transparent"
border.width: 3 border.width: 3
width: 30 width: 30
height: 20 height: 20
MouseArea {
anchors.fill: parent
onClicked: {
if (model.day === 11)
console.log(model.day)
}
}
Text { Text {
anchors.centerIn: parent anchors.centerIn: parent
font.pixelSize: 12 font.pixelSize: 12
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
text: model.day text: model.day
color: model.month === currentDate.getMonth() ? activePalette.text : disabledTextColor color: model.month === currentDate.getMonth() ? calendarActivePalette.text : disabledTextColor
} }
required property var model required property var model
@@ -47,8 +59,4 @@ Flickable {
property date currentlySelectedDate: currentDate; property date currentlySelectedDate: currentDate;
} }
} }
required property date currentDate
required property SystemPalette activePalette;
required property color disabledTextColor;
} }

View File

@@ -22,7 +22,7 @@ Window {
} }
color: myPalette.window color: myPalette.window
id: name id: root
Appheader Appheader
{ {

View File

@@ -1,6 +1,6 @@
import QtQuick import QtQuick
import QtQuick.Controls import QtQuick.Controls
import QtQuick.Layouts
Dialog { Dialog {
id: userDialog id: userDialog
modal: true modal: true
@@ -8,9 +8,10 @@ Dialog {
width: 600 width: 600
height: 400 height: 400
Row { GridLayout {
id: usernameRow id: userInformationGrid
spacing: 100 columns: 2
columnSpacing: 100
Label { Label {
id: nameFieldLabel id: nameFieldLabel
@@ -19,27 +20,35 @@ Dialog {
TextField { TextField {
id: nameField id: nameField
Layout.minimumWidth: 300;
color: configActivePalette.text color: configActivePalette.text
width: 400
placeholderText: "Enter the new user's username" placeholderText: "Enter the new user's username"
} }
}
Row {
id: dateOfBirthRow
anchors.top: usernameRow.bottom
spacing: 100
Label { Label {
id: dateOfBirthLabel id: dateOfBirthLabel
text: qsTr("Date of birth:") text: qsTr("Date of birth:")
} }
CalendarGrid { TextField {
id: dateOfBirthGrid id: dateOfBirthField
currentDate: dateOfBirth Layout.minimumWidth: 300;
activePalette: configActivePalette; readOnly: true
disabledTextColor: configDisabledTextColor; color: configActivePalette.text
placeholderText: "<empty>"
}
Label {
id: dateOfDeathLabel
text: qsTr("Estimated date of death:")
}
TextField {
id: dateOfDeathField
Layout.minimumWidth: 300;
readOnly: true
color: configActivePalette.text
placeholderText: "<empty>"
} }
} }

View File

@@ -8,7 +8,10 @@
UserList loadUserList(const QString &file) UserList loadUserList(const QString &file)
{ {
QFile doc{std::filesystem::path{file.toStdString()}}; 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(); QString fileContents = doc.readAll();
@@ -41,7 +44,10 @@ UserList loadUserList(const QString &file)
void saveUserList(const UserList &list, const QString &file) void saveUserList(const UserList &list, const QString &file)
{ {
QFile doc{std::filesystem::path{file.toStdString()}}; 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; QJsonArray container;