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
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;
}

View File

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

View File

@@ -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: "<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)
{
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;