File indexing completed on 2024-11-24 04:50:43

0001 // SPDX-FileCopyrightText: 2022 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-FileCopyrightText: 2022 Claudio Cambra <claudio.cambra@gmail.com>
0003 // SPDX-License-Identifier: GPL-2.0-or-later
0004 
0005 #pragma once
0006 
0007 #include <Akonadi/EntityTreeModel>
0008 #include <QColor>
0009 #include <QSortFilterProxyModel>
0010 
0011 /// Despite the name, this handles the presentation of collections including display text and icons, not just colors.
0012 class ColorProxyModel : public QSortFilterProxyModel
0013 {
0014     Q_OBJECT
0015 
0016 public:
0017     enum Roles {
0018         isResource = Akonadi::EntityTreeModel::UserRole + 1,
0019     };
0020     Q_ENUM(Roles)
0021 
0022     explicit ColorProxyModel(QObject *parent = nullptr);
0023     QVariant data(const QModelIndex &index, int role) const override;
0024     Qt::ItemFlags flags(const QModelIndex &index) const override;
0025     QHash<int, QByteArray> roleNames() const override;
0026     QColor getCollectionColor(Akonadi::Collection collection) const;
0027     QColor color(Akonadi::Collection::Id collectionId) const;
0028     void setColor(Akonadi::Collection::Id collectionId, const QColor &color);
0029 
0030     void setStandardCollectionId(Akonadi::Collection::Id standardCollectionId);
0031 
0032 private:
0033     mutable QHash<Akonadi::Collection::Id, QColor> colorCache;
0034     Akonadi::Collection::Id m_standardCollectionId = -1;
0035 };