Commit 0c1a88ae authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Add BasicMonthGridView



Signed-off-by: Claudio Cambra's avatarClaudio Cambra <claudio.cambra@gmail.com>
parent dba1f73c
// SPDX-FileCopyrightText: 2022 Claudio Cambra <claudio.cambra@gmail.com>
// SPDX-License-Identifier: GPL-2.0-or-later
import QtQuick 2.4
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.14 as Kirigami
import org.kde.kalendar 1.0 as Kalendar
import "dateutils.js" as DateUtils
DayGridView {
id: dayView
signal viewDatesChanged(date startDate, date firstDayOfMonth, int month, int year)
property bool isLarge: true
property bool isTiny: false
function setToDate(date) {
foregroundLoader.active = false;
month = date.getMonth();
year = date.getFullYear();
let firstDayOfMonth = new Date(year, month, 1);
let newDate = DateUtils.getFirstDayOfWeek(firstDayOfMonth)
// Handling adding and subtracting months in Javascript can get *really* messy.
newDate = DateUtils.addDaysToDate(newDate, 7)
if (newDate.getMonth() === month) {
newDate = DateUtils.addDaysToDate(newDate, - 7)
}
if (newDate.getDate() < 14) {
newDate = DateUtils.addDaysToDate(newDate, - 7)
}
startDate = newDate;
viewDatesChanged(startDate, firstDayOfMonth, month, year);
foregroundLoader.active = true;
}
objectName: "monthView"
dayHeaderDelegate: QQC2.Control {
Layout.maximumHeight: Kirigami.Units.gridUnit * 2
contentItem: Kirigami.Heading {
text: {
let longText = day.toLocaleString(Qt.locale(), "dddd");
let midText = day.toLocaleString(Qt.locale(), "ddd");
let shortText = midText.slice(0,1);
switch(Kalendar.Config.weekdayLabelLength) {
case Kalendar.Config.Full:
let chosenFormat = "dddd"
return dayView.isLarge ? longText : dayView.isTiny ? shortText : midText;
case Kalendar.Config.Abbreviated:
return dayView.isTiny ? shortText : midText;
case Kalendar.Config.Letter:
default:
return shortText;
}
}
level: 2
leftPadding: Kirigami.Units.smallSpacing
rightPadding: Kirigami.Units.smallSpacing
horizontalAlignment: {
switch(Kalendar.Config.weekdayLabelAlignment) {
case Kalendar.Config.Left:
return Text.AlignLeft;
case Kalendar.Config.Center:
return Text.AlignHCenter;
case Kalendar.Config.Right:
return Text.AlignRight;
default:
return Text.AlignHCenter;
}
}
}
}
weekHeaderDelegate: QQC2.Label {
padding: Kirigami.Units.smallSpacing
verticalAlignment: Qt.AlignTop
horizontalAlignment: Qt.AlignHCenter
text: DateUtils.getWeek(startDate, Qt.locale().firstDayOfWeek)
background: Rectangle {
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
}
}
}
......@@ -36,6 +36,8 @@ Item {
property bool isCurrentView: true
property bool dragDropEnabled: true
readonly property alias foregroundLoader: foregroundLoader
//Internal
property int numberOfLinesShown: 0
property int numberOfRows: (daysToShow / daysPerRow)
......
......@@ -14,13 +14,13 @@ import "dateutils.js" as DateUtils
Kirigami.Page {
id: monthPage
property bool initialMonth
property var openOccurrence
property date startDate
property date currentDate
property date firstDayOfMonth
property int month
property int year
property bool initialMonth: true
property var openOccurrence: null
property date currentDate: new Date()
property date firstDayOfMonth: DateUtils.getFirstDayOfMonth(currentDate)
property date startDate: DateUtils.getFirstDayOfWeek(firstDayOfMonth)
property int month: startDate.month()
property int year: startDate.getFullYear()
readonly property bool isLarge: width > Kirigami.Units.gridUnit * 40
readonly property bool isTiny: width < Kirigami.Units.gridUnit * 18
readonly property int mode: Kalendar.KalendarApplication.Month
......@@ -89,5 +89,28 @@ Kirigami.Page {
}
}
}
Loader {
id: basicViewLoader
anchors.fill: parent
active: false
sourceComponent: BasicMonthGridView {
anchors.fill: parent
isLarge: monthPage.isLarge
isTiny: monthPage.isTiny
dragDropEnabled: monthPage.dragDropEnabled
startDate: monthPage.startDate
currentDate: monthPage.currentDate
openOccurrence: monthPage.openOccurrence
onViewDatesChanged: {
monthPage.startDate = startDate;
monthPage.firstDayOfMonth = firstDayOfMonth;
monthPage.month = month;
monthPage.year = year;
}
}
}
}
......@@ -96,11 +96,13 @@ PathView {
active: isNextOrCurrentItem
asynchronous: !isCurrentItem
visible: status === Loader.Ready
sourceComponent: DayGridView {
id: dayView
objectName: "monthView"
sourceComponent: BasicMonthGridView {
width: pathView.width
height: pathView.height
isLarge: pathView.isLarge
isTiny: pathView.isTiny
isCurrentView: viewLoader.isCurrentItem
dragDropEnabled: pathView.dragDropEnabled
......@@ -108,54 +110,6 @@ PathView {
currentDate: pathView.currentDate
month: viewLoader.month
dayHeaderDelegate: QQC2.Control {
Layout.maximumHeight: Kirigami.Units.gridUnit * 2
contentItem: Kirigami.Heading {
text: {
let longText = day.toLocaleString(Qt.locale(), "dddd");
let midText = day.toLocaleString(Qt.locale(), "ddd");
let shortText = midText.slice(0,1);
switch(Kalendar.Config.weekdayLabelLength) {
case Kalendar.Config.Full:
let chosenFormat = "dddd"
return pathView.isLarge ? longText : pathView.isTiny ? shortText : midText;
case Kalendar.Config.Abbreviated:
return pathView.isTiny ? shortText : midText;
case Kalendar.Config.Letter:
default:
return shortText;
}
}
level: 2
leftPadding: Kirigami.Units.smallSpacing
rightPadding: Kirigami.Units.smallSpacing
horizontalAlignment: {
switch(Kalendar.Config.weekdayLabelAlignment) {
case Kalendar.Config.Left:
return Text.AlignLeft;
case Kalendar.Config.Center:
return Text.AlignHCenter;
case Kalendar.Config.Right:
return Text.AlignRight;
default:
return Text.AlignHCenter;
}
}
}
}
weekHeaderDelegate: QQC2.Label {
padding: Kirigami.Units.smallSpacing
verticalAlignment: Qt.AlignTop
horizontalAlignment: Qt.AlignHCenter
text: DateUtils.getWeek(startDate, Qt.locale().firstDayOfWeek)
background: Rectangle {
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
}
}
openOccurrence: pathView.openOccurrence
}
}
......
......@@ -20,6 +20,7 @@ SPDX-License-Identifier: CC0-1.0
<file alias="DayGridView.qml">contents/ui/MainViews/DayGridView.qml</file>
<file alias="SwipeableMonthGridView.qml">contents/ui/MainViews/SwipeableMonthGridView.qml</file>
<file alias="BasicMonthGridView.qml">contents/ui/MainViews/BasicMonthGridView.qml</file>
<file alias="MonthView.qml">contents/ui/MainViews/MonthView.qml</file>
<file alias="ScheduleView.qml">contents/ui/MainViews/ScheduleView.qml</file>
<file alias="TodoTreeView.qml">contents/ui/MainViews/TodoTreeView.qml</file>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment