/src/sourcetree/sourcedelegate.h

http://github.com/tomahawk-player/tomahawk · C Header · 88 lines · 53 code · 15 blank · 20 comment · 0 complexity · a6568b2add5094b404add25effd34ca9 MD5 · raw file

  1. /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2. *
  3. * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4. * Copyright 2011, Leo Franchi <lfranchi@kde.org>
  5. * Copyright 2011, Michael Zanetti <mzanetti@kde.org>
  6. * Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
  7. *
  8. * Tomahawk is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Tomahawk is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #ifndef SOURCEDELEGATE_H
  22. #define SOURCEDELEGATE_H
  23. #include "SourceTreeView.h"
  24. #include "items/SourceTreeItem.h"
  25. #include <QStyledItemDelegate>
  26. #include <QPropertyAnimation>
  27. class AnimationHelper;
  28. class SourceDelegate : public QStyledItemDelegate
  29. {
  30. Q_OBJECT
  31. public:
  32. SourceDelegate( QAbstractItemView* parent = 0 );
  33. ~SourceDelegate();
  34. void hovered( const QModelIndex &index, const QMimeData *mimeData );
  35. void dragLeaveEvent();
  36. SourceTreeItem::DropType hoveredDropType() const;
  37. signals:
  38. void clicked( const QModelIndex& idx );
  39. void doubleClicked( const QModelIndex& idx );
  40. void latchOn( const Tomahawk::source_ptr& idx );
  41. void latchOff( const Tomahawk::source_ptr& idx );
  42. void toggleRealtimeLatch( const Tomahawk::source_ptr& idx, bool realtime );
  43. protected:
  44. virtual QSize sizeHint( const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  45. virtual void paint( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  46. virtual void updateEditorGeometry( QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  47. virtual int dropTypeCount( SourceTreeItem* item ) const;
  48. virtual bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option, const QModelIndex& index );
  49. private slots:
  50. void animationFinished( const QModelIndex& );
  51. private:
  52. void paintDecorations( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  53. void paintCollection( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  54. void paintCategory( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  55. void paintGroup( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
  56. QAbstractItemView* m_parent;
  57. mutable int m_iconHeight;
  58. QModelIndex m_dropHoverIndex;
  59. QModelIndex m_newDropHoverIndex;
  60. QMimeData *m_dropMimeData;
  61. mutable SourceTreeItem::DropType m_hoveredDropType; // Hack to keep easily track of the current highlighted DropType in paint()
  62. QMap< QModelIndex, AnimationHelper* > m_expandedMap;
  63. QPixmap m_headphonesOn, m_headphonesOff, m_realtimeLocked, m_realtimeUnlocked, m_nowPlayingSpeaker, m_nowPlayingSpeakerDark, m_collaborativeOn;
  64. qint64 m_lastClicked;
  65. QMap< int, SourceTreeItem::DropType > m_dropTypeMap;
  66. QMap< int, QString > m_dropTypeTextMap;
  67. QMap< int, QPixmap > m_dropTypeImageMap;
  68. mutable QHash< QPersistentModelIndex, QRect > m_trackRects;
  69. mutable QHash< QPersistentModelIndex, QRect > m_headphoneRects;
  70. mutable QHash< QPersistentModelIndex, QRect > m_lockRects;
  71. mutable QLinearGradient m_gradient;
  72. };
  73. #endif // SOURCEDELEGATE_H