/src/sourcetree/items/sourcetreeitem.h

http://github.com/tomahawk-player/tomahawk · C Header · 114 lines · 74 code · 20 blank · 20 comment · 0 complexity · 2ae697066e62bb80528ca2f80b7847b2 MD5 · raw file

  1. /*
  2. Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  14. */
  15. #ifndef SOURCETREEITEM_H
  16. #define SOURCETREEITEM_H
  17. #include "Typedefs.h"
  18. #include "SourcesModel.h"
  19. #include <QIcon>
  20. class QMimeData;
  21. class SourceTreeItem : public QObject
  22. {
  23. Q_OBJECT
  24. public:
  25. enum DropType
  26. {
  27. DropTypesNone = 0x00,
  28. DropTypeThisTrack = 0x01,
  29. DropTypeThisAlbum = 0x02,
  30. DropTypeAllFromArtist = 0x04,
  31. DropTypeLocalItems = 0x08,
  32. DropTypeTop50 = 0x10,
  33. DropTypesAllTypes = 0xff
  34. };
  35. Q_DECLARE_FLAGS( DropTypes, DropType )
  36. SourceTreeItem() : m_type( SourcesModel::Invalid ), m_parent( 0 ), m_model( 0 ) {}
  37. SourceTreeItem( SourcesModel* model, SourceTreeItem* parent, SourcesModel::RowType thisType, int peerSortValue = 0, int index = -1 ); // if index is -1, append at end of parent's child list
  38. virtual ~SourceTreeItem();
  39. // generic info used by the tree model
  40. SourcesModel::RowType type() const;
  41. SourceTreeItem* parent() const;
  42. SourcesModel* model() const;
  43. QList< SourceTreeItem* > children() const;
  44. void appendChild( SourceTreeItem* item );
  45. void insertChild( int index, SourceTreeItem* item );
  46. void removeChild( SourceTreeItem* item );
  47. // varies depending on the type of the item
  48. virtual QString text() const;
  49. virtual QString tooltip() const;
  50. virtual Qt::ItemFlags flags() const;
  51. virtual QIcon icon() const;
  52. virtual bool willAcceptDrag( const QMimeData* ) const;
  53. virtual bool dropMimeData( const QMimeData*, Qt::DropAction );
  54. virtual bool setData( const QVariant&, bool );
  55. virtual int peerSortValue() const; // How to sort relative to peers in the tree.
  56. virtual int IDValue() const;
  57. virtual DropTypes supportedDropTypes( const QMimeData* mimeData ) const;
  58. virtual void setDropType( DropType type );
  59. virtual DropType dropType() const;
  60. virtual bool isBeingPlayed() const;
  61. virtual QList< QAction* > customActions() const;
  62. /// don't call me unless you are a sourcetreeitem. i prefer this to making everyone a friend
  63. void beginRowsAdded( int from, int to );
  64. void endRowsAdded();
  65. void beginRowsRemoved( int from, int to );
  66. void endRowsRemoved();
  67. public slots:
  68. virtual void activate() {}
  69. virtual void doubleClicked() {}
  70. signals:
  71. void updated();
  72. void selectRequest( SourceTreeItem* );
  73. void expandRequest( SourceTreeItem* );
  74. void toggleExpandRequest( SourceTreeItem* );
  75. void beginChildRowsAdded( int fromRow, int toRow );
  76. void childRowsAdded();
  77. void beginChildRowsRemoved( int fromRow, int toRow );
  78. void childRowsRemoved();
  79. protected:
  80. void setRowType( SourcesModel::RowType t );
  81. void setParentItem( SourceTreeItem* item );
  82. private:
  83. SourcesModel::RowType m_type;
  84. SourceTreeItem* m_parent;
  85. QList< SourceTreeItem* > m_children;
  86. SourcesModel* m_model;
  87. int m_peerSortValue;
  88. DropType m_dropType;
  89. };
  90. Q_DECLARE_METATYPE( SourceTreeItem* );
  91. #endif // SOURCETREEITEM_H