1 /**************************************************************************************** 2 * Copyright (c) 2007 Ian Monroe <ian@monroe.nu> * 3 * Copyright (c) 2008 Soren Harward <stharward@gmail.com> * 4 * Copyright (c) 2013 Mark Kretschmann <kretschmann@kde.org> * 5 * * 6 * This program is free software; you can redistribute it and/or modify it under * 7 * the terms of the GNU General Public License as published by the Free Software * 8 * Foundation; either version 2 of the License, or (at your option) version 3 or * 9 * any later version accepted by the membership of KDE e.V. (or its successor approved * 10 * by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of * 11 * version 3 of the license. * 12 * * 13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 14 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 15 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 16 * * 17 * You should have received a copy of the GNU General Public License along with * 18 * this program. If not, see <http://www.gnu.org/licenses/>. * 19 ****************************************************************************************/ 20 21 #ifndef PRETTYITEMDELEGATE_H 22 #define PRETTYITEMDELEGATE_H 23 24 #include "core/meta/forward_declarations.h" 25 #include "playlist/layouts/LayoutItemConfig.h" 26 27 #include <QModelIndex> 28 #include <QStyledItemDelegate> 29 30 class InlineEditorWidget; 31 class QPainter; 32 class QTimeLine; 33 34 namespace Playlist 35 { 36 class PrettyItemDelegate : public QStyledItemDelegate 37 { 38 Q_OBJECT 39 40 public: 41 static int rowsForItem( const QModelIndex &index ); 42 43 explicit PrettyItemDelegate( QObject* parent = nullptr ); 44 ~PrettyItemDelegate() override; 45 46 QSize sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const override; 47 void paint( QPainter*, const QStyleOptionViewItem&, const QModelIndex& ) const override; 48 49 // helper function for view which lets us determine if a click is within an album group's header 50 bool insideItemHeader( const QPoint&, const QRect& ); 51 52 /** Returns the height an item header would have */ 53 int headerHeight() const; 54 55 /** 56 * Handle clicks within a delegate. 57 * @param pos The position of the click, in delegate coordinates. 58 * @param itemRect QRect for the item. 59 * @param index The index of the clicked item. 60 * @return True if delegate acts on this click, false otherwise. 61 */ 62 bool clicked( const QPoint &pos, const QRect &itemRect, const QModelIndex& index ); 63 64 QWidget * createEditor ( QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index ) const override; 65 66 void setModelData ( QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const override; 67 void updateEditorGeometry ( QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index ) const override; 68 69 70 /** 71 * Paint a playlist item based on a LayoutItemConfig 72 * 73 * @param config The LayoutItemConfig that defines how the item should look and which info it should include. 74 * @param painter The QPainter used to paint the item. 75 * @param option Additional state options used to paint the item.. 76 * @param index The model index of the track in the playlist that we are painting. 77 * @param headerRow A boolean value specifying whether we should ignore any "markers" when painting this item. 78 * Markers can be such things as the "now playing" background, queue markers, multi track markers and the likes. 79 * The main reason for wanting to ignore these is that when painting the head part of the first track in the group, these 80 * things should not be shown as they will be hown in the track part of the item. 81 */ 82 void paintItem( const LayoutItemConfig &config, 83 QPainter* painter, 84 const QStyleOptionViewItem& option, 85 const QModelIndex& index, 86 bool headerRow = false ) const; 87 88 89 protected Q_SLOTS: 90 void editorDone( InlineEditorWidget * editor ); 91 92 Q_SIGNALS: 93 void redrawRequested(); 94 95 private Q_SLOTS: 96 void currentDesktopChanged(); 97 98 private: 99 void paintActiveTrackExtras( const QRect &rect, QPainter* painter, const QModelIndex& index ) const; 100 101 QTimeLine * m_animationTimeLine; 102 QPointF centerImage( const QPixmap&, const QRectF& ) const; 103 104 static int getGroupMode( const QModelIndex &index); 105 106 QMap<QString, QString> buildTrackArgsMap( const Meta::TrackPtr &track ) const; 107 108 static QFontMetricsF* s_nfm; //normal 109 static QFontMetricsF* s_ufm; //underline 110 static QFontMetricsF* s_ifm; //italic 111 static QFontMetricsF* s_bfm; //bold 112 113 static int s_fontHeight; 114 }; 115 116 } 117 118 #endif 119 120