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

Set better default time when converting event from allDay

Previously when event was converted from allDay to the "normal" one,
time set by default in the incidence editor was always set to 00:00.
Now it is set to the nearest quarter of the current time.
End time is set to start + 1h to be consistent with the convertion by
drag and drop.

Closes-issue: #119
parent b194e57b
Pipeline #129664 passed with stage
in 1 minute and 14 seconds
......@@ -258,7 +258,12 @@ Kirigami.ScrollablePage {
enabled: !incidenceForm.isTodo || !isNaN(root.incidenceWrapper.incidenceStart.getTime()) || !isNaN(root.incidenceWrapper.incidenceEnd.getTime())
onEnabledChanged: if (!enabled) root.incidenceWrapper.allDay = false
checked: root.incidenceWrapper.allDay
onClicked: root.incidenceWrapper.allDay = checked
onClicked: {
if (!checked) {
root.incidenceWrapper.setIncidenceTimeToNearestQuarterHour();
}
root.incidenceWrapper.allDay = checked;
}
}
Connections {
......@@ -345,11 +350,7 @@ Kirigami.ScrollablePage {
} else if(incidenceForm.isTodo && oldDate) {
root.incidenceWrapper.incidenceEnd = oldDate
} else if(incidenceForm.isTodo) {
let start = new Date();
let startInMsecsSinceEpoch = start.getTime();
const quarterHourInMsecs = 15 * 60 * 1000;
const nearestQuarterHourStart = startInMsecsSinceEpoch + (quarterHourInMsecs - startInMsecsSinceEpoch % quarterHourInMsecs);
root.incidenceWrapper.incidenceEnd = new Date(nearestQuarterHourStart);
root.incidenceWrapper.incidenceEnd = root.incidenceWrapper.setIncidenceTimeToNearestQuarterHour(false, true);
}
}
visible: incidenceForm.isTodo
......
......@@ -354,6 +354,21 @@ QString IncidenceWrapper::incidenceEndTimeDisplay() const
return QLocale::system().toString(incidenceEnd().time(), QLocale::NarrowFormat);
}
void IncidenceWrapper::setIncidenceTimeToNearestQuarterHour(bool setStartTime, bool setEndTime)
{
const int now = QDateTime::currentSecsSinceEpoch();
const int quarterHourInSecs = 15 * 60;
const int secsToSet = now + (quarterHourInSecs - now % quarterHourInSecs);
QDateTime startTime = QDateTime::currentDateTime();
startTime.setSecsSinceEpoch(secsToSet);
if (setStartTime) {
setIncidenceStart(startTime, true);
}
if (setEndTime) {
setIncidenceEnd(startTime.addSecs(3600), true);
}
}
QByteArray IncidenceWrapper::timeZone() const
{
return incidenceEnd().timeZone().id();
......
......@@ -140,6 +140,7 @@ public:
Q_INVOKABLE void setIncidenceEndTime(int hours, int minutes);
QString incidenceEndDateDisplay() const;
QString incidenceEndTimeDisplay() const;
Q_INVOKABLE void setIncidenceTimeToNearestQuarterHour(bool setStartTime = true, bool setEndTime = true);
QByteArray timeZone() const;
void setTimeZone(const QByteArray &timeZone);
int startTimeZoneUTCOffsetMins();
......
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