File indexing completed on 2024-11-24 04:41:37
0001 /* 0002 SPDX-FileCopyrightText: 2023 Kevin Ottens <ervin@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0 0005 */ 0006 0007 #include "coloredtodoproxymodel.h" 0008 0009 #include <Akonadi/TodoModel> 0010 0011 class ColoredTodoProxyModelPrivate 0012 { 0013 public: 0014 ColoredTodoProxyModelPrivate(const EventViews::PrefsPtr &preferences) 0015 : m_preferences(preferences) 0016 { 0017 } 0018 0019 EventViews::PrefsPtr m_preferences; 0020 }; 0021 0022 static bool isDueToday(const KCalendarCore::Todo::Ptr &todo) 0023 { 0024 return !todo->isCompleted() && todo->dtDue().date() == QDate::currentDate(); 0025 } 0026 0027 ColoredTodoProxyModel::ColoredTodoProxyModel(const EventViews::PrefsPtr &preferences, QObject *parent) 0028 : QIdentityProxyModel(parent) 0029 , d(new ColoredTodoProxyModelPrivate(preferences)) 0030 { 0031 } 0032 0033 ColoredTodoProxyModel::~ColoredTodoProxyModel() = default; 0034 0035 QVariant ColoredTodoProxyModel::data(const QModelIndex &index, int role) const 0036 { 0037 if (role == Qt::BackgroundRole) { 0038 const auto todo 0039 = QIdentityProxyModel::data(index, Akonadi::TodoModel::TodoPtrRole).value<KCalendarCore::Todo::Ptr>(); 0040 if (!todo) { 0041 return {}; 0042 } 0043 0044 if (todo->isOverdue()) { 0045 return QVariant(QBrush(d->m_preferences->todoOverdueColor())); 0046 } else if (isDueToday(todo)) { 0047 return QVariant(QBrush(d->m_preferences->todoDueTodayColor())); 0048 } else { 0049 return {}; 0050 } 0051 } 0052 0053 return QIdentityProxyModel::data(index, role); 0054 }