incidencedatetime.h 5.27 KB
Newer Older
Sergio Luis Martins's avatar
Sergio Luis Martins committed
1
/*
Allen Winter's avatar
Allen Winter committed
2
  Copyright (c) 2010 Bertjan Broeksema <broeksema@kde.org>
Allen Winter's avatar
Allen Winter committed
3
  Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
Allen Winter's avatar
Allen Winter committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18

  This library is free software; you can redistribute it and/or modify it
  under the terms of the GNU Library General Public License as published by
  the Free Software Foundation; either version 2 of the License, or (at your
  option) any later version.

  This library is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
  License for more details.

  You should have received a copy of the GNU Library General Public License
  along with this library; see the file COPYING.LIB.  If not, write to the
  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  02110-1301, USA.
Sergio Luis Martins's avatar
Sergio Luis Martins committed
19 20
*/

Allen Winter's avatar
Allen Winter committed
21 22
#ifndef INCIDENCEEDITOR_INCIDENCEDATETIME_H
#define INCIDENCEEDITOR_INCIDENCEDATETIME_H
Sergio Luis Martins's avatar
Sergio Luis Martins committed
23

24
#include "incidenceeditor-ng.h"
Sergio Luis Martins's avatar
Sergio Luis Martins committed
25

Sergio Luis Martins's avatar
Sergio Luis Martins committed
26
#include <KCalCore/Event>
27
#include <KCalCore/Journal>
28
#include <KCalCore/Todo>
Sergio Luis Martins's avatar
Sergio Luis Martins committed
29

Laurent Montel's avatar
Laurent Montel committed
30 31
#include <QDate>

Laurent Montel's avatar
Laurent Montel committed
32 33 34
namespace Ui
{
class EventOrTodoDesktop;
Sergio Luis Martins's avatar
Sergio Luis Martins committed
35 36
}

Laurent Montel's avatar
Laurent Montel committed
37 38 39
namespace KCalCore
{
class ICalTimeZones;
40 41
}

