Eventviews

journalview.cpp
1/*
2 This file is part of KOrganizer.
3
4 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
5 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
8*/
9
10// View of Journal entries
11
12#include "journalview.h"
13#include "journalframe.h"
14
15#include <Akonadi/CalendarUtils>
16#include <CalendarSupport/Utils>
17
18#include "calendarview_debug.h"
19#include <QEvent>
20#include <QScrollArea>
21#include <QVBoxLayout>
22
23using namespace EventViews;
24
25JournalView::JournalView(QWidget *parent)
26 : EventView(parent)
27{
28 auto topLayout = new QVBoxLayout(this);
29 topLayout->setContentsMargins({});
30 mSA = new QScrollArea(this);
31 mCurrentWidget = new QWidget(mSA->viewport());
32 auto mVBoxVBoxLayout = new QVBoxLayout(mCurrentWidget);
33 mVBoxVBoxLayout->setContentsMargins({});
34 mSA->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
35 mSA->setWidgetResizable(true);
36 mSA->setWidget(mCurrentWidget);
37 topLayout->addWidget(mSA);
38
39 installEventFilter(this);
40}
41
42JournalView::~JournalView() = default;
43
44void JournalView::appendJournal(const Akonadi::Item &journal, const Akonadi::CollectionCalendar::Ptr &calendar, QDate dt)
45{
46 JournalDateView *entry = nullptr;
47 if (mEntries.contains(dt)) {
48 entry = mEntries[dt];
49 } else {
50 entry = new JournalDateView(calendar, mCurrentWidget);
51 mCurrentWidget->layout()->addWidget(entry);
52 entry->setDate(dt);
53 entry->setIncidenceChanger(mChanger);
54 entry->show();
55 connect(this, &JournalView::flushEntries, entry, &JournalDateView::flushEntries);
56 connect(this, &JournalView::setIncidenceChangerSignal, entry, &JournalDateView::setIncidenceChanger);
57 connect(this, &JournalView::journalEdited, entry, &JournalDateView::journalEdited);
58 connect(this, &JournalView::journalDeleted, entry, &JournalDateView::journalDeleted);
59
60 connect(entry, &JournalDateView::editIncidence, this, &EventView::editIncidenceSignal);
61 connect(entry, &JournalDateView::deleteIncidence, this, &EventView::deleteIncidenceSignal);
62 connect(entry, &JournalDateView::newJournal, this, &EventView::newJournalSignal);
63 connect(entry, &JournalDateView::incidenceSelected, this, &EventView::incidenceSelected);
64 connect(entry, &JournalDateView::printJournal, this, &JournalView::printJournal);
65 mEntries.insert(dt, entry);
66 }
67
68 if (entry && CalendarSupport::hasJournal(journal)) {
69 entry->addJournal(journal);
70 }
71}
72
74{
75 return mEntries.size();
76}
77
79{
80 // We don't have a selection in the journal view.
81 // FIXME: The currently edited journal is the selected incidence...
82 Akonadi::Item::List eventList;
83 return eventList;
84}
85
86void JournalView::clearEntries()
87{
88 // qDebug() << "JournalView::clearEntries()";
90 for (it = mEntries.begin(); it != mEntries.end(); ++it) {
91 delete it.value();
92 }
93 mEntries.clear();
94}
95
96void JournalView::updateView()
97{
99 while (it != mEntries.begin()) {
100 --it;
101 it.value()->clear();
102 for (const auto &calendar : calendars()) {
103 const auto journals = calendar->journals(it.key());
104 for (const auto &journal : journals) {
105 it.value()->addJournal(calendar->item(journal));
106 }
107 }
108 }
109}
110
111void JournalView::flushView()
112{
113 Q_EMIT flushEntries();
114}
115
116void JournalView::showDates(const QDate &start, const QDate &end, const QDate &)
117{
118 clearEntries();
119 if (end < start) {
120 qCWarning(CALENDARVIEW_LOG) << "End is smaller than start. end=" << end << "; start=" << start;
121 return;
122 }
123
124 const auto cals = calendars();
125 for (QDate d = end; d >= start; d = d.addDays(-1)) {
126 for (const auto &calendar : cals) {
127 const KCalendarCore::Journal::List jnls = calendar->journals(d);
128 // qCDebug(CALENDARVIEW_LOG) << "Found" << jnls.count() << "journals on date" << d;
129 for (const KCalendarCore::Journal::Ptr &journal : jnls) {
130 Akonadi::Item item = calendar->item(journal);
131 appendJournal(item, calendar, d);
132 }
133 if (jnls.isEmpty()) {
134 // create an empty dateentry widget
135 // updateView();
136 // qCDebug(CALENDARVIEW_LOG) << "Appended null journal";
137 appendJournal(Akonadi::Item(), calendar, d);
138 }
139 }
140 }
141}
142
143void JournalView::showIncidences(const Akonadi::Item::List &incidences, const QDate &date)
144{
145 Q_UNUSED(date)
146 clearEntries();
147 for (const Akonadi::Item &i : incidences) {
149 appendJournal(i, calendar3(j), j->dtStart().date());
150 }
151 }
152}
153
154void JournalView::changeIncidenceDisplay(const Akonadi::Item &incidence, Akonadi::IncidenceChanger::ChangeType changeType)
155{
157 switch (changeType) {
158 case Akonadi::IncidenceChanger::ChangeTypeCreate:
159 appendJournal(incidence, calendar3(incidence), journal->dtStart().date());
160 break;
161 case Akonadi::IncidenceChanger::ChangeTypeModify:
162 Q_EMIT journalEdited(incidence);
163 break;
164 case Akonadi::IncidenceChanger::ChangeTypeDelete:
165 Q_EMIT journalDeleted(incidence);
166 break;
167 default:
168 qCWarning(CALENDARVIEW_LOG) << "Illegal change type" << changeType;
169 }
170 }
171}
172
173void JournalView::setIncidenceChanger(Akonadi::IncidenceChanger *changer)
174{
175 mChanger = changer;
176 Q_EMIT setIncidenceChangerSignal(changer);
177}
178
179void JournalView::newJournal()
180{
181 Q_EMIT newJournalSignal(QDate::currentDate());
182}
183
184bool JournalView::eventFilter(QObject *object, QEvent *event)
185{
186 Q_UNUSED(object)
187 switch (event->type()) {
189 Q_EMIT newJournalSignal(QDate());
190 return true;
191 default:
192 return false;
193 }
194}
195
196#include "moc_journalview.cpp"
EventView is the abstract base class from which all other calendar views for event data are derived.
Definition eventview.h:69
void deleteIncidenceSignal(const Akonadi::Item &)
instructs the receiver to delete the Incidence in some manner; some possibilities include automatical...
void editIncidenceSignal(const Akonadi::Item &)
instructs the receiver to begin editing the incidence specified in some manner.
Akonadi::Item::List selectedIncidences() const override
int currentDateCount() const override
Returns the number of currently shown dates.
Q_SCRIPTABLE Q_NOREPLY void start()
AKONADI_CALENDAR_EXPORT KCalendarCore::Journal::Ptr journal(const Akonadi::Item &item)
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
const QList< QKeySequence > & end()
QDate addDays(qint64 ndays) const const
QDate currentDate()
MouseButtonDblClick
void addWidget(QWidget *w)
iterator begin()
void clear()
bool contains(const Key &key) const const
iterator end()
iterator insert(const Key &key, const T &value)
Key key(const T &value, const Key &defaultKey) const const
size_type size() const const
T value(const Key &key, const T &defaultValue) const const
Q_EMITQ_EMIT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
ScrollBarAlwaysOff
virtual bool event(QEvent *event) override
QLayout * layout() const const
void show()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:07:11 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.