PageRenderTime 640ms CodeModel.GetById 121ms app.highlight 14ms RepoModel.GetById 157ms app.codeStats 316ms

/src/libtomahawk/playlist/PlaylistItemDelegate.h

http://github.com/tomahawk-player/tomahawk
C Header | 129 lines | 86 code | 25 blank | 18 comment | 0 complexity | 2731a99f36039230e72d27d63b3bee45 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2015, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2013,      Teo Mrnjavac <teo@kde.org>
  5 *
  6 *   Tomahawk is free software: you can redistribute it and/or modify
  7 *   it under the terms of the GNU General Public License as published by
  8 *   the Free Software Foundation, either version 3 of the License, or
  9 *   (at your option) any later version.
 10 *
 11 *   Tomahawk is distributed in the hope that it will be useful,
 12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14 *   GNU General Public License for more details.
 15 *
 16 *   You should have received a copy of the GNU General Public License
 17 *   along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
 18 */
 19
 20#ifndef PLAYLISTITEMDELEGATE_H
 21#define PLAYLISTITEMDELEGATE_H
 22
 23#include <QStyledItemDelegate>
 24#include <QTextOption>
 25#include <QTextDocument>
 26
 27#include "DllMacro.h"
 28#include "Typedefs.h"
 29
 30class TrackModel;
 31class PlayableItem;
 32class PlayableProxyModel;
 33class TrackView;
 34
 35class QComboBox;
 36
 37namespace Tomahawk {
 38    class PixmapDelegateFader;
 39}
 40
 41class DLLEXPORT PlaylistItemDelegate : public QStyledItemDelegate
 42{
 43Q_OBJECT
 44
 45public:
 46    PlaylistItemDelegate( TrackView* parent, PlayableProxyModel* proxy );
 47
 48    void updateRowSize( const QModelIndex& index );
 49
 50    virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
 51
 52public slots:
 53    void resetHoverIndex();
 54
 55signals:
 56    void updateIndex( const QModelIndex& idx );
 57
 58private slots:
 59    void doUpdateIndex( const QPersistentModelIndex& index );
 60
 61protected:
 62    void prepareStyleOption( QStyleOptionViewItem* option, const QModelIndex& index, PlayableItem* item ) const;
 63
 64    void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
 65    QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
 66    bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
 67    void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
 68    void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const;
 69
 70    QPersistentModelIndex hoveringOver() const { return m_hoveringOver; }
 71
 72    QRect drawInfoButton( QPainter* painter, const QRect& rect, const QModelIndex& index, float height ) const;
 73    QRect drawSourceIcon( QPainter* painter, const QRect& rect, PlayableItem* item, float height ) const;
 74    QRect drawCover( QPainter* painter, const QRect& rect, PlayableItem* item, const QModelIndex& index ) const;
 75    QRect drawLoveBox( QPainter* painter,
 76                       const QRect& rect,
 77                       PlayableItem* item,
 78                       const QModelIndex& index ) const;
 79    QRect drawGenericBox( QPainter* painter,
 80                          const QStyleOptionViewItem& option,
 81                          const QRect& rect,
 82                          const QString& text,
 83                          const QList< Tomahawk::source_ptr >& sources,
 84                          const QModelIndex& index ) const;
 85    void drawRectForBox( QPainter* painter, const QRect& rect ) const;
 86    void drawAvatarsForBox( QPainter* painter,
 87                            const QRect& avatarsRect,
 88                            int avatarSize,
 89                            int avatarMargin,
 90                            int count,
 91                            const QList< Tomahawk::source_ptr >& sources,
 92                            const QModelIndex& index ) const;
 93    void drawRichText( QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, int flags, QTextDocument& text ) const;
 94
 95    QRect drawSource( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QRect& rect, PlayableItem* item ) const;
 96    QRect drawTrack( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QRect& rect, PlayableItem* item ) const;
 97
 98    void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
 99
100    QTextOption m_topOption;
101    QTextOption m_bottomOption;
102    QTextOption m_centerOption;
103    QTextOption m_centerRightOption;
104
105    QFont m_demiBoldFont;
106    QFont m_normalFont;
107
108protected slots:
109    virtual void modelChanged();
110    virtual void onAudioEngineTick( qint64 ms );
111    virtual void onPlaybackChange();
112
113private:
114    mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
115    mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
116    mutable QHash< QPersistentModelIndex, QRect > m_loveButtonRects;
117    mutable QHash< QPersistentModelIndex, QRect > m_downloadDropDownRects;
118    mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects;
119    mutable QHash< QPersistentModelIndex, QHash< Tomahawk::source_ptr, QRect > > m_avatarBoxRects;
120    QPersistentModelIndex m_hoveringOver;
121    QPersistentModelIndex m_hoveringOverArtist;
122    QPersistentModelIndex m_hoveringOverDownloadButton;
123    mutable QPersistentModelIndex m_nowPlaying;
124
125    TrackView* m_view;
126    PlayableProxyModel* m_model;
127};
128
129#endif // PLAYLISTITEMDELEGATE_H