File indexing completed on 2024-05-26 05:14:41
0001 /* 0002 SPDX-FileCopyrightText: 2008 Thomas McGuire <thomas.mcguire@gmx.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #pragma once 0007 0008 #include "akonadiwidgets_export.h" 0009 0010 #include <QStyledItemDelegate> 0011 0012 #include <memory> 0013 0014 class QAbstractItemView; 0015 class QTreeView; 0016 0017 namespace Akonadi 0018 { 0019 class CollectionStatisticsDelegatePrivate; 0020 0021 /** 0022 * @short A delegate that draws unread and total count for StatisticsProxyModel. 0023 * 0024 * The delegate provides the following features: 0025 * 0026 * - Collections with unread items will have the foldername and the unread 0027 * column marked in bold. 0028 * - If a folder is collapsed, the unread and the total column will contain 0029 * the total sum of all child folders 0030 * - It has the possibility to draw the unread count directly after the 0031 * foldername, see toggleUnreadAfterFolderName(). 0032 * 0033 * Example: 0034 * @code 0035 * 0036 * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView( this ); 0037 * 0038 * Akonadi::StatisticsProxyModel *statisticsProxy = new Akonadi::StatisticsProxyModel( view ); 0039 * view->setModel( statisticsProxy ); 0040 * 0041 * Akonadi::CollectionStatisticsDelegate *delegate = new Akonadi::CollectionStatisticsDelegate( view ); 0042 * view->setItemDelegate( delegate ); 0043 * 0044 * @endcode 0045 * 0046 * @note This proxy model is intended to be used on top of the EntityTreeModel. One of the proxies 0047 * between the EntityTreeModel (the root model) and the view must be a StatisticsProxyModel. That 0048 * proxy model may appear anywhere in the chain. 0049 * 0050 * @author Thomas McGuire <thomas.mcguire@gmx.net> 0051 */ 0052 class AKONADIWIDGETS_EXPORT CollectionStatisticsDelegate : public QStyledItemDelegate 0053 { 0054 Q_OBJECT 0055 0056 public: 0057 /** 0058 * Creates a new collection statistics delegate. 0059 * 0060 * @param parent The parent item view, which will also take ownership. 0061 * 0062 * @since 4.6 0063 */ 0064 explicit CollectionStatisticsDelegate(QAbstractItemView *parent); 0065 0066 /** 0067 * Creates a new collection statistics delegate. 0068 * 0069 * @param parent The parent tree view, which will also take ownership. 0070 */ 0071 explicit CollectionStatisticsDelegate(QTreeView *parent); 0072 0073 /** 0074 * Destroys the collection statistics delegate. 0075 */ 0076 ~CollectionStatisticsDelegate() override; 0077 0078 /** 0079 * @since 4.9.1 0080 */ 0081 void updatePalette(); 0082 0083 /** 0084 * Sets whether the unread count is drawn next to the folder name. 0085 * 0086 * You probably want to enable this when the unread count is hidden only. 0087 * This is disabled by default. 0088 * 0089 * @param enable If @c true, the unread count is drawn next to the folder name, 0090 * if @c false, the folder name will be drawn normally. 0091 */ 0092 void setUnreadCountShown(bool enable); 0093 0094 /** 0095 * Returns whether the unread count is drawn next to the folder name. 0096 */ 0097 [[nodiscard]] bool unreadCountShown() const; 0098 0099 /** 0100 * @param enable new mode of progress animation 0101 */ 0102 void setProgressAnimationEnabled(bool enable); 0103 0104 [[nodiscard]] bool progressAnimationEnabled() const; 0105 0106 protected: 0107 /** 0108 * @param painter pointer for QPainter to use in method 0109 * @param option style options 0110 * @param index model index (QModelIndex) 0111 */ 0112 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; 0113 0114 /** 0115 * @param option style option view item 0116 * @param index model index (QModelIndex) 0117 */ 0118 void initStyleOption(QStyleOptionViewItem *option, const QModelIndex &index) const override; 0119 0120 private: 0121 /// @cond PRIVATE 0122 std::unique_ptr<CollectionStatisticsDelegatePrivate> const d_ptr; 0123 /// @endcond 0124 0125 Q_DECLARE_PRIVATE(CollectionStatisticsDelegate) 0126 }; 0127 0128 }