Eventviews

prefs.cpp
1/*
2 SPDX-FileCopyrightText: 2001, 2003 Cornelius Schumacher <schumacher@kde.org>
3 SPDX-FileCopyrightText: 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
4 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
5 SPDX-FileContributor: Kevin Krammer <krake@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
8*/
9#include "prefs.h"
10#include "prefs_base.h"
11
12#include "calendarview_debug.h"
13
14#include <Akonadi/AttributeFactory>
15#include <Akonadi/CollectionColorAttribute>
16
17#include <QFontDatabase>
18#include <QRandomGenerator>
19using namespace EventViews;
20
21QSet<EventViews::EventView::ItemIcon> iconArrayToSet(const QByteArray &array)
22{
24 for (int i = 0; i < array.size(); ++i) {
25 if (i >= EventViews::EventView::IconCount) {
26 qCWarning(CALENDARVIEW_LOG) << "Icon array is too big: " << array.size();
27 return set;
28 }
29 if (array[i] != 0) {
30 set.insert(static_cast<EventViews::EventView::ItemIcon>(i));
31 }
32 }
33 return set;
34}
35
37{
38 QByteArray array;
39 for (int i = 0; i < EventViews::EventView::IconCount; ++i) {
40 const bool contains = set.contains(static_cast<EventViews::EventView::ItemIcon>(i));
41 array.append(contains ? 1 : 0);
42 }
43
44 return array;
45}
46
47QByteArray agendaViewIconDefaults()
48{
49 QByteArray iconDefaults;
50 iconDefaults.resize(7);
51
52 iconDefaults[EventViews::EventView::CalendarCustomIcon] = 1;
53 iconDefaults[EventViews::EventView::TaskIcon] = 1;
54 iconDefaults[EventViews::EventView::JournalIcon] = 1;
55 iconDefaults[EventViews::EventView::RecurringIcon] = 1;
56 iconDefaults[EventViews::EventView::ReminderIcon] = 1;
57 iconDefaults[EventViews::EventView::ReadOnlyIcon] = 1;
58 iconDefaults[EventViews::EventView::ReplyIcon] = 0;
59
60 return iconDefaults;
61}
62
63QByteArray monthViewIconDefaults()
64{
65 QByteArray iconDefaults;
66 iconDefaults.resize(7);
67
68 iconDefaults[EventViews::EventView::CalendarCustomIcon] = 1;
69 iconDefaults[EventViews::EventView::TaskIcon] = 1;
70 iconDefaults[EventViews::EventView::JournalIcon] = 1;
71 iconDefaults[EventViews::EventView::RecurringIcon] = 0;
72 iconDefaults[EventViews::EventView::ReminderIcon] = 0;
73 iconDefaults[EventViews::EventView::ReadOnlyIcon] = 1;
74 iconDefaults[EventViews::EventView::ReplyIcon] = 0;
75
76 return iconDefaults;
77}
78
79class BaseConfig : public PrefsBase
80{
81public:
82 BaseConfig();
83
84 void setResourceColor(const QString &resource, const QColor &color);
85
86 void setTimeScaleTimezones(const QStringList &timeZones);
87 QStringList timeScaleTimezones() const;
88
89public:
90 QHash<QString, QColor> mResourceColors;
91 QColor mDefaultResourceColor;
92
93 QFont mDefaultMonthViewFont;
94 QFont mDefaultAgendaTimeLabelsFont;
95
96 QStringList mTimeScaleTimeZones;
97
100
101protected:
102 void usrSetDefaults() override;
103 void usrRead() override;
104 bool usrSave() override;
105};
106
107BaseConfig::BaseConfig()
108 : PrefsBase()
109{
110 mDefaultResourceColor = QColor(); // Default is a color invalid
111
112 mDefaultAgendaTimeLabelsFont = QFontDatabase::systemFont(QFontDatabase::GeneralFont);
113 // make a large default time bar font, at least 16 points.
114 mDefaultAgendaTimeLabelsFont.setPointSize(qMax(mDefaultAgendaTimeLabelsFont.pointSize() + 4, 16));
115
117 // make it a bit smaller
118 mDefaultMonthViewFont.setPointSize(qMax(mDefaultMonthViewFont.pointSize() - 2, 6));
119
120 agendaTimeLabelsFontItem()->setDefaultValue(mDefaultAgendaTimeLabelsFont);
121 agendaTimeLabelsFontItem()->setDefault();
122 monthViewFontItem()->setDefaultValue(mDefaultMonthViewFont);
123 monthViewFontItem()->setDefault();
124}
125
126void BaseConfig::setResourceColor(const QString &resource, const QColor &color)
127{
128 mResourceColors.insert(resource, color);
129}
130
131void BaseConfig::setTimeScaleTimezones(const QStringList &list)
132{
133 mTimeScaleTimeZones = list;
134}
135
136QStringList BaseConfig::timeScaleTimezones() const
137{
138 return mTimeScaleTimeZones;
139}
140
141void BaseConfig::usrSetDefaults()
142{
143 setAgendaTimeLabelsFont(mDefaultAgendaTimeLabelsFont);
144 setMonthViewFont(mDefaultMonthViewFont);
145
146 PrefsBase::usrSetDefaults();
147}
148
149void BaseConfig::usrRead()
150{
151 KConfigGroup rColorsConfig(config(), QStringLiteral("Resources Colors"));
152 const QStringList colorKeyList = rColorsConfig.keyList();
153
154 for (const QString &key : colorKeyList) {
155 QColor color = rColorsConfig.readEntry(key, mDefaultResourceColor);
156 // qCDebug(CALENDARVIEW_LOG) << "key:" << key << "value:" << color;
157 setResourceColor(key, color);
158 }
159
160#if 0
161 config()->setGroup("FreeBusy");
162 if (mRememberRetrievePw) {
163 mRetrievePassword
164 = KStringHandler::obscure(config()->readEntry("Retrieve Server Password"));
165 }
166#endif
167
168 KConfigGroup timeScaleConfig(config(), QStringLiteral("Timescale"));
169 setTimeScaleTimezones(timeScaleConfig.readEntry("Timescale Timezones", QStringList()));
170
171 KConfigGroup monthViewConfig(config(), QStringLiteral("Month View"));
172 KConfigGroup agendaViewConfig(config(), QStringLiteral("Agenda View"));
173 const auto agendaIconArray = agendaViewConfig.readEntry<QByteArray>("agendaViewItemIcons", agendaViewIconDefaults());
174 const auto monthIconArray = monthViewConfig.readEntry<QByteArray>("monthViewItemIcons", monthViewIconDefaults());
175
176 mAgendaViewIcons = iconArrayToSet(agendaIconArray);
177 mMonthViewIcons = iconArrayToSet(monthIconArray);
178
180}
181
182bool BaseConfig::usrSave()
183{
184 KConfigGroup rColorsConfig(config(), QStringLiteral("Resources Colors"));
185 for (auto it = mResourceColors.constBegin(); it != mResourceColors.constEnd(); ++it) {
186 rColorsConfig.writeEntry(it.key(), it.value());
187 }
188
189#if 0
190 if (mRememberRetrievePw) {
191 config()->writeEntry("Retrieve Server Password",
192 KStringHandler::obscure(mRetrievePassword));
193 } else {
194 config()->deleteEntry("Retrieve Server Password");
195 }
196#endif
197
198 KConfigGroup timeScaleConfig(config(), QStringLiteral("Timescale"));
199 timeScaleConfig.writeEntry("Timescale Timezones", timeScaleTimezones());
200
201 KConfigGroup monthViewConfig(config(), QStringLiteral("Month View"));
202 KConfigGroup agendaViewConfig(config(), QStringLiteral("Agenda View"));
203
204 const QByteArray agendaIconArray = iconSetToArray(mAgendaViewIcons);
205 const QByteArray monthIconArray = iconSetToArray(mMonthViewIcons);
206
207 agendaViewConfig.writeEntry<QByteArray>("agendaViewItemIcons", agendaIconArray);
208 monthViewConfig.writeEntry<QByteArray>("monthViewItemIcons", monthIconArray);
209
211}
212
213class EventViews::PrefsPrivate
214{
215public:
216 explicit PrefsPrivate(Prefs *parent)
217 : mAppConfig(nullptr)
218 , q(parent)
219 {
220 }
221
222 PrefsPrivate(Prefs *parent, KCoreConfigSkeleton *appConfig)
223 : mAppConfig(appConfig)
224 , q(parent)
225 {
226 }
227
228 KConfigSkeletonItem *appConfigItem(const KConfigSkeletonItem *baseConfigItem) const;
229
230 void setBool(KCoreConfigSkeleton::ItemBool *baseConfigItem, bool value);
231 bool getBool(const KCoreConfigSkeleton::ItemBool *baseConfigItem) const;
232
233 void setInt(KCoreConfigSkeleton::ItemInt *baseConfigItem, int value);
234 int getInt(const KCoreConfigSkeleton::ItemInt *baseConfigItem) const;
235
236 void setString(KCoreConfigSkeleton::ItemString *baseConfigItem, const QString &value);
237 QString getString(const KCoreConfigSkeleton::ItemString *baseConfigItem) const;
238
239 void setDateTime(KCoreConfigSkeleton::ItemDateTime *baseConfigItem, const QDateTime &value);
240 QDateTime getDateTime(const KCoreConfigSkeleton::ItemDateTime *baseConfigItem) const;
241
242 void setStringList(KCoreConfigSkeleton::ItemStringList *baseConfigItem, const QStringList &value);
243 QStringList getStringList(const KCoreConfigSkeleton::ItemStringList *baseConfigItem) const;
244
245 void setColor(KConfigSkeleton::ItemColor *baseConfigItem, const QColor &value);
246 QColor getColor(const KConfigSkeleton::ItemColor *baseConfigItem) const;
247
248 void setFont(KConfigSkeleton::ItemFont *baseConfigItem, const QFont &value);
249 QFont getFont(const KConfigSkeleton::ItemFont *baseConfigItem) const;
250
251public:
252 BaseConfig mBaseConfig;
253 KCoreConfigSkeleton *mAppConfig = nullptr;
254
255private:
256 Prefs *q;
257};
258
259KConfigSkeletonItem *PrefsPrivate::appConfigItem(const KConfigSkeletonItem *baseConfigItem) const
260{
261 Q_ASSERT(baseConfigItem);
262
263 if (mAppConfig) {
264 return mAppConfig->findItem(baseConfigItem->name());
265 }
266
267 return nullptr;
268}
269
270void PrefsPrivate::setBool(KCoreConfigSkeleton::ItemBool *baseConfigItem, bool value)
271{
272 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
273 if (appItem) {
274 auto item = dynamic_cast<KCoreConfigSkeleton::ItemBool *>(appItem);
275 if (item) {
276 item->setValue(value);
277 } else {
278 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Bool";
279 }
280 } else {
281 baseConfigItem->setValue(value);
282 }
283}
284
285bool PrefsPrivate::getBool(const KCoreConfigSkeleton::ItemBool *baseConfigItem) const
286{
287 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
288 if (appItem) {
289 auto item = dynamic_cast<KCoreConfigSkeleton::ItemBool *>(appItem);
290 if (item) {
291 return item->value();
292 }
293 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Bool";
294 }
295 return baseConfigItem->value();
296}
297
298void PrefsPrivate::setInt(KCoreConfigSkeleton::ItemInt *baseConfigItem, int value)
299{
300 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
301 if (appItem) {
302 auto item = dynamic_cast<KCoreConfigSkeleton::ItemInt *>(appItem);
303 if (item) {
304 item->setValue(value);
305 } else {
306 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Int";
307 }
308 } else {
309 baseConfigItem->setValue(value);
310 }
311}
312
313int PrefsPrivate::getInt(const KCoreConfigSkeleton::ItemInt *baseConfigItem) const
314{
315 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
316 if (appItem) {
317 auto item = dynamic_cast<KCoreConfigSkeleton::ItemInt *>(appItem);
318 if (item) {
319 return item->value();
320 }
321 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Int";
322 }
323 return baseConfigItem->value();
324}
325
326void PrefsPrivate::setString(KCoreConfigSkeleton::ItemString *baseConfigItem, const QString &value)
327{
328 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
329 if (appItem) {
330 auto item = dynamic_cast<KCoreConfigSkeleton::ItemString *>(appItem);
331
332 if (item) {
333 item->setValue(value);
334 } else {
335 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type String";
336 }
337 } else {
338 baseConfigItem->setValue(value);
339 }
340}
341
342QString PrefsPrivate::getString(const KCoreConfigSkeleton::ItemString *baseConfigItem) const
343{
344 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
345 if (appItem) {
346 auto item = dynamic_cast<KCoreConfigSkeleton::ItemString *>(appItem);
347
348 if (item) {
349 return item->value();
350 }
351 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type String";
352 }
353 return baseConfigItem->value();
354}
355
356void PrefsPrivate::setDateTime(KCoreConfigSkeleton::ItemDateTime *baseConfigItem, const QDateTime &value)
357{
358 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
359 if (appItem) {
360 auto item = dynamic_cast<KCoreConfigSkeleton::ItemDateTime *>(appItem);
361
362 if (item) {
363 item->setValue(value);
364 } else {
365 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type DateTime";
366 }
367 } else {
368 baseConfigItem->setValue(value);
369 }
370}
371
372QDateTime PrefsPrivate::getDateTime(const KCoreConfigSkeleton::ItemDateTime *baseConfigItem) const
373{
374 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
375 if (appItem) {
376 auto item = dynamic_cast<KCoreConfigSkeleton::ItemDateTime *>(appItem);
377
378 if (item) {
379 return item->value();
380 }
381 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type DateTime";
382 }
383 return baseConfigItem->value();
384}
385
386void PrefsPrivate::setStringList(KCoreConfigSkeleton::ItemStringList *baseConfigItem, const QStringList &value)
387{
388 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
389 if (appItem) {
390 auto item = dynamic_cast<KCoreConfigSkeleton::ItemStringList *>(appItem);
391
392 if (item) {
393 item->setValue(value);
394 } else {
395 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type StringList";
396 }
397 } else {
398 baseConfigItem->setValue(value);
399 }
400}
401
402QStringList PrefsPrivate::getStringList(const KCoreConfigSkeleton::ItemStringList *baseConfigItem) const
403{
404 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
405 if (appItem) {
406 auto item = dynamic_cast<KCoreConfigSkeleton::ItemStringList *>(appItem);
407
408 if (item) {
409 return item->value();
410 }
411 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type StringList";
412 }
413 return baseConfigItem->value();
414}
415
416void PrefsPrivate::setColor(KConfigSkeleton::ItemColor *baseConfigItem, const QColor &value)
417{
418 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
419 if (appItem) {
420 auto item = dynamic_cast<KConfigSkeleton::ItemColor *>(appItem);
421 if (item) {
422 item->setValue(value);
423 } else {
424 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Color";
425 }
426 } else {
427 baseConfigItem->setValue(value);
428 }
429}
430
431QColor PrefsPrivate::getColor(const KConfigSkeleton::ItemColor *baseConfigItem) const
432{
433 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
434 if (appItem) {
435 auto item = dynamic_cast<KConfigSkeleton::ItemColor *>(appItem);
436 if (item) {
437 return item->value();
438 }
439 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Color";
440 }
441 return baseConfigItem->value();
442}
443
444void PrefsPrivate::setFont(KConfigSkeleton::ItemFont *baseConfigItem, const QFont &value)
445{
446 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
447 if (appItem) {
448 auto item = dynamic_cast<KConfigSkeleton::ItemFont *>(appItem);
449 if (item) {
450 item->setValue(value);
451 } else {
452 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Font";
453 }
454 } else {
455 baseConfigItem->setValue(value);
456 }
457}
458
459QFont PrefsPrivate::getFont(const KConfigSkeleton::ItemFont *baseConfigItem) const
460{
461 KConfigSkeletonItem *appItem = appConfigItem(baseConfigItem);
462 if (appItem) {
463 auto item = dynamic_cast<KConfigSkeleton::ItemFont *>(appItem);
464 if (item) {
465 return item->value();
466 }
467 qCCritical(CALENDARVIEW_LOG) << "Application config item" << appItem->name() << "is not of type Font";
468 }
469 return baseConfigItem->value();
470}
471
472Prefs::Prefs()
473 : d(new PrefsPrivate(this))
474{
475 // necessary to use CollectionColorAttribute in the EventViews::resourceColor and EventViews::setResourceColor
477}
478
479Prefs::Prefs(KCoreConfigSkeleton *appConfig)
480 : d(new PrefsPrivate(this, appConfig))
481{
482 // necessary to use CollectionColorAttribute in the EventViews::resourceColor and EventViews::setResourceColor
484}
485
486Prefs::~Prefs() = default;
487
488void Prefs::readConfig()
489{
490 d->mBaseConfig.load();
491 if (d->mAppConfig) {
492 d->mAppConfig->load();
493 }
494}
495
496void Prefs::writeConfig()
497{
498 d->mBaseConfig.save();
499 if (d->mAppConfig) {
500 d->mAppConfig->save();
501 }
502}
503
504void Prefs::setUseSystemColor(bool useSystemColor)
505{
506 d->setBool(d->mBaseConfig.useSystemColorItem(), useSystemColor);
507}
508
509bool Prefs::useSystemColor() const
510{
511 return d->getBool(d->mBaseConfig.useSystemColorItem());
512}
513
514void Prefs::setMarcusBainsShowSeconds(bool showSeconds)
515{
516 d->setBool(d->mBaseConfig.marcusBainsShowSecondsItem(), showSeconds);
517}
518
519bool Prefs::marcusBainsShowSeconds() const
520{
521 return d->getBool(d->mBaseConfig.marcusBainsShowSecondsItem());
522}
523
524void Prefs::setAgendaMarcusBainsLineLineColor(const QColor &color)
525{
526 d->setColor(d->mBaseConfig.agendaMarcusBainsLineLineColorItem(), color);
527}
528
529QColor Prefs::agendaMarcusBainsLineLineColor() const
530{
531 return d->getColor(d->mBaseConfig.agendaMarcusBainsLineLineColorItem());
532}
533
534void Prefs::setMarcusBainsEnabled(bool enabled)
535{
536 d->setBool(d->mBaseConfig.marcusBainsEnabledItem(), enabled);
537}
538
539bool Prefs::marcusBainsEnabled() const
540{
541 return d->getBool(d->mBaseConfig.marcusBainsEnabledItem());
542}
543
544void Prefs::setAgendaMarcusBainsLineFont(const QFont &font)
545{
546 d->setFont(d->mBaseConfig.agendaMarcusBainsLineFontItem(), font);
547}
548
549QFont Prefs::agendaMarcusBainsLineFont() const
550{
551 return d->getFont(d->mBaseConfig.agendaMarcusBainsLineFontItem());
552}
553
554void Prefs::setHourSize(int size)
555{
556 d->setInt(d->mBaseConfig.hourSizeItem(), size);
557}
558
559int Prefs::hourSize() const
560{
561 return d->getInt(d->mBaseConfig.hourSizeItem());
562}
563
564void Prefs::setDayBegins(const QDateTime &dateTime)
565{
566 d->setDateTime(d->mBaseConfig.dayBeginsItem(), dateTime);
567}
568
569QDateTime Prefs::dayBegins() const
570{
571 return d->getDateTime(d->mBaseConfig.dayBeginsItem());
572}
573
574void Prefs::setFirstDayOfWeek(const int day)
575{
576 d->setInt(d->mBaseConfig.weekStartDayItem(), day - 1);
577}
578
579int Prefs::firstDayOfWeek() const
580{
581 return d->getInt(d->mBaseConfig.weekStartDayItem()) + 1;
582}
583
584void Prefs::setWorkingHoursStart(const QDateTime &dateTime)
585{
586 d->setDateTime(d->mBaseConfig.workingHoursStartItem(), dateTime);
587}
588
589QDateTime Prefs::workingHoursStart() const
590{
591 return d->getDateTime(d->mBaseConfig.workingHoursStartItem());
592}
593
594void Prefs::setWorkingHoursEnd(const QDateTime &dateTime)
595{
596 d->setDateTime(d->mBaseConfig.workingHoursEndItem(), dateTime);
597}
598
599QDateTime Prefs::workingHoursEnd() const
600{
601 return d->getDateTime(d->mBaseConfig.workingHoursEndItem());
602}
603
604void Prefs::setSelectionStartsEditor(bool startEditor)
605{
606 d->setBool(d->mBaseConfig.selectionStartsEditorItem(), startEditor);
607}
608
609bool Prefs::selectionStartsEditor() const
610{
611 return d->getBool(d->mBaseConfig.selectionStartsEditorItem());
612}
613
614void Prefs::setAgendaGridWorkHoursBackgroundColor(const QColor &color)
615{
616 d->setColor(d->mBaseConfig.agendaGridWorkHoursBackgroundColorItem(), color);
617}
618
619QColor Prefs::agendaGridWorkHoursBackgroundColor() const
620{
621 return d->getColor(d->mBaseConfig.agendaGridWorkHoursBackgroundColorItem());
622}
623
624void Prefs::setAgendaGridHighlightColor(const QColor &color)
625{
626 d->setColor(d->mBaseConfig.agendaGridHighlightColorItem(), color);
627}
628
629QColor Prefs::agendaGridHighlightColor() const
630{
631 return d->getColor(d->mBaseConfig.agendaGridHighlightColorItem());
632}
633
634void Prefs::setAgendaGridBackgroundColor(const QColor &color)
635{
636 d->setColor(d->mBaseConfig.agendaGridBackgroundColorItem(), color);
637}
638
639QColor Prefs::agendaGridBackgroundColor() const
640{
641 return d->getColor(d->mBaseConfig.agendaGridBackgroundColorItem());
642}
643
644void Prefs::setEnableAgendaItemIcons(bool enable)
645{
646 d->setBool(d->mBaseConfig.enableAgendaItemIconsItem(), enable);
647}
648
649bool Prefs::enableAgendaItemIcons() const
650{
651 return d->getBool(d->mBaseConfig.enableAgendaItemIconsItem());
652}
653
654void Prefs::setTodosUseCategoryColors(bool useColors)
655{
656 d->setBool(d->mBaseConfig.todosUseCategoryColorsItem(), useColors);
657}
658
659bool Prefs::todosUseCategoryColors() const
660{
661 return d->getBool(d->mBaseConfig.todosUseCategoryColorsItem());
662}
663
664void Prefs::setAgendaHolidaysBackgroundColor(const QColor &color) const
665{
666 d->setColor(d->mBaseConfig.agendaHolidaysBackgroundColorItem(), color);
667}
668
669QColor Prefs::agendaHolidaysBackgroundColor() const
670{
671 return d->getColor(d->mBaseConfig.agendaHolidaysBackgroundColorItem());
672}
673
674void Prefs::setAgendaViewColors(int colors)
675{
676 d->setInt(d->mBaseConfig.agendaViewColorsItem(), colors);
677}
678
679int Prefs::agendaViewColors() const
680{
681 return d->getInt(d->mBaseConfig.agendaViewColorsItem());
682}
683
684void Prefs::setAgendaViewFont(const QFont &font)
685{
686 d->setFont(d->mBaseConfig.agendaViewFontItem(), font);
687}
688
689QFont Prefs::agendaViewFont() const
690{
691 return d->getFont(d->mBaseConfig.agendaViewFontItem());
692}
693
694void Prefs::setMonthViewFont(const QFont &font)
695{
696 d->setFont(d->mBaseConfig.monthViewFontItem(), font);
697}
698
699QFont Prefs::monthViewFont() const
700{
701 return d->getFont(d->mBaseConfig.monthViewFontItem());
702}
703
704QColor Prefs::monthGridBackgroundColor() const
705{
706 return d->getColor(d->mBaseConfig.monthGridBackgroundColorItem());
707}
708
709void Prefs::setMonthGridBackgroundColor(const QColor &color)
710{
711 d->setColor(d->mBaseConfig.monthGridBackgroundColorItem(), color);
712}
713
714QColor Prefs::monthGridWorkHoursBackgroundColor() const
715{
716 return d->getColor(d->mBaseConfig.monthGridWorkHoursBackgroundColorItem());
717}
718
719void Prefs::monthGridWorkHoursBackgroundColor(const QColor &color)
720{
721 d->setColor(d->mBaseConfig.monthGridWorkHoursBackgroundColorItem(), color);
722}
723
724int Prefs::monthViewColors() const
725{
726 return d->getInt(d->mBaseConfig.monthViewColorsItem());
727}
728
729void Prefs::setMonthViewColors(int colors) const
730{
731 d->setInt(d->mBaseConfig.monthViewColorsItem(), colors);
732}
733
734void Prefs::setEnableMonthItemIcons(bool enable)
735{
736 d->setBool(d->mBaseConfig.enableMonthItemIconsItem(), enable);
737}
738
739bool Prefs::enableMonthItemIcons() const
740{
741 return d->getBool(d->mBaseConfig.enableMonthItemIconsItem());
742}
743
744bool Prefs::showTimeInMonthView() const
745{
746 return d->getBool(d->mBaseConfig.showTimeInMonthViewItem());
747}
748
749void Prefs::setShowTimeInMonthView(bool show)
750{
751 d->setBool(d->mBaseConfig.showTimeInMonthViewItem(), show);
752}
753
754bool Prefs::showTodosMonthView() const
755{
756 return d->getBool(d->mBaseConfig.showTodosMonthViewItem());
757}
758
759void Prefs::setShowTodosMonthView(bool enable)
760{
761 d->setBool(d->mBaseConfig.showTodosMonthViewItem(), enable);
762}
763
764bool Prefs::showJournalsMonthView() const
765{
766 return d->getBool(d->mBaseConfig.showJournalsMonthViewItem());
767}
768
769void Prefs::setShowJournalsMonthView(bool enable)
770{
771 d->setBool(d->mBaseConfig.showJournalsMonthViewItem(), enable);
772}
773
774bool Prefs::fullViewMonth() const
775{
776 return d->getBool(d->mBaseConfig.fullViewMonthItem());
777}
778
779void Prefs::setFullViewMonth(bool fullView)
780{
781 d->setBool(d->mBaseConfig.fullViewMonthItem(), fullView);
782}
783
784bool Prefs::sortCompletedTodosSeparately() const
785{
786 return d->getBool(d->mBaseConfig.sortCompletedTodosSeparatelyItem());
787}
788
789void Prefs::setSortCompletedTodosSeparately(bool enable)
790{
791 d->setBool(d->mBaseConfig.sortCompletedTodosSeparatelyItem(), enable);
792}
793
794void Prefs::setEnableToolTips(bool enable)
795{
796 d->setBool(d->mBaseConfig.enableToolTipsItem(), enable);
797}
798
799bool Prefs::enableToolTips() const
800{
801 return d->getBool(d->mBaseConfig.enableToolTipsItem());
802}
803
804void Prefs::setShowTodosAgendaView(bool show)
805{
806 d->setBool(d->mBaseConfig.showTodosAgendaViewItem(), show);
807}
808
809bool Prefs::showTodosAgendaView() const
810{
811 return d->getBool(d->mBaseConfig.showTodosAgendaViewItem());
812}
813
814void Prefs::setAgendaTimeLabelsFont(const QFont &font)
815{
816 d->setFont(d->mBaseConfig.agendaTimeLabelsFontItem(), font);
817}
818
819QFont Prefs::agendaTimeLabelsFont() const
820{
821 return d->getFont(d->mBaseConfig.agendaTimeLabelsFontItem());
822}
823
824QTimeZone Prefs::timeZone() const
825{
827}
828
829bool Prefs::colorAgendaBusyDays() const
830{
831 return d->getBool(d->mBaseConfig.colorBusyDaysEnabledItem());
832}
833
834bool Prefs::colorMonthBusyDays() const
835{
836 return d->getBool(d->mBaseConfig.colorMonthBusyDaysEnabledItem());
837}
838
839QColor Prefs::viewBgBusyColor() const
840{
841 return d->getColor(d->mBaseConfig.viewBgBusyColorItem());
842}
843
844void Prefs::setViewBgBusyColor(const QColor &color)
845{
846 d->mBaseConfig.mViewBgBusyColor = color;
847}
848
849QColor Prefs::holidayColor() const
850{
851 return d->getColor(d->mBaseConfig.holidayColorItem());
852}
853
854void Prefs::setHolidayColor(const QColor &color)
855{
856 d->mBaseConfig.mHolidayColor = color;
857}
858
859QColor Prefs::agendaViewBackgroundColor() const
860{
861 return d->getColor(d->mBaseConfig.agendaBgColorItem());
862}
863
864void Prefs::setAgendaViewBackgroundColor(const QColor &color)
865{
866 d->mBaseConfig.mAgendaBgColor = color;
867}
868
869QColor Prefs::workingHoursColor() const
870{
871 return d->getColor(d->mBaseConfig.workingHoursColorItem());
872}
873
874void Prefs::setWorkingHoursColor(const QColor &color)
875{
876 d->mBaseConfig.mWorkingHoursColor = color;
877}
878
879QColor Prefs::todoDueTodayColor() const
880{
881 return d->getColor(d->mBaseConfig.todoDueTodayColorItem());
882}
883
884void Prefs::setTodoDueTodayColor(const QColor &color)
885{
886 d->mBaseConfig.mTodoDueTodayColor = color;
887}
888
889QColor Prefs::todoOverdueColor() const
890{
891 return d->getColor(d->mBaseConfig.todoOverdueColorItem());
892}
893
894void Prefs::setTodoOverdueColor(const QColor &color)
895{
896 d->mBaseConfig.mTodoOverdueColor = color;
897}
898
899void Prefs::setColorAgendaBusyDays(bool enable)
900{
901 d->mBaseConfig.mColorBusyDaysEnabled = enable;
902}
903
904void Prefs::setColorMonthBusyDays(bool enable)
905{
906 d->mBaseConfig.mColorMonthBusyDaysEnabled = enable;
907}
908
909void Prefs::setResourceColor(const QString &cal, const QColor &color)
910{
911 d->mBaseConfig.setResourceColor(cal, color);
912}
913
914QColor Prefs::resourceColorKnown(const QString &cal) const
915{
916 QColor color;
917 if (!cal.isEmpty()) {
918 color = d->mBaseConfig.mResourceColors.value(cal);
919 }
920 return color;
921}
922
923QColor Prefs::resourceColor(const QString &cal)
924{
925 if (cal.isEmpty()) {
926 return d->mBaseConfig.mDefaultResourceColor;
927 }
928
929 QColor color = resourceColorKnown(cal);
930
931 // assign default color if enabled
932 if (!color.isValid() && d->getBool(d->mBaseConfig.assignDefaultResourceColorsItem())) {
933 color.setRgb(0x37, 0x7A, 0xBC); // blueish
934 const int seed = d->getInt(d->mBaseConfig.defaultResourceColorSeedItem());
935 const QStringList colors = d->getStringList(d->mBaseConfig.defaultResourceColorsItem());
936 if (seed > 0 && seed - 1 < colors.size()) {
937 color = QColor::fromString(colors[seed - 1]);
938 } else {
939 color.setRgb(QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256), QRandomGenerator::global()->bounded(256));
940 }
941 d->setInt(d->mBaseConfig.defaultResourceColorSeedItem(), (seed + 1));
942 d->mBaseConfig.setResourceColor(cal, color);
943 }
944 if (color.isValid()) {
945 return color;
946 } else {
947 return d->mBaseConfig.mDefaultResourceColor;
948 }
949}
950
951QStringList Prefs::timeScaleTimezones() const
952{
953 return d->mBaseConfig.timeScaleTimezones();
954}
955
956void Prefs::setTimeScaleTimezones(const QStringList &list)
957{
958 d->mBaseConfig.setTimeScaleTimezones(list);
959}
960
961KConfigSkeleton::ItemFont *Prefs::fontItem(const QString &name) const
962{
963 KConfigSkeletonItem *item = d->mAppConfig ? d->mAppConfig->findItem(name) : nullptr;
964
965 if (!item) {
966 item = d->mBaseConfig.findItem(name);
967 }
968
969 return dynamic_cast<KConfigSkeleton::ItemFont *>(item);
970}
971
972QStringList Prefs::selectedPlugins() const
973{
974 return d->mBaseConfig.mSelectedPlugins;
975}
976
977QStringList Prefs::decorationsAtAgendaViewTop() const
978{
979 return d->mBaseConfig.decorationsAtAgendaViewTop();
980}
981
982QStringList Prefs::decorationsAtAgendaViewBottom() const
983{
984 return d->mBaseConfig.decorationsAtAgendaViewBottom();
985}
986
987void Prefs::setSelectedPlugins(const QStringList &plugins)
988{
989 d->mBaseConfig.setSelectedPlugins(plugins);
990}
991
992void Prefs::setDecorationsAtAgendaViewTop(const QStringList &decorations)
993{
994 d->mBaseConfig.setDecorationsAtAgendaViewTop(decorations);
995}
996
997void Prefs::setDecorationsAtAgendaViewBottom(const QStringList &decorations)
998{
999 d->mBaseConfig.setDecorationsAtAgendaViewBottom(decorations);
1000}
1001
1002QSet<EventViews::EventView::ItemIcon> Prefs::agendaViewIcons() const
1003{
1004 return d->mBaseConfig.mAgendaViewIcons;
1005}
1006
1007void Prefs::setAgendaViewIcons(const QSet<EventViews::EventView::ItemIcon> &icons)
1008{
1009 d->mBaseConfig.mAgendaViewIcons = icons;
1010}
1011
1012QSet<EventViews::EventView::ItemIcon> Prefs::monthViewIcons() const
1013{
1014 return d->mBaseConfig.mMonthViewIcons;
1015}
1016
1017void Prefs::setMonthViewIcons(const QSet<EventViews::EventView::ItemIcon> &icons)
1018{
1019 d->mBaseConfig.mMonthViewIcons = icons;
1020}
1021
1022void Prefs::setFlatListTodo(bool enable)
1023{
1024 d->mBaseConfig.mFlatListTodo = enable;
1025}
1026
1027bool Prefs::flatListTodo() const
1028{
1029 return d->mBaseConfig.mFlatListTodo;
1030}
1031
1032void Prefs::setFullViewTodo(bool enable)
1033{
1034 d->mBaseConfig.mFullViewTodo = enable;
1035}
1036
1037bool Prefs::fullViewTodo() const
1038{
1039 return d->mBaseConfig.mFullViewTodo;
1040}
1041
1042bool Prefs::enableTodoQuickSearch() const
1043{
1044 return d->mBaseConfig.mEnableTodoQuickSearch;
1045}
1046
1047void Prefs::setEnableTodoQuickSearch(bool enable)
1048{
1049 d->mBaseConfig.mEnableTodoQuickSearch = enable;
1050}
1051
1052bool Prefs::enableQuickTodo() const
1053{
1054 return d->mBaseConfig.mEnableQuickTodo;
1055}
1056
1057void Prefs::setEnableQuickTodo(bool enable)
1058{
1059 d->mBaseConfig.mEnableQuickTodo = enable;
1060}
1061
1062bool Prefs::highlightTodos() const
1063{
1064 return d->mBaseConfig.mHighlightTodos;
1065}
1066
1067void Prefs::setHighlightTodos(bool highlight)
1068{
1069 d->mBaseConfig.mHighlightTodos = highlight;
1070}
1071
1072KConfig *Prefs::config() const
1073{
1074 return d->mAppConfig ? d->mAppConfig->config() : d->mBaseConfig.config();
1075}
static void registerAttribute()
void setValue(const T &v)
QString name() const
virtual bool usrSave()
KConfigSkeletonItem * findItem(const QString &name) const
virtual void usrRead()
Namespace EventViews provides facilities for displaying incidences, including events,...
Definition agenda.h:33
KIOCORE_EXPORT QStringList list(const QString &fileClass)
KCOREADDONS_EXPORT QString obscure(const QString &str)
QByteArray & append(QByteArrayView data)
void resize(qsizetype newSize, char c)
qsizetype size() const const
QColor fromString(QAnyStringView name)
bool isValid() const const
void setRgb(QRgb rgb)
QFont systemFont(SystemFont type)
const_iterator constBegin() const const
const_iterator constEnd() const const
iterator insert(const Key &key, const T &value)
qsizetype size() const const
QRandomGenerator * global()
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
bool isEmpty() const const
QTimeZone systemTimeZone()
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.