PageRenderTime 141ms CodeModel.GetById 61ms app.highlight 10ms RepoModel.GetById 50ms app.codeStats 0ms

/src/sourcetree/sourcetreeview.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 127 lines | 82 code | 27 blank | 18 comment | 0 complexity | 633bf396895114dfb3524f15688b500a 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 2010-2012, Jeff Mitchell <jeff@tomahawk-player.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 SOURCETREEVIEW_H
 21#define SOURCETREEVIEW_H
 22
 23#include "Typedefs.h"
 24#include "SourcePlaylistInterface.h"
 25
 26#include <QTreeView>
 27#include <QMenu>
 28
 29class SourceTreePopupDialog;
 30class CollectionModel;
 31class PlaylistModel;
 32class SourcesModel;
 33class SourcesProxyModel;
 34class SourceDelegate;
 35
 36namespace Tomahawk
 37{
 38    class LatchManager;
 39}
 40
 41class SourceTreeView : public QTreeView
 42{
 43Q_OBJECT
 44
 45public:
 46    explicit SourceTreeView( QWidget* parent = 0 );
 47    ~SourceTreeView();
 48
 49public slots:
 50    void showOfflineSources( bool offlineSourcesShown );
 51
 52    void renamePlaylist();
 53
 54    void update( const QModelIndex &index );
 55
 56signals:
 57    void onOnline( const QModelIndex& index );
 58    void onOffline( const QModelIndex& index );
 59
 60    void latchRequest( const Tomahawk::source_ptr& source );
 61    void unlatchRequest( const Tomahawk::source_ptr& source );
 62    void catchUpRequest();
 63    void latchModeChangeRequest( const Tomahawk::source_ptr& source, bool realtime );
 64
 65private slots:
 66    void onItemExpanded( const QModelIndex& idx );
 67    void onItemActivated( const QModelIndex& index );
 68    void selectRequest( const QPersistentModelIndex& idx );
 69    void expandRequest( const QPersistentModelIndex& idx );
 70    void toggleExpandRequest( const QPersistentModelIndex& idx );
 71    void onItemDoubleClicked( const QModelIndex& idx );
 72
 73    void loadPlaylist();
 74    void deletePlaylist( const QModelIndex& = QModelIndex() );
 75    void copyPlaylistLink();
 76    void exportPlaylist();
 77    void addToLocal();
 78
 79    void latchOnOrCatchUp();
 80    void latchOff();
 81    void latchOnOrCatchUp( const Tomahawk::source_ptr& source );
 82    void latchOff( const Tomahawk::source_ptr& source );
 83    void latchModeToggled( bool checked );
 84
 85    void onCustomContextMenu( const QPoint& pos );
 86    void onSelectionChanged();
 87
 88    void onDeletePlaylistResult( bool result );
 89
 90protected:
 91    void drawRow( QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const;
 92    void drawBranches( QPainter *painter, const QRect &rect, const QModelIndex &index ) const;
 93
 94    virtual void paintEvent( QPaintEvent* event );
 95
 96    virtual void dragEnterEvent( QDragEnterEvent* event );
 97    virtual void dragLeaveEvent( QDragLeaveEvent* event );
 98    virtual void dragMoveEvent( QDragMoveEvent* event );
 99    virtual void dropEvent( QDropEvent* event );
100    virtual void keyPressEvent( QKeyEvent* event );
101
102private:
103    void setupMenus();
104
105    template< typename T >
106    T* itemFromIndex( const QModelIndex& index ) const;
107
108    SourcesModel* m_model;
109    SourcesProxyModel* m_proxyModel;
110    QModelIndex m_contextMenuIndex;
111    SourceDelegate* m_delegate;
112    Tomahawk::LatchManager* m_latchManager;
113    QWeakPointer<SourceTreePopupDialog> m_popupDialog;
114
115    QMenu m_playlistMenu;
116    QMenu m_roPlaylistMenu;
117    QMenu m_latchMenu;
118    QMenu m_privacyMenu;
119
120    bool m_dragging;
121    QRect m_dropRect;
122    QPersistentModelIndex m_dropIndex;
123
124    QPersistentModelIndex m_selectedIndex;
125};
126
127#endif // SOURCETREEVIEW_H