1/*
2 Copyright (c) 2008 Thomas McGuire <thomas.mcguire@gmx.net>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19#ifndef AKONADI_COLLECTIONSTATISTICSDELEGATE_H
20#define AKONADI_COLLECTIONSTATISTICSDELEGATE_H
21
22#include "akonadi_export.h"
23
24#include <QStyledItemDelegate>
25
26class QAbstractItemView;
27class QTreeView;
28
29namespace Akonadi {
30
31class CollectionStatisticsDelegatePrivate;
32
33/**
34 * @short A delegate that draws unread and total count for CollectionStatisticsModel.
35 *
36 * The delegate provides the following features:
37 *
38 * - Collections with unread items will have the foldername and the unread
39 * column marked in bold.
40 * - If a folder is collapsed, the unread and the total column will contain
41 * the total sum of all child folders
42 * - It has the possibility to draw the unread count directly after the
43 * foldername, see toggleUnreadAfterFolderName().
44 *
45 * Example:
46 * @code
47 *
48 * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView( this );
49 *
50 * Akonadi::StatisticsProxyModel *statisticsProxy = new Akonadi::StatisticsProxyModel( view );
51 * view->setModel( statisticsProxy );
52 *
53 * Akonadi::CollectionStatisticsDelegate *delegate = new Akonadi::CollectionStatisticsDelegate( view );
54 * view->setItemDelegate( delegate );
55 *
56 * @endcode
57 *
58 * @note This proxy model is intended to be used on top of the EntityTreeModel. One of the proxies
59 * between the EntityTreeModel (the root model) and the view must be a StatisticsProxyModel. That
60 * proxy model may appear anywhere in the chain.
61 *
62 * @author Thomas McGuire <thomas.mcguire@gmx.net>
63 */
64class AKONADI_EXPORT CollectionStatisticsDelegate : public QStyledItemDelegate
65{
66 Q_OBJECT
67
68public:
69
70 /**
71 * Creates a new collection statistics delegate.
72 *
73 * @param parent The parent item view, which will also take ownership.
74 *
75 * @since 4.6
76 */
77 explicit CollectionStatisticsDelegate(QAbstractItemView *parent);
78
79 /**
80 * Creates a new collection statistics delegate.
81 *
82 * @param parent The parent tree view, which will also take ownership.
83 */
84 explicit CollectionStatisticsDelegate(QTreeView *parent);
85
86 /**
87 * Destroys the collection statistics delegate.
88 */
89 ~CollectionStatisticsDelegate();
90
91 /**
92 * @since 4.9.1
93 */
94 void updatePalette();
95
96public Q_SLOTS:
97 /**
98 * Sets whether the unread count is drawn next to the folder name.
99 *
100 * You probably want to enable this when the unread count is hidden only.
101 * This is disabled by default.
102 *
103 * @param enable If @c true, the unread count is drawn next to the folder name,
104 * if @c false, the folder name will be drawn normally.
105 */
106 void setUnreadCountShown(bool enable);
107
108 /**
109 * Returns whether the unread count is drawn next to the folder name.
110 */
111 bool unreadCountShown() const;
112
113 /**
114 * @param enable new mode of progress animation
115 */
116 void setProgressAnimationEnabled(bool enable);
117
118 bool progressAnimationEnabled() const;
119
120protected:
121 /**
122 * @param painter pointer for QPainter to use in method
123 * @param option style options
124 * @param index model index (QModelIndex)
125 */
126 virtual void paint(QPainter *painter, const QStyleOptionViewItem &option,
127 const QModelIndex &index) const;
128
129 /**
130 * @param option style option view item
131 * @param index model index (QModelIndex)
132 */
133 virtual void initStyleOption(QStyleOptionViewItem *option,
134 const QModelIndex &index) const;
135
136private:
137 //@cond PRIVATE
138 CollectionStatisticsDelegatePrivate *const d_ptr;
139 //@endcond
140
141 Q_DECLARE_PRIVATE(CollectionStatisticsDelegate)
142};
143
144}
145
146#endif
147