Commit 4a117774 authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Cleaned up unneeded code and fixed automatic date matching on view switch in month view



Signed-off-by: Claudio Cambra's avatarClaudio Cambra <claudio.cambra@gmail.com>
parent 48b4cd9f
......@@ -12,17 +12,15 @@ import "dateutils.js" as DateUtils
DayGridView {
id: dayView
signal viewDatesChanged(date startDate, date firstDayOfMonth, int month, int year)
signal viewDatesChanged(date startDate, date firstDayOfMonth)
property bool isLarge: true
property bool isTiny: false
readonly property bool isLarge: width > Kirigami.Units.gridUnit * 40
readonly property bool isTiny: width < Kirigami.Units.gridUnit * 18
function setToDate(date) {
foregroundLoader.active = false;
month = date.getMonth();
year = date.getFullYear();
let firstDayOfMonth = new Date(year, month, 1);
firstDayOfMonth = new Date(date.getFullYear(), date.getMonth(), 1);
let newDate = DateUtils.getFirstDayOfWeek(firstDayOfMonth)
// Handling adding and subtracting months in Javascript can get *really* messy.
......@@ -36,7 +34,7 @@ DayGridView {
}
startDate = newDate;
viewDatesChanged(startDate, firstDayOfMonth, month, year);
viewDatesChanged(startDate, firstDayOfMonth);
foregroundLoader.active = true;
}
......
......@@ -21,17 +21,21 @@ Item {
property int daysToShow: daysPerRow * 6
property int daysPerRow: 7
property double weekHeaderWidth: Kalendar.Config.showWeekNumbers ? Kirigami.Units.gridUnit * 1.5 : 0
property date currentDate
property date currentDate: new Date()
// Getting the components once makes this faster when we need them repeatedly
property int currentDay: currentDate ? currentDate.getDate() : null
property int currentMonth: currentDate ? currentDate.getMonth() : null
property int currentYear: currentDate ? currentDate.getFullYear() : null
property date startDate
readonly property int currentDay: currentDate.getDate()
readonly property int currentMonth: currentDate.getMonth()
readonly property int currentYear:currentDate.getFullYear()
property date firstDayOfMonth: DateUtils.getFirstDayOfMonth(currentDate)
property date startDate: DateUtils.getFirstDayOfWeek(firstDayOfMonth)
readonly property int month: firstDayOfMonth.getMonth()
property bool paintGrid: true
property bool showDayIndicator: true
property Component dayHeaderDelegate
property Component weekHeaderDelegate
property int month
property alias bgLoader: backgroundLoader.item
property bool isCurrentView: true
property bool dragDropEnabled: true
......
......@@ -19,10 +19,10 @@ Kirigami.Page {
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 month: firstDayOfMonth.getMonth()
readonly property int year: firstDayOfMonth.getFullYear()
readonly property int mode: Kalendar.KalendarApplication.Month
property bool dragDropEnabled: true
......@@ -37,18 +37,6 @@ Kirigami.Page {
}
}
function setToDate(date, isInitialMonth = false) {
dayGrid.setToDate(date, isInitialMonth);
}
padding: 0
background: Rectangle {
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
}
readonly property Kirigami.Action previousAction: Kirigami.Action {
icon.name: "go-previous"
text: i18n("Previous Month")
......@@ -69,12 +57,26 @@ Kirigami.Page {
shortcut: StandardKey.MoveToStartOfLine
onTriggered: setToDate(new Date())
}
function setToDate(date, isInitialMonth = false) {
initialMonth = isInitialMonth;
dayGrid.setToDate(date);
}
actions {
left: Qt.application.layoutDirection === Qt.RightToLeft ? nextAction : previousAction
right: Qt.application.layoutDirection === Qt.RightToLeft ? previousAction : nextAction
main: todayAction
}
padding: 0
background: Rectangle {
Kirigami.Theme.inherit: false
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.backgroundColor
}
Loader {
id: swipeableViewLoader
anchors.fill: parent
......@@ -82,9 +84,6 @@ Kirigami.Page {
sourceComponent: SwipeableMonthGridView {
anchors.fill: parent
initialMonth: monthPage.initialMonth
isLarge: monthPage.isLarge
isTiny: monthPage.isTiny
dragDropEnabled: monthPage.dragDropEnabled
currentDate: monthPage.currentDate
openOccurrence: monthPage.openOccurrence
......@@ -92,8 +91,6 @@ Kirigami.Page {
onViewDatesChanged: {
monthPage.startDate = startDate;
monthPage.firstDayOfMonth = firstDayOfMonth;
monthPage.month = month;
monthPage.year = year;
}
}
}
......@@ -105,8 +102,6 @@ Kirigami.Page {
sourceComponent: BasicMonthGridView {
anchors.fill: parent
isLarge: monthPage.isLarge
isTiny: monthPage.isTiny
dragDropEnabled: monthPage.dragDropEnabled
startDate: monthPage.startDate
currentDate: monthPage.currentDate
......@@ -115,8 +110,6 @@ Kirigami.Page {
onViewDatesChanged: {
monthPage.startDate = startDate;
monthPage.firstDayOfMonth = firstDayOfMonth;
monthPage.month = month;
monthPage.year = year;
}
}
}
......
......@@ -12,26 +12,23 @@ import "dateutils.js" as DateUtils
PathView {
id: pathView
signal viewDatesChanged(date startDate, date firstDayOfMonth, int month, int year)
signal viewDatesChanged(date startDate, date firstDayOfMonth)
property bool initialMonth: true
property bool isLarge: true
property bool isTiny: false
property bool dragDropEnabled: true
property date currentDate: new Date()
property date startDate: DateUtils.getFirstDayOfWeek(DateUtils.getFirstDayOfMonth(currentDate))
property var openOccurrence: null
function setToDate(date, isInitialMonth = false) {
initialMonth = isInitialMonth;
let monthDiff = date.getMonth() - pathView.currentItem.firstDayOfMonth.getMonth() + (12 * (date.getFullYear() - pathView.currentItem.firstDayOfMonth.getFullYear()))
let newIndex = pathView.currentIndex + monthDiff;
function setToDate(date) {
let monthDiff = date.getMonth() - currentItem.firstDayOfMonth.getMonth() + (12 * (date.getFullYear() - currentItem.firstDayOfMonth.getFullYear()))
let newIndex = currentIndex + monthDiff;
let firstItemDate = pathView.model.data(pathView.model.index(1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
let lastItemDate = pathView.model.data(pathView.model.index(pathView.model.rowCount() - 1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
let firstItemDate = model.data(model.index(1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
let lastItemDate = model.data(model.index(model.rowCount() - 1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
while(firstItemDate >= date) {
pathView.model.addDates(false)
firstItemDate = pathView.model.data(pathView.model.index(1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
model.addDates(false)
firstItemDate = model.data(model.index(1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
newIndex = 0;
}
if(firstItemDate < date && newIndex === 0) {
......@@ -39,10 +36,12 @@ PathView {
}
while(lastItemDate <= date) {
pathView.model.addDates(true)
lastItemDate = pathView.model.data(pathView.model.index(pathView.model.rowCount() - 1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
model.addDates(true)
lastItemDate = model.data(model.index(model.rowCount() - 1,0), Kalendar.InfiniteCalendarViewModel.FirstDayOfMonthRole);
}
pathView.currentIndex = newIndex;
currentIndex = newIndex;
viewDatesChanged(currentItem.startDate, currentItem.firstDayOfMonth);
}
flickDeceleration: Kirigami.Units.longDuration
......@@ -72,8 +71,6 @@ PathView {
currentIndex = startIndex;
}
onCurrentIndexChanged: {
pathView.viewDatesChanged(currentItem.startDate, currentItem.firstDayOfMonth, currentItem.month, currentItem.year);
if(currentIndex >= count - 2) {
model.addDates(true);
} else if (currentIndex <= 1) {
......@@ -85,13 +82,13 @@ PathView {
delegate: Loader {
id: viewLoader
property date startDate: model.startDate
property date firstDayOfMonth: model.firstDay
property int month: model.selectedMonth - 1 // Convert QDateTime month to JS month
property int year: model.selectedYear
readonly property date startDate: model.startDate
readonly property date firstDayOfMonth: model.firstDay
readonly property int month: model.selectedMonth - 1 // Convert QDateTime month to JS month
readonly property int year: model.selectedYear
property bool isNextOrCurrentItem: index >= pathView.currentIndex -1 && index <= pathView.currentIndex + 1
property bool isCurrentItem: PathView.isCurrentItem
readonly property bool isNextOrCurrentItem: index >= pathView.currentIndex -1 && index <= pathView.currentIndex + 1
readonly property bool isCurrentItem: PathView.isCurrentItem
active: isNextOrCurrentItem
asynchronous: !isCurrentItem
......@@ -100,15 +97,12 @@ PathView {
width: pathView.width
height: pathView.height
isLarge: pathView.isLarge
isTiny: pathView.isTiny
isCurrentView: viewLoader.isCurrentItem
dragDropEnabled: pathView.dragDropEnabled
startDate: viewLoader.startDate
firstDayOfMonth: viewLoader.firstDayOfMonth
currentDate: pathView.currentDate
month: viewLoader.month
openOccurrence: pathView.openOccurrence
}
......
......@@ -1094,7 +1094,6 @@ Kirigami.ApplicationWindow {
]
}
}
selectedDate: root.selectedDate
currentDate: root.currentDate
openOccurrence: root.openOccurrence
......
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