File indexing completed on 2025-01-19 04:46:47
0001 /* 0002 SPDX-FileCopyrightText: 2018 Allen Winter <winter@kde.org> 0003 SPDX-FileCopyrightText: 2021 Friedrich W. H. Kossebau <kossebau@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "lunarphases.h" 0009 0010 #include <KConfig> 0011 #include <KConfigGroup> 0012 #include <KLocalizedString> 0013 #include <KPluginFactory> 0014 0015 K_PLUGIN_CLASS_WITH_JSON(Lunarphases, "lunarphases.json") 0016 0017 static QIcon phaseIcon(KHolidays::LunarPhase::Phase phase) 0018 { 0019 const QString iconName = (phase == KHolidays::LunarPhase::NewMoon) ? QStringLiteral("moon-phase-new") 0020 : (phase == KHolidays::LunarPhase::FullMoon) ? QStringLiteral("moon-phase-full") 0021 : (phase == KHolidays::LunarPhase::FirstQuarter) ? QStringLiteral("moon-phase-first-quarter") 0022 : (phase == KHolidays::LunarPhase::LastQuarter) ? QStringLiteral("moon-phase-last-quarter") 0023 : 0024 /* else */ QString(); 0025 return iconName.isEmpty() ? QIcon() : QIcon::fromTheme(iconName); 0026 } 0027 0028 LunarphasesElement::LunarphasesElement(KHolidays::LunarPhase::Phase phase) 0029 : Element(QStringLiteral("main element")) 0030 , mName(KHolidays::LunarPhase::phaseName(phase)) 0031 , mIcon(phaseIcon(phase)) 0032 { 0033 } 0034 0035 QString LunarphasesElement::shortText() const 0036 { 0037 return mName; 0038 } 0039 0040 QString LunarphasesElement::longText() const 0041 { 0042 return mName; 0043 } 0044 0045 QPixmap LunarphasesElement::newPixmap(const QSize &size) 0046 { 0047 // TODO: support south hemisphere & equator by rotating by 90 and 180 degrees 0048 return mIcon.pixmap(size); 0049 } 0050 0051 Lunarphases::Lunarphases(QObject *parent, const QVariantList &args) 0052 : Decoration(parent, args) 0053 { 0054 KConfig _config(QStringLiteral("korganizerrc")); 0055 KConfigGroup config(&_config, QStringLiteral("Calendar/Lunar Phases Plugin")); 0056 } 0057 0058 QString Lunarphases::info() const 0059 { 0060 return i18n( 0061 "This plugin displays the day's lunar phase (New, First, Last, Full). " 0062 "Currently, the phase is computed for noon at UTC; therefore, you should " 0063 "expect variations by 1 day in either direction."); 0064 } 0065 0066 Element::List Lunarphases::createDayElements(const QDate &date) 0067 { 0068 Element::List result; 0069 0070 KHolidays::LunarPhase::Phase phase = KHolidays::LunarPhase::phaseAtDate(date); 0071 if (phase != KHolidays::LunarPhase::None) { 0072 auto e = new LunarphasesElement(phase); 0073 result.append(e); 0074 } 0075 0076 return result; 0077 } 0078 0079 #include "lunarphases.moc" 0080 0081 #include "moc_lunarphases.cpp"