File indexing completed on 2025-01-05 04:47:40
0001 /* 0002 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company 0003 SPDX-FileContributor: Tobias Koenig <tokoe@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "calendarsupport_export.h" 0011 0012 #include <Akonadi/ItemMonitor> 0013 0014 #include <QDate> 0015 #include <QWidget> 0016 0017 #include <memory> 0018 0019 class QAbstractItemModel; 0020 0021 namespace Akonadi 0022 { 0023 class EntityTreeModel; 0024 class ETMCalendar; 0025 } 0026 0027 namespace CalendarSupport 0028 { 0029 class IncidenceViewerPrivate; 0030 0031 /** 0032 * @short A viewer component for incidences in Akonadi. 0033 * 0034 * This widgets provides a way to show an incidence from the 0035 * Akonadi storage. 0036 * 0037 * Example: 0038 * 0039 * @code 0040 * 0041 * using namespace CalendarSupport; 0042 * 0043 * const Item item = ... 0044 * 0045 * IncidenceViewer *viewer = new IncidenceViewer( this ); 0046 * viewer->setIncidence( item ); 0047 * 0048 * @endcode 0049 * 0050 * @author Tobias Koenig <tokoe@kde.org> 0051 * @since 4.5 0052 */ 0053 class CALENDARSUPPORT_EXPORT IncidenceViewer : public QWidget, public Akonadi::ItemMonitor 0054 { 0055 Q_OBJECT 0056 0057 public: 0058 /** 0059 * Creates a new incidence viewer. 0060 * 0061 * *param 0062 * @param calendar is a pointer to a Calendar instance. 0063 * @param parent it the parent widget. 0064 */ 0065 CALENDARSUPPORT_DEPRECATED_VERSION(5, 24, "Use constructor with ETM") 0066 explicit IncidenceViewer(Akonadi::ETMCalendar *calendar, QWidget *parent = nullptr); 0067 explicit IncidenceViewer(Akonadi::EntityTreeModel *etm, QWidget *parent = nullptr); 0068 0069 /** 0070 * Creates a new incidence viewer. 0071 * 0072 * *param 0073 * @param parent it the parent widget. 0074 */ 0075 explicit IncidenceViewer(QWidget *parent = nullptr); 0076 0077 /** 0078 * Destroys the incidence viewer. 0079 */ 0080 ~IncidenceViewer() override; 0081 0082 /** 0083 * Sets the Calendar for this viewer. 0084 * @param calendar is a pointer to a Calendar instance. 0085 */ 0086 CALENDARSUPPORT_DEPRECATED_VERSION(5, 24, "Prefer passing an ETM via setModel()") 0087 void setCalendar(Akonadi::ETMCalendar *calendar); 0088 0089 /** 0090 * Sets the model for this viewer. 0091 * @param etm is a pointer to an ETM instance. 0092 */ 0093 void setModel(Akonadi::EntityTreeModel *etm); 0094 0095 /** 0096 * Returns the incidence that is currently displayed. 0097 */ 0098 [[nodiscard]] Akonadi::Item incidence() const; 0099 0100 /** 0101 * Returns the active date used for the currently displayed incidence 0102 */ 0103 [[nodiscard]] QDate activeDate() const; 0104 0105 /** 0106 * Returns the attachment model for the currently displayed incidence. 0107 */ 0108 QAbstractItemModel *attachmentModel() const; 0109 0110 /** 0111 * Sets whether the view shall be cleared as soon as an empty incidence is 0112 * set (default) or @p delayed when the next valid incidence is set. 0113 */ 0114 void setDelayedClear(bool delayed); 0115 0116 /** 0117 * Sets the default @p message that shall be shown if no incidence is set. 0118 */ 0119 void setDefaultMessage(const QString &message); 0120 0121 /** 0122 * Sets an additional @p text that is shown above the incidence. 0123 */ 0124 void setHeaderText(const QString &text); 0125 0126 public Q_SLOTS: 0127 /** 0128 * Sets the @p incidence that shall be displayed in the viewer. 0129 * 0130 * @param activeDate The active date is used to calculate the actual date of 0131 * the selected incidence in case of recurring incidences. 0132 */ 0133 void setIncidence(const Akonadi::Item &incidence, QDate activeDate = QDate()); 0134 0135 protected: 0136 /** 0137 * Initialize the widget settings. 0138 */ 0139 void init(); 0140 0141 private: 0142 /** 0143 * This method is called whenever the displayed incidence @p item has been changed. 0144 */ 0145 CALENDARSUPPORT_NO_EXPORT void itemChanged(const Akonadi::Item &item) override; 0146 0147 /** 0148 * This method is called whenever the displayed incidence has been 0149 * removed from Akonadi. 0150 */ 0151 CALENDARSUPPORT_NO_EXPORT void itemRemoved() override; 0152 0153 private: 0154 //@cond PRIVATE 0155 std::unique_ptr<IncidenceViewerPrivate> const d; 0156 0157 Q_PRIVATE_SLOT(d, void slotParentCollectionFetched(KJob *)) 0158 //@endcond 0159 }; 0160 }