Incidenceeditor

incidencerecurrence.h
1/*
2 SPDX-FileCopyrightText: 2010 Bertjan Broeksema <broeksema@kde.org>
3 SPDX-FileCopyrightText: 2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "incidenceeditor-ng.h"
11
12#include <KLocalizedString>
13#include <QDate>
14namespace Ui
15{
16class EventOrTodoDesktop;
17}
18
19namespace IncidenceEditorNG
20{
21class IncidenceDateTime;
22
23/// Keep this in sync with the values in mUi->mRecurrenceTypeCombo
24enum RecurrenceType {
25 RecurrenceTypeNone = 0,
26 RecurrenceTypeDaily,
27 RecurrenceTypeWeekly,
28 RecurrenceTypeMonthly,
29 RecurrenceTypeYearly,
30 RecurrenceTypeUnknown, // keep this one at the end of the ones which are also in the combobox
31 RecurrenceTypeException
32};
33
34class IncidenceRecurrence : public IncidenceEditor
35{
37public:
38 using IncidenceEditorNG::IncidenceEditor::load; // So we don't trigger -Woverloaded-virtual
39 using IncidenceEditorNG::IncidenceEditor::save; // So we don't trigger -Woverloaded-virtual
40
41 IncidenceRecurrence(IncidenceDateTime *dateTime, Ui::EventOrTodoDesktop *ui);
42
43 void load(const KCalendarCore::Incidence::Ptr &incidence) override;
44 void save(const KCalendarCore::Incidence::Ptr &incidence) override;
45 [[nodiscard]] bool isDirty() const override;
46 [[nodiscard]] bool isValid() const override;
47
48 void focusInvalidField() override;
49
50 [[nodiscard]] RecurrenceType currentRecurrenceType() const;
51
53 void recurrenceChanged(IncidenceEditorNG::RecurrenceType type);
54
55private:
56 void addException();
57 void fillCombos();
58 void handleDateTimeToggle();
59 void handleEndAfterOccurrencesChange(int currentValue);
60 void handleExceptionDateChange(const QDate &currentDate);
61 void handleFrequencyChange();
62 void handleRecurrenceTypeChange(int currentIndex);
63 void removeExceptions();
64 void updateRemoveExceptionButton();
65 void updateWeekDays(const QDate &newStartDate);
66 void handleStartDateChange(const QDate &);
67
68 /**
69 I needed save() to be const, so created this func.
70 save() calls this now, and changes members outside.
71 */
72 void writeToIncidence(const KCalendarCore::Incidence::Ptr &incidence) const;
73
74 [[nodiscard]] KLocalizedString subsOrdinal(const KLocalizedString &text, int number) const;
75 /**
76 * Return the day in the month/year on which the event recurs, starting at the
77 * beginning/end. Both return a positive number.
78 */
79 [[nodiscard]] short dayOfMonthFromStart() const;
80 [[nodiscard]] short dayOfMonthFromEnd() const;
81 [[nodiscard]] short dayOfYearFromStart() const; // We don't need from end for year
82 [[nodiscard]] int duration() const;
83
84 /** Returns the week number (1-5) of the month in which the start date occurs. */
85 [[nodiscard]] short monthWeekFromStart() const;
86 [[nodiscard]] short monthWeekFromEnd() const;
87
88 /** DO NOT USE THIS METHOD DIRECTLY
89 use subsOrdinal() instead for i18n * */
90 [[nodiscard]] QString numberToString(int number) const;
91 void selectMonthlyItem(KCalendarCore::Recurrence *recurrence, ushort recurenceType);
92 void selectYearlyItem(KCalendarCore::Recurrence *recurrence, ushort recurenceType);
93 void setDefaults();
94 void setDuration(int duration);
95 void setExceptionDates(const KCalendarCore::DateList &dates);
96 void setExceptionDateTimes(const KCalendarCore::DateTimeList &dateTimes);
97 void setFrequency(int freq);
98 void toggleRecurrenceWidgets(int enable);
99 /** Returns an array with the weekday on which the event occurs set to 1 */
100 [[nodiscard]] QBitArray weekday() const;
101
102 /**
103 * Return how many times the weekday represented by @param date occurs in
104 * the month of @param date.
105 */
106 [[nodiscard]] int weekdayCountForMonth(const QDate &date) const;
107
108 [[nodiscard]] QDate currentDate() const;
109
110private:
111 Ui::EventOrTodoDesktop *const mUi;
112 QDate mCurrentDate;
113 IncidenceDateTime *const mDateTime;
114 KCalendarCore::DateList mExceptionDates;
115
116 // So we can easily detect if the user changed the type,
117 // without going through complicated recurrence logic:
118 int mMonthlyInitialType = -1;
119 int mYearlyInitialType = -1;
120};
121}
KCalendarCore::IncidenceBase::IncidenceType type() const
Returns the type of the Incidence that is currently loaded.
virtual void load(const KCalendarCore::Incidence::Ptr &incidence)=0
Load the values of.
QSharedPointer< IncidenceT > incidence() const
Convenience method to get a pointer for a specific const Incidence Type.
virtual void save(const KCalendarCore::Incidence::Ptr &incidence)=0
Store the current values of the editor into.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.