CalendarSupport

incidenceviewer.h
1/*
2 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company
3 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#pragma once
9
10#include "calendarsupport_export.h"
11
12#include <Akonadi/ItemMonitor>
13
14#include <QDate>
15#include <QWidget>
16
17#include <memory>
18
20
21namespace Akonadi
22{
23class EntityTreeModel;
24class ETMCalendar;
25}
26
27namespace CalendarSupport
28{
29class IncidenceViewerPrivate;
30
31/**
32 * @short A viewer component for incidences in Akonadi.
33 *
34 * This widgets provides a way to show an incidence from the
35 * Akonadi storage.
36 *
37 * Example:
38 *
39 * @code
40 *
41 * using namespace CalendarSupport;
42 *
43 * const Item item = ...
44 *
45 * IncidenceViewer *viewer = new IncidenceViewer( this );
46 * viewer->setIncidence( item );
47 *
48 * @endcode
49 *
50 * @author Tobias Koenig <tokoe@kde.org>
51 * @since 4.5
52 */
53class CALENDARSUPPORT_EXPORT IncidenceViewer : public QWidget, public Akonadi::ItemMonitor
54{
56
57public:
58 /**
59 * Creates a new incidence viewer.
60 *
61 * *param
62 * @param calendar is a pointer to a Calendar instance.
63 * @param parent it the parent widget.
64 */
65 CALENDARSUPPORT_DEPRECATED_VERSION(5, 24, "Use constructor with ETM")
66 explicit IncidenceViewer(Akonadi::ETMCalendar *calendar, QWidget *parent = nullptr);
67 explicit IncidenceViewer(Akonadi::EntityTreeModel *etm, QWidget *parent = nullptr);
68
69 /**
70 * Creates a new incidence viewer.
71 *
72 * *param
73 * @param parent it the parent widget.
74 */
75 explicit IncidenceViewer(QWidget *parent = nullptr);
76
77 /**
78 * Destroys the incidence viewer.
79 */
80 ~IncidenceViewer() override;
81
82 /**
83 * Sets the Calendar for this viewer.
84 * @param calendar is a pointer to a Calendar instance.
85 */
86 CALENDARSUPPORT_DEPRECATED_VERSION(5, 24, "Prefer passing an ETM via setModel()")
87 void setCalendar(Akonadi::ETMCalendar *calendar);
88
89 /**
90 * Sets the model for this viewer.
91 * @param etm is a pointer to an ETM instance.
92 */
93 void setModel(Akonadi::EntityTreeModel *etm);
94
95 /**
96 * Returns the incidence that is currently displayed.
97 */
98 [[nodiscard]] Akonadi::Item incidence() const;
99
100 /**
101 * Returns the active date used for the currently displayed incidence
102 */
103 [[nodiscard]] QDate activeDate() const;
104
105 /**
106 * Returns the attachment model for the currently displayed incidence.
107 */
108 [[nodiscard]] QAbstractItemModel *attachmentModel() const;
109
110 /**
111 * Sets whether the view shall be cleared as soon as an empty incidence is
112 * set (default) or @p delayed when the next valid incidence is set.
113 */
114 void setDelayedClear(bool delayed);
115
116 /**
117 * Sets the default @p message that shall be shown if no incidence is set.
118 */
119 void setDefaultMessage(const QString &message);
120
121 /**
122 * Sets an additional @p text that is shown above the incidence.
123 */
124 void setHeaderText(const QString &text);
125
126public Q_SLOTS:
127 /**
128 * Sets the @p incidence that shall be displayed in the viewer.
129 *
130 * @param activeDate The active date is used to calculate the actual date of
131 * the selected incidence in case of recurring incidences.
132 */
134
135protected:
136 /**
137 * Initialize the widget settings.
138 */
139 void init();
140
141private:
142 /**
143 * This method is called whenever the displayed incidence @p item has been changed.
144 */
145 CALENDARSUPPORT_NO_EXPORT void itemChanged(const Akonadi::Item &item) override;
146
147 /**
148 * This method is called whenever the displayed incidence has been
149 * removed from Akonadi.
150 */
151 CALENDARSUPPORT_NO_EXPORT void itemRemoved() override;
152
153 //@cond PRIVATE
154 std::unique_ptr<IncidenceViewerPrivate> const d;
155
156 Q_PRIVATE_SLOT(d, void slotParentCollectionFetched(KJob *))
157 //@endcond
158};
159}
Akonadi::Item incidence() const
Returns the incidence that is currently displayed.
QDate activeDate() const
Returns the active date used for the currently displayed incidence.
void setCalendar(Akonadi::ETMCalendar *calendar)
Sets the Calendar for this viewer.
void setIncidence(const Akonadi::Item &incidence, QDate activeDate=QDate())
Sets the incidence that shall be displayed in the viewer.
IncidenceViewer(Akonadi::ETMCalendar *calendar, QWidget *parent=nullptr)
Creates a new incidence viewer.
void setHeaderText(const QString &text)
Sets an additional text that is shown above the incidence.
void setModel(Akonadi::EntityTreeModel *etm)
Sets the model for this viewer.
~IncidenceViewer() override
Destroys the incidence viewer.
void setDefaultMessage(const QString &message)
Sets the default message that shall be shown if no incidence is set.
void setDelayedClear(bool delayed)
Sets whether the view shall be cleared as soon as an empty incidence is set (default) or delayed when...
void init()
Initialize the widget settings.
QAbstractItemModel * attachmentModel() const
Returns the attachment model for the currently displayed incidence.
Q_OBJECTQ_OBJECT
Q_SLOTSQ_SLOTS
QObject * parent() const const
QWidget(QWidget *parent, Qt::WindowFlags f)
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Feb 21 2025 11:56:03 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.