/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. #ifndef PLAYLISTITEMDELEGATE_H
  20. #define PLAYLISTITEMDELEGATE_H
  21. #include <QStyledItemDelegate>
  22. #include <QTextOption>
  23. #include <QTextDocument>
  24. #include "DllMacro.h"
  25. #include "Typedefs.h"
  26. class TrackModel;
  27. class PlayableItem;
  28. class PlayableProxyModel;
  29. class TrackView;
  30. class QComboBox;
  31. namespace Tomahawk {
  32. class PixmapDelegateFader;
  33. }
  34. class DLLEXPORT PlaylistItemDelegate : public QStyledItemDelegate
  35. {
  36. Q_OBJECT
  37. public:
  38. PlaylistItemDelegate( TrackView* parent, PlayableProxyModel* proxy );
  39. void updateRowSize( const QModelIndex& index );
  40. virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  41. public slots:
  42. void resetHoverIndex();
  43. signals:
  44. void updateIndex( const QModelIndex& idx );
  45. private slots:
  46. void doUpdateIndex( const QPersistentModelIndex& index );
  47. protected:
  48. void prepareStyleOption( QStyleOptionViewItem* option, const QModelIndex& index, PlayableItem* item ) const;
  49. void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  50. QWidget* createEditor( QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  51. bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
  52. void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  53. void setModelData( QWidget* editor, QAbstractItemModel* model, const QModelIndex& index ) const;
  54. QPersistentModelIndex hoveringOver() const { return m_hoveringOver; }
  55. QRect drawInfoButton( QPainter* painter, const QRect& rect, const QModelIndex& index, float height ) const;
  56. QRect drawSourceIcon( QPainter* painter, const QRect& rect, PlayableItem* item, float height ) const;
  57. QRect drawCover( QPainter* painter, const QRect& rect, PlayableItem* item, const QModelIndex& index ) const;
  58. QRect drawLoveBox( QPainter* painter,
  59. const QRect& rect,
  60. PlayableItem* item,
  61. const QModelIndex& index ) const;
  62. QRect drawGenericBox( QPainter* painter,
  63. const QStyleOptionViewItem& option,
  64. const QRect& rect,
  65. const QString& text,
  66. const QList< Tomahawk::source_ptr >& sources,
  67. const QModelIndex& index ) const;
  68. void drawRectForBox( QPainter* painter, const QRect& rect ) const;
  69. void drawAvatarsForBox( QPainter* painter,
  70. const QRect& avatarsRect,
  71. int avatarSize,
  72. int avatarMargin,
  73. int count,
  74. const QList< Tomahawk::source_ptr >& sources,
  75. const QModelIndex& index ) const;
  76. void drawRichText( QPainter* painter, const QStyleOptionViewItem& option, const QRect& rect, int flags, QTextDocument& text ) const;
  77. QRect drawSource( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QRect& rect, PlayableItem* item ) const;
  78. QRect drawTrack( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QRect& rect, PlayableItem* item ) const;
  79. void paintDetailed( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  80. QTextOption m_topOption;
  81. QTextOption m_bottomOption;
  82. QTextOption m_centerOption;
  83. QTextOption m_centerRightOption;
  84. QFont m_demiBoldFont;
  85. QFont m_normalFont;
  86. protected slots:
  87. virtual void modelChanged();
  88. virtual void onAudioEngineTick( qint64 ms );
  89. virtual void onPlaybackChange();
  90. private:
  91. mutable QHash< QPersistentModelIndex, QSharedPointer< Tomahawk::PixmapDelegateFader > > m_pixmaps;
  92. mutable QHash< QPersistentModelIndex, QRect > m_infoButtonRects;
  93. mutable QHash< QPersistentModelIndex, QRect > m_loveButtonRects;
  94. mutable QHash< QPersistentModelIndex, QRect > m_downloadDropDownRects;
  95. mutable QHash< QPersistentModelIndex, QRect > m_artistNameRects;
  96. mutable QHash< QPersistentModelIndex, QHash< Tomahawk::source_ptr, QRect > > m_avatarBoxRects;
  97. QPersistentModelIndex m_hoveringOver;
  98. QPersistentModelIndex m_hoveringOverArtist;
  99. QPersistentModelIndex m_hoveringOverDownloadButton;
  100. mutable QPersistentModelIndex m_nowPlaying;
  101. TrackView* m_view;
  102. PlayableProxyModel* m_model;
  103. };
  104. #endif // PLAYLISTITEMDELEGATE_H