File indexing completed on 2025-03-09 04:45:07
0001 /* 0002 SPDX-FileCopyrightText: 2007 Loïc Corbasson <loic.corbasson@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #include "calendardecoration.h" 0007 0008 using namespace EventViews::CalendarDecoration; 0009 0010 Element::Element(const QString &id) 0011 : mId(id) 0012 { 0013 } 0014 0015 Element::~Element() = default; 0016 0017 QString Element::id() const 0018 { 0019 return mId; 0020 } 0021 0022 QString Element::elementInfo() const 0023 { 0024 return {}; 0025 } 0026 0027 QString Element::shortText() const 0028 { 0029 return {}; 0030 } 0031 0032 QString Element::longText() const 0033 { 0034 return {}; 0035 } 0036 0037 QString Element::extensiveText() const 0038 { 0039 return {}; 0040 } 0041 0042 QPixmap Element::newPixmap(const QSize &) 0043 { 0044 return {}; 0045 } 0046 0047 QUrl Element::url() const 0048 { 0049 return {}; 0050 } 0051 0052 //////////////////////////////////////////////////////////////////////////////// 0053 0054 StoredElement::StoredElement(const QString &id) 0055 : Element(id) 0056 { 0057 } 0058 0059 StoredElement::StoredElement(const QString &id, const QString &shortText) 0060 : Element(id) 0061 , mShortText(shortText) 0062 { 0063 } 0064 0065 StoredElement::StoredElement(const QString &id, const QString &shortText, const QString &longText) 0066 : Element(id) 0067 , mShortText(shortText) 0068 , mLongText(longText) 0069 { 0070 } 0071 0072 StoredElement::StoredElement(const QString &id, const QString &shortText, const QString &longText, const QString &extensiveText) 0073 : Element(id) 0074 , mShortText(shortText) 0075 , mLongText(longText) 0076 , mExtensiveText(extensiveText) 0077 { 0078 } 0079 0080 StoredElement::StoredElement(const QString &id, const QPixmap &pixmap) 0081 : Element(id) 0082 , mPixmap(pixmap) 0083 { 0084 } 0085 0086 void StoredElement::setShortText(const QString &t) 0087 { 0088 mShortText = t; 0089 } 0090 0091 QString StoredElement::shortText() const 0092 { 0093 return mShortText; 0094 } 0095 0096 void StoredElement::setLongText(const QString &t) 0097 { 0098 mLongText = t; 0099 } 0100 0101 QString StoredElement::longText() const 0102 { 0103 return mLongText; 0104 } 0105 0106 void StoredElement::setExtensiveText(const QString &t) 0107 { 0108 mExtensiveText = t; 0109 } 0110 0111 QString StoredElement::extensiveText() const 0112 { 0113 return mExtensiveText; 0114 } 0115 0116 void StoredElement::setPixmap(const QPixmap &p) 0117 { 0118 mPixmap = p; 0119 } 0120 0121 QPixmap StoredElement::pixmap() const 0122 { 0123 return mPixmap; 0124 } 0125 0126 void StoredElement::setUrl(const QUrl &u) 0127 { 0128 mUrl = u; 0129 } 0130 0131 QUrl StoredElement::url() const 0132 { 0133 return mUrl; 0134 } 0135 0136 //////////////////////////////////////////////////////////////////////////////// 0137 0138 Decoration::Decoration(QObject *parent, const QVariantList &args) 0139 : QObject(parent) 0140 { 0141 Q_UNUSED(args) 0142 } 0143 0144 Decoration::~Decoration() 0145 { 0146 // Deleted by label directly. 0147 #if 0 0148 for (Element::List lst : std::as_const(mDayElements)) { 0149 qDeleteAll(lst); 0150 lst.clear(); 0151 } 0152 for (Element::List lst : std::as_const(mWeekElements)) { 0153 qDeleteAll(lst); 0154 lst.clear(); 0155 } 0156 for (Element::List lst : std::as_const(mMonthElements)) { 0157 qDeleteAll(lst); 0158 lst.clear(); 0159 } 0160 for (Element::List lst : std::as_const(mYearElements)) { 0161 qDeleteAll(lst); 0162 lst.clear(); 0163 } 0164 #endif 0165 mDayElements.clear(); 0166 mWeekElements.clear(); 0167 mMonthElements.clear(); 0168 mYearElements.clear(); 0169 } 0170 0171 Element::List Decoration::dayElements(const QDate &date) 0172 { 0173 QMap<QDate, Element::List>::ConstIterator it; 0174 it = mDayElements.constFind(date); 0175 if (it == mDayElements.constEnd()) { 0176 return registerDayElements(createDayElements(date), date); 0177 } else { 0178 return *it; 0179 } 0180 } 0181 0182 Element::List Decoration::weekElements(const QDate &d) 0183 { 0184 QDate date = weekDate(d); 0185 QMap<QDate, Element::List>::ConstIterator it; 0186 it = mWeekElements.constFind(date); 0187 if (it == mWeekElements.constEnd()) { 0188 return registerWeekElements(createWeekElements(date), date); 0189 } else { 0190 return *it; 0191 } 0192 } 0193 0194 Element::List Decoration::monthElements(const QDate &d) 0195 { 0196 QDate date = monthDate(d); 0197 QMap<QDate, Element::List>::ConstIterator it; 0198 it = mMonthElements.constFind(date); 0199 if (it == mMonthElements.constEnd()) { 0200 return registerMonthElements(createMonthElements(date), date); 0201 } else { 0202 return *it; 0203 } 0204 } 0205 0206 Element::List Decoration::yearElements(const QDate &d) 0207 { 0208 QDate date = yearDate(d); 0209 QMap<QDate, Element::List>::ConstIterator it; 0210 it = mYearElements.constFind(date); 0211 if (it == mYearElements.constEnd()) { 0212 return registerYearElements(createYearElements(date), date); 0213 } else { 0214 return *it; 0215 } 0216 } 0217 0218 Element::List Decoration::registerDayElements(const Element::List &e, const QDate &d) 0219 { 0220 mDayElements.insert(d, e); 0221 return e; 0222 } 0223 0224 Element::List Decoration::registerWeekElements(const Element::List &e, const QDate &d) 0225 { 0226 mWeekElements.insert(weekDate(d), e); 0227 return e; 0228 } 0229 0230 Element::List Decoration::registerMonthElements(const Element::List &e, const QDate &d) 0231 { 0232 mMonthElements.insert(monthDate(d), e); 0233 return e; 0234 } 0235 0236 Element::List Decoration::registerYearElements(const Element::List &e, const QDate &d) 0237 { 0238 mYearElements.insert(yearDate(d), e); 0239 return e; 0240 } 0241 0242 Element::List Decoration::createDayElements(const QDate &) 0243 { 0244 return {}; 0245 } 0246 0247 Element::List Decoration::createWeekElements(const QDate &) 0248 { 0249 return {}; 0250 } 0251 0252 Element::List Decoration::createMonthElements(const QDate &) 0253 { 0254 return {}; 0255 } 0256 0257 Element::List Decoration::createYearElements(const QDate &) 0258 { 0259 return {}; 0260 } 0261 0262 void Decoration::configure(QWidget *) 0263 { 0264 } 0265 0266 QDate Decoration::weekDate(QDate date) 0267 { 0268 QDate result = date; 0269 return result.addDays(date.dayOfWeek() - 1); 0270 } 0271 0272 QDate Decoration::monthDate(QDate date) 0273 { 0274 return {date.year(), date.month(), 1}; 0275 } 0276 0277 QDate Decoration::yearDate(QDate date) 0278 { 0279 return {date.year(), 1, 1}; 0280 } 0281 0282 #include "moc_calendardecoration.cpp"