Laurent Montel's avatar
Laurent Montel committed
42 43
namespace IncidenceEditorNG
{
Sergio Luis Martins's avatar
Sergio Luis Martins committed
44

45
class IncidenceDateTime : public IncidenceEditor
Sergio Luis Martins's avatar
Sergio Luis Martins committed
46
{
Laurent Montel's avatar
Laurent Montel committed
47 48
    Q_OBJECT
public:
49 50
    using IncidenceEditorNG::IncidenceEditor::save; // So we don't trigger -Woverloaded-virtual
    using IncidenceEditorNG::IncidenceEditor::load; // So we don't trigger -Woverloaded-virtual
Laurent Montel's avatar
Laurent Montel committed
51
    explicit IncidenceDateTime(Ui::EventOrTodoDesktop *ui);
Sergio Luis Martins's avatar
Sergio Luis Martins committed
52 53
    ~IncidenceDateTime();

Laurent Montel's avatar
Laurent Montel committed
54 55 56
    void load(const KCalCore::Incidence::Ptr &incidence) Q_DECL_OVERRIDE;
    void save(const KCalCore::Incidence::Ptr &incidence) Q_DECL_OVERRIDE;
    bool isDirty() const Q_DECL_OVERRIDE;
Sergio Luis Martins's avatar
Sergio Luis Martins committed
57 58 59 60 61 62

    /**
     * Sets the active date for the editing session. This defaults to the current
     * date. It should be set <em>before</em> loading a non-empty (i.e. existing
     * incidence).
     */
Laurent Montel's avatar
Laurent Montel committed
63
    void setActiveDate(const QDate &activeDate);
Sergio Luis Martins's avatar
Sergio Luis Martins committed
64 65

    QDate startDate() const; /// Returns the current start date.
Sergio Luis Martins's avatar
Sergio Luis Martins committed
66 67 68 69 70 71 72
    QTime startTime() const; /// Returns the current start time.
    QDate endDate() const; /// Returns the current end date.
    QTime endTime() const; /// Returns the current endtime.

    /// Created from the values in the widgets
    KDateTime currentStartDateTime() const;
    KDateTime currentEndDateTime() const;
Sergio Luis Martins's avatar
Sergio Luis Martins committed
73

Laurent Montel's avatar
Laurent Montel committed
74 75
    void setStartTime(const QTime &newTime);
    void setStartDate(const QDate &newDate);
76

77 78 79
    bool startDateTimeEnabled() const;
    bool endDateTimeEnabled() const;

80 81
    bool isValid() const Q_DECL_OVERRIDE;
    void printDebugInfo() const Q_DECL_OVERRIDE;
82

Laurent Montel's avatar
Laurent Montel committed
83
Q_SIGNALS:
84
    // used to indicate that the widgets were activated
Laurent Montel's avatar
Laurent Montel committed
85 86 87 88
    void startDateFocus(QObject *obj);
    void endDateFocus(QObject *obj);
    void startTimeFocus(QObject *obj);
    void endTimeFocus(QObject *obj);
89 90

    // general
Laurent Montel's avatar
Laurent Montel committed
91 92 93 94 95 96 97
    void startDateTimeToggled(bool enabled);
    void startDateChanged(const QDate &newDate);
    void startTimeChanged(const QTime &newTime);
    void endDateTimeToggled(bool enabled);
    void endDateChanged(const QDate &newDate);
    void endTimeChanged(const QTime &newTime);

Laurent Montel's avatar
Laurent Montel committed
98
private Q_SLOTS: /// General
Laurent Montel's avatar
Laurent Montel committed
99
    void setTimeZonesVisibility(bool visible);
Sergio Luis Martins's avatar
Sergio Luis Martins committed
100
    void toggleTimeZoneVisibility();
Laurent Montel's avatar
Laurent Montel committed
101 102
    void updateStartTime(const QTime &newTime);
    void updateStartDate(const QDate &newDate);
Sergio Luis Martins's avatar
Sergio Luis Martins committed
103
    void updateStartSpec();
104 105
    void updateStartToolTips();
    void updateEndToolTips();
Sergio Luis Martins's avatar
Sergio Luis Martins committed
106

Laurent Montel's avatar
Laurent Montel committed
107
private Q_SLOTS: /// Todo specific
Laurent Montel's avatar
Laurent Montel committed
108 109
    void enableStartEdit(bool enable);
    void enableEndEdit(bool enable);
Sergio Luis Martins's avatar
Sergio Luis Martins committed
110
    void enableTimeEdits();
Laurent Montel's avatar
Laurent Montel committed
111 112
    bool isDirty(const KCalCore::Todo::Ptr &todo) const;

Laurent Montel's avatar
Laurent Montel committed
113
private Q_SLOTS: /// Event specific
Laurent Montel's avatar
Laurent Montel committed
114 115 116 117
    bool isDirty(const KCalCore::Event::Ptr &event) const;
    bool isDirty(const KCalCore::Journal::Ptr &journal) const;

protected:
Laurent Montel's avatar
Laurent Montel committed
118
    bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
Laurent Montel's avatar
Laurent Montel committed
119 120 121 122 123 124 125 126 127 128 129 130 131 132

private:
    void load(const KCalCore::Event::Ptr &event, bool isTemplate = false, bool templateOverridesTimes = false);
    void load(const KCalCore::Todo::Ptr &todo, bool isTemplate = false, bool templateOverridesTimes = false);
    void load(const KCalCore::Journal::Ptr &journal, bool isTemplate = false, bool templateOverridesTimes = false);
    void save(const KCalCore::Event::Ptr &event);
    void save(const KCalCore::Todo::Ptr &todo);
    void save(const KCalCore::Journal::Ptr &journal);
    void setDateTimes(const KDateTime &start, const KDateTime &end);
    void setTimes(const KDateTime &start, const KDateTime &end);
    void setTimeZoneLabelEnabled(bool enable);
    bool timeZonesAreLocal(const KDateTime &start, const KDateTime &end);

private:
Sergio Luis Martins's avatar
Sergio Luis Martins committed
133
    KCalCore::ICalTimeZones *mTimeZones;
Sergio Luis Martins's avatar
Sergio Luis Martins committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    Ui::EventOrTodoDesktop *mUi;

    QDate mActiveDate;
    /**
     * These might differ from mLoadedIncidence->(dtStart|dtDue) as these take
     * in account recurrence if needed. The values are calculated once on load().
     * and don't change afterwards.
     */
    KDateTime mInitialStartDT;
    KDateTime mInitialEndDT;

    /**
     * We need to store the current start date/time to be able to update the end
     * time appropriate when the start time changes.
     */
    KDateTime mCurrentStartDateTime;
150

151
    /// Remembers state when switching between takes whole day and timed event/to-do.
152
    bool mTimezoneCombosWereVisibile;
Sergio Luis Martins's avatar
Sergio Luis Martins committed
153 154
};

Allen Winter's avatar
Allen Winter committed
155
}
Sergio Luis Martins's avatar
Sergio Luis Martins committed
156

Allen Winter's avatar
Allen Winter committed
157
#endif