PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 31ms app.codeStats 0ms

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