Commit e0bf0a25 authored by Slawek Kaplonski's avatar Slawek Kaplonski Committed by Claudio Cambra
Browse files

Drag and drop convert to and from all day events

In the week view it is now possible to drag and drop allday/multiday
event to the "main area" to convert it to be 1h long event.
Drag and drop in the opposite way also works now. So it is possible
to drag and drop hourly event to the allday/multiday events area to
convert it to be all day task.

Closes-issue: #120
parent df40a670
Pipeline #116396 passed with stage
in 5 minutes and 47 seconds
......@@ -22,6 +22,7 @@ Kirigami.Page {
signal addSubTodo(var parentWrapper)
signal deselect()
signal moveIncidence(int startOffset, date occurrenceDate, var incidenceWrapper, Item caughtDelegate)
signal convertIncidence(bool allDay, int startOffset, int endOffset, date occurrenceDate, var incidenceWrapper, Item caughtDelegate)
signal resizeIncidence(int endOffset, date occurrenceDate, var incidenceWrapper, Item caughtDelegate)
signal openDayView(date selectedDate)
......@@ -508,7 +509,15 @@ Kirigami.Page {
let sameTimeOnDate = new Date(listViewMenu.addDate);
sameTimeOnDate = new Date(sameTimeOnDate.setHours(drop.source.occurrenceDate.getHours(), drop.source.occurrenceDate.getMinutes()));
const offset = sameTimeOnDate.getTime() - drop.source.occurrenceDate.getTime();
root.moveIncidence(offset, drop.source.occurrenceDate, incidenceWrapper, drop.source);
/* There are 2 possibilities here: we move multiday incidence between days or we move hourly incidence
* to convert it into multiday incidence
*/
if (drop.source.objectName === 'incidenceDelegate') {
// This is conversion from non-multiday to multiday
root.convertIncidence(true, offset, offset, drop.source.occurrenceDate, incidenceWrapper, drop.source);
} else {
root.moveIncidence(offset, drop.source.occurrenceDate, incidenceWrapper, drop.source);
}
}
}
}
......@@ -530,6 +539,7 @@ Kirigami.Page {
model: modelData
MultiDayViewIncidenceDelegate {
id: incidenceDelegate
objectName: "multiDayIncidenceDelegate"
dayWidth: root.dayWidth
height: Kirigami.Units.gridUnit + Kirigami.Units.smallSpacing
parentViewSpacing: root.gridLineWidth
......@@ -826,8 +836,7 @@ Kirigami.Page {
z: 9999
onDropped: if(viewLoader.isCurrentItem) {
let incidenceWrapper = Qt.createQmlObject('import org.kde.kalendar 1.0; IncidenceWrapper {id: incidence}', incidenceDropArea, "incidence");
/* So when we drop the entire incidence card somewhere, we are dropping the delegate with object name "incidenceDelegate".
/* So when we drop the entire incidence card somewhere, we are dropping the delegate with object name "incidenceDelegate" or "multiDayIncidenceDelegate" in case when all day event is converted to the hour incidence.
* However, when we are simply resizing, we are actually dropping the specific mouseArea within the delegate that handles
* the dragging for the incidence's bottom edge which has name "endDtResizeMouseArea". Hence why we check the object names
*/
......@@ -845,6 +854,24 @@ Kirigami.Page {
const startOffset = posDate.getTime() - drop.source.occurrenceDate.getTime();
root.moveIncidence(startOffset, drop.source.occurrenceDate, incidenceWrapper, drop.source);
} else if(drop.source.objectName === "multiDayIncidenceDelegate") {
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.incidencePtr);
const pos = mapToItem(root, dropAreaHighlightRectangle.x, dropAreaHighlightRectangle.y);
drop.source.caughtX = pos.x + incidenceSpacing;
drop.source.caughtY = pos.y + incidenceSpacing;
drop.source.caught = true;
// We want the date as if it were "from the top" of the droparea
const startPosDate = new Date(backgroundDayMouseArea.addDate.getFullYear(), backgroundDayMouseArea.addDate.getMonth(), backgroundDayMouseArea.addDate.getDate(), backgroundRectangle.index, dropAreaRepeater.minutes * index);
// In case when incidence is converted to not be all day anymore, lets set it as 1h long
const endPosDate = new Date(backgroundDayMouseArea.addDate.getFullYear(), backgroundDayMouseArea.addDate.getMonth(), backgroundDayMouseArea.addDate.getDate(), backgroundRectangle.index + 1, dropAreaRepeater.minutes * index);
const startOffset = startPosDate.getTime() - drop.source.occurrenceDate.getTime();
const endOffset = endPosDate.getTime() - drop.source.occurrenceEndDate.getTime();
root.convertIncidence(false, startOffset, endOffset, drop.source.occurrenceDate, incidenceWrapper, drop.source);
} else { // The resize affects the end time
incidenceWrapper.incidenceItem = Kalendar.CalendarManager.incidenceItem(drop.source.parent.incidencePtr);
......
......@@ -980,6 +980,12 @@ Kirigami.ApplicationWindow {
}
}
function convertIncidence(incidenceWrapper, allDay, startOffset, endOffset, occurrenceDate, caughtDelegate) {
incidenceWrapper.allDay = allDay;
setUpIncidenceDateChange(incidenceWrapper, startOffset, endOffset, occurrenceDate, caughtDelegate);
}
function reenableDragOnCurrentView() {
pageStack.currentItem.dragDropEnabled = true;
......@@ -1263,6 +1269,7 @@ Kirigami.ApplicationWindow {
onAddSubTodo: root.setUpAddSubTodo(parentWrapper)
onDeselect: incidenceInfo.close()
onMoveIncidence: root.setUpIncidenceDateChange(incidenceWrapper, startOffset, startOffset, occurrenceDate, caughtDelegate) // We move the entire incidence
onConvertIncidence: root.convertIncidence(incidenceWrapper, allDay, startOffset, endOffset, caughtDelegate) // We convert incidence from or to all day event
onResizeIncidence: root.setUpIncidenceDateChange(incidenceWrapper, 0, endOffset, occurrenceDate, caughtDelegate)
onOpenDayView: root.openDayLayer(selectedDate)
......
Markdown is supported
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