File indexing completed on 2024-05-05 04:49:28
0001 /**************************************************************************************** 0002 * Copyright (c) 2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * Copyright (c) 2008 Mark Kretschmann <kretschmann@kde.org> * 0004 * Copyright (c) 2009 Seb Ruiz <ruiz@kde.org> * 0005 * Copyright (c) 2013 Ralf Engels <ralf-engels@gmx.de> * 0006 * * 0007 * This program is free software; you can redistribute it and/or modify it under * 0008 * the terms of the GNU General Public License as published by the Free Software * 0009 * Foundation; either version 2 of the License, or (at your option) any later * 0010 * version. * 0011 * * 0012 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0013 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0014 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License along with * 0017 * this program. If not, see <http://www.gnu.org/licenses/>. * 0018 ****************************************************************************************/ 0019 0020 #ifndef AMAROK_PRETTY_TREE_DELEGATE_H 0021 #define AMAROK_PRETTY_TREE_DELEGATE_H 0022 0023 #include <QFont> 0024 #include <QRect> 0025 #include <QStyledItemDelegate> 0026 0027 namespace Amarok { 0028 class PrettyTreeView; 0029 } 0030 class QFontMetrics; 0031 0032 /** A delegate used for the browser. 0033 This delegate has the following specialities: 0034 It will handle the hasCoverRole and will draw a bigger item for the cover. 0035 It will handle the byLineRole and will draw an extra big item with a second 0036 line of text 0037 Also this big item will have an expander arrow if needed and capacities and 0038 actions. 0039 */ 0040 class PrettyTreeDelegate : public QStyledItemDelegate 0041 { 0042 Q_OBJECT 0043 0044 public: 0045 explicit PrettyTreeDelegate( Amarok::PrettyTreeView *view ); 0046 ~PrettyTreeDelegate() override; 0047 0048 void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const override; 0049 QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const override; 0050 0051 /** Returns the rectangle where the action icon with the specific nr is located. */ 0052 QRect decoratorRect( const QRect &itemRect, int nr ) const; 0053 0054 private: 0055 /** Verify and if needed update the buffered fonts and font metrics. */ 0056 void updateFonts( const QStyleOptionViewItem &option ) const; 0057 0058 Amarok::PrettyTreeView *m_view; 0059 0060 mutable QFont m_originalFont; 0061 mutable QFont m_bigFont; 0062 mutable QFont m_smallFont; 0063 0064 mutable QFontMetrics *m_normalFm; 0065 mutable QFontMetrics *m_bigFm; 0066 mutable QFontMetrics *m_smallFm; 0067 }; 0068 0069 #endif