File indexing completed on 2024-04-28 05:11:34

0001 /*
0002   SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
0003   SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
0004 
0005   SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "incidenceeditor-ng.h"
0011 
0012 #include <KCalendarCore/Event>
0013 #include <KCalendarCore/Journal>
0014 #include <KCalendarCore/Todo>
0015 
0016 #include <QDate>
0017 
0018 namespace Ui
0019 {
0020 class EventOrTodoDesktop;
0021 }
0022 
0023 namespace IncidenceEditorNG
0024 {
0025 class IncidenceDateTime : public IncidenceEditor
0026 {
0027     Q_OBJECT
0028 public:
0029     using IncidenceEditorNG::IncidenceEditor::load; // So we don't trigger -Woverloaded-virtual
0030     using IncidenceEditorNG::IncidenceEditor::save; // So we don't trigger -Woverloaded-virtual
0031     explicit IncidenceDateTime(Ui::EventOrTodoDesktop *ui);
0032     ~IncidenceDateTime() override;
0033 
0034     void load(const KCalendarCore::Incidence::Ptr &incidence) override;
0035     void save(const KCalendarCore::Incidence::Ptr &incidence) override;
0036     [[nodiscard]] bool isDirty() const override;
0037 
0038     /**
0039      * Sets the active date for the editing session. This defaults to the current
0040      * date. It should be set <em>before</em> loading a non-empty (i.e. existing
0041      * incidence).
0042      */
0043     void setActiveDate(const QDate &activeDate);
0044 
0045     [[nodiscard]] QDate startDate() const; /// Returns the current start date.
0046     [[nodiscard]] QTime startTime() const; /// Returns the current start time.
0047     [[nodiscard]] QDate endDate() const; /// Returns the current end date.
0048     [[nodiscard]] QTime endTime() const; /// Returns the current endtime.
0049 
0050     /// Created from the values in the widgets
0051     [[nodiscard]] QDateTime currentStartDateTime() const;
0052     [[nodiscard]] QDateTime currentEndDateTime() const;
0053 
0054     void setStartTime(const QTime &newTime);
0055     void setStartDate(const QDate &newDate);
0056 
0057     [[nodiscard]] bool startDateTimeEnabled() const;
0058     [[nodiscard]] bool endDateTimeEnabled() const;
0059 
0060     void focusInvalidField() override;
0061 
0062     [[nodiscard]] bool isValid() const override;
0063     void printDebugInfo() const override;
0064 
0065 Q_SIGNALS:
0066     // used to indicate that the widgets were activated
0067     void startDateFocus(QObject *obj);
0068     void endDateFocus(QObject *obj);
0069     void startTimeFocus(QObject *obj);
0070     void endTimeFocus(QObject *obj);
0071 
0072     // general
0073     void startDateTimeToggled(bool enabled);
0074     void startDateChanged(const QDate &newDate);
0075     void startTimeChanged(const QTime &newTime);
0076     void endDateTimeToggled(bool enabled);
0077     void endDateChanged(const QDate &newDate);
0078     void endTimeChanged(const QTime &newTime);
0079 
0080 private Q_SLOTS: /// General
0081     void setTimeZonesVisibility(bool visible);
0082     void toggleTimeZoneVisibility();
0083     void updateStartTime(const QTime &newTime);
0084     void updateStartDate(const QDate &newDate);
0085     void updateStartSpec();
0086     void updateEndSpec();
0087     void updateStartToolTips();
0088     void updateEndToolTips();
0089 
0090 private Q_SLOTS: /// Todo specific
0091     void enableStartEdit(bool enable);
0092     void enableEndEdit(bool enable);
0093     void enableTimeEdits();
0094 
0095 private:
0096     bool isDirty(const KCalendarCore::Todo::Ptr &todo) const;
0097     bool isDirty(const KCalendarCore::Event::Ptr &event) const;
0098     bool isDirty(const KCalendarCore::Journal::Ptr &journal) const;
0099 
0100 protected:
0101     bool eventFilter(QObject *obj, QEvent *event) override;
0102 
0103 private:
0104     void load(const KCalendarCore::Event::Ptr &event, bool isTemplate = false, bool templateOverridesTimes = false);
0105     void load(const KCalendarCore::Todo::Ptr &todo, bool isTemplate = false, bool templateOverridesTimes = false);
0106     void load(const KCalendarCore::Journal::Ptr &journal, bool isTemplate = false, bool templateOverridesTimes = false);
0107     void save(const KCalendarCore::Event::Ptr &event);
0108     void save(const KCalendarCore::Todo::Ptr &todo);
0109     void save(const KCalendarCore::Journal::Ptr &journal);
0110     void setDateTimes(const QDateTime &start, const QDateTime &end);
0111     void setTimes(const QDateTime &start, const QDateTime &end);
0112     void setTimeZoneLabelEnabled(bool enable);
0113     bool timeZonesAreLocal(const QDateTime &start, const QDateTime &end);
0114 
0115 private:
0116     Ui::EventOrTodoDesktop *mUi = nullptr;
0117 
0118     QDate mActiveDate;
0119     /**
0120      * These might differ from mLoadedIncidence->(dtStart|dtDue) as these take
0121      * in account recurrence if needed. The values are calculated once on load().
0122      * and don't change afterwards.
0123      */
0124     QDateTime mInitialStartDT;
0125     QDateTime mInitialEndDT;
0126 
0127     /**
0128      * We need to store the current start date/time to be able to update the end
0129      * time appropriate when the start time changes.
0130      */
0131     QDateTime mCurrentStartDateTime;
0132 
0133     /// Remembers state when switching between takes whole day and timed event/to-do.
0134     bool mTimezoneCombosWereVisibile;
0135 };
0136 }