1 /****************************************************************************************
2  * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org>                                *
3  * Copyright (c) 2008 Mark Kretschmann <kretschmann@kde.org>                            *
4  * Copyright (c) 2009 Seb Ruiz <ruiz@kde.org>                                           *
5  * Copyright (c) 2013 Ralf Engels <ralf-engels@gmx.de>                                  *
6  *                                                                                      *
7  * This program is free software; you can redistribute it and/or modify it under        *
8  * the terms of the GNU General Public License as published by the Free Software        *
9  * Foundation; either version 2 of the License, or (at your option) any later           *
10  * version.                                                                             *
11  *                                                                                      *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
14  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
15  *                                                                                      *
16  * You should have received a copy of the GNU General Public License along with         *
17  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
18  ****************************************************************************************/
19 
20 #ifndef AMAROK_PRETTY_TREE_DELEGATE_H
21 #define AMAROK_PRETTY_TREE_DELEGATE_H
22 
23 #include <QFont>
24 #include <QRect>
25 #include <QStyledItemDelegate>
26 
27 namespace Amarok {
28     class PrettyTreeView;
29 }
30 class QFontMetrics;
31 
32 /** A delegate used for the browser.
33     This delegate has the following specialities:
34      It will handle the hasCoverRole and will draw a bigger item for the cover.
35      It will handle the byLineRole and will draw an extra big item with a second
36       line of text
37      Also this big item will have an expander arrow if needed and capacities and
38      actions.
39 */
40 class PrettyTreeDelegate : public QStyledItemDelegate
41 {
42     Q_OBJECT
43 
44     public:
45         explicit PrettyTreeDelegate( Amarok::PrettyTreeView *view );
46         ~PrettyTreeDelegate() override;
47 
48         void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
49         QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override;
50 
51         /** Returns the rectangle where the action icon with the specific nr is located. */
52         QRect decoratorRect( const QRect &itemRect, int nr ) const;
53 
54     private:
55         /** Verify and if needed update the buffered fonts and font metrics. */
56         void updateFonts( const QStyleOptionViewItem &option ) const;
57 
58         Amarok::PrettyTreeView *m_view;
59 
60         mutable QFont m_originalFont;
61         mutable QFont m_bigFont;
62         mutable QFont m_smallFont;
63 
64         mutable QFontMetrics *m_normalFm;
65         mutable QFontMetrics *m_bigFm;
66         mutable QFontMetrics *m_smallFm;
67 };
68 
69 #endif
70