PageRenderTime 203ms CodeModel.GetById 91ms app.highlight 13ms RepoModel.GetById 97ms app.codeStats 0ms

/src/libtomahawk/playlist/TrackView.h

http://github.com/tomahawk-player/tomahawk
C Header | 171 lines | 112 code | 40 blank | 19 comment | 0 complexity | 1b4d43065259bfbba852c65bb4d54a1e MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  3 *   Copyright 2010-2014, Christian Muehlhaeuser <muesli@tomahawk-player.org>
  4 *   Copyright 2010-2011, 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 TRACKVIEW_H
 21#define TRACKVIEW_H
 22
 23#include "ContextMenu.h"
 24#include "PlaylistItemDelegate.h"
 25#include "ViewPage.h"
 26
 27#include "DllMacro.h"
 28
 29#include <QTreeView>
 30#include <QSortFilterProxyModel>
 31#include <QTimer>
 32
 33class QAction;
 34class AnimatedSpinner;
 35class ViewHeader;
 36class PlayableModel;
 37class PlayableProxyModel;
 38class OverlayWidget;
 39
 40class DLLEXPORT TrackView : public QTreeView, public Tomahawk::ViewPage
 41{
 42Q_OBJECT
 43
 44public:
 45    explicit TrackView( QWidget* parent = 0 );
 46    ~TrackView();
 47
 48    virtual QString guid() const;
 49    virtual void setGuid( const QString& newguid );
 50
 51    virtual void setPlaylistItemDelegate( PlaylistItemDelegate* delegate );
 52    virtual void setPlayableModel( PlayableModel* model );
 53    virtual void setModel( QAbstractItemModel* model );
 54    void setProxyModel( PlayableProxyModel* model );
 55
 56    virtual PlayableModel* model() const;
 57    PlayableProxyModel* proxyModel() const { return m_proxyModel; }
 58    PlaylistItemDelegate* delegate() const { return m_delegate; }
 59    ViewHeader* header() const { return m_header; }
 60    OverlayWidget* overlay() const { return m_overlay; }
 61    Tomahawk::ContextMenu* contextMenu() const { return m_contextMenu; }
 62    AnimatedSpinner* loadingSpinner() const { return m_loadingSpinner; }
 63
 64    void setEmptyTip( const QString& tip );
 65
 66    virtual QWidget* widget() { return this; }
 67    virtual Tomahawk::playlistinterface_ptr playlistInterface() const;
 68    void setPlaylistInterface( const Tomahawk::playlistinterface_ptr& playlistInterface );
 69
 70    virtual QString title() const;
 71    virtual QString description() const;
 72    virtual QPixmap pixmap() const;
 73
 74    virtual bool setFilter( const QString& filter );
 75    virtual bool jumpToCurrentTrack();
 76
 77    QModelIndex contextMenuIndex() const { return m_contextMenuIndex; }
 78    void setContextMenuIndex( const QModelIndex& idx ) { m_contextMenuIndex = idx; }
 79
 80    bool autoResize() const { return m_autoResize; }
 81    void setAutoResize( bool b );
 82
 83    void setAlternatingRowColors( bool enable );
 84    void setAutoExpanding( bool enable );
 85
 86    // Starts playing from the beginning if resolved, or waits until a track is playable
 87    void startPlayingFromStart();
 88
 89public slots:
 90    virtual void onItemActivated( const QModelIndex& index );
 91
 92    virtual void downloadSelectedItems();
 93    virtual void deleteSelectedItems();
 94
 95    void playItem();
 96    virtual void onMenuTriggered( int action );
 97
 98    void expand( const QPersistentModelIndex& idx );
 99    void select( const QPersistentModelIndex& idx );
100    void selectFirstTrack();
101
102signals:
103    void itemActivated( const QModelIndex& index );
104    void querySelected( const Tomahawk::query_ptr& query );
105    void modelChanged();
106
107protected:
108    virtual void resizeEvent( QResizeEvent* event );
109    virtual bool eventFilter( QObject* obj, QEvent* event );
110
111    virtual void startDrag( Qt::DropActions supportedActions );
112    virtual void dragEnterEvent( QDragEnterEvent* event );
113    virtual void dragLeaveEvent( QDragLeaveEvent* event );
114    virtual void dragMoveEvent( QDragMoveEvent* event );
115    virtual void dropEvent( QDropEvent* event );
116
117    virtual void leaveEvent( QEvent* event );
118    virtual void paintEvent( QPaintEvent* event );
119    virtual void keyPressEvent( QKeyEvent* event );
120    virtual void wheelEvent( QWheelEvent* event );
121
122protected slots:
123    virtual void currentChanged( const QModelIndex& current, const QModelIndex& previous );
124
125    void onViewChanged();
126    void onScrollTimeout();
127
128private slots:
129    void onItemResized( const QModelIndex& index );
130    void onFilterChanged( const QString& filter );
131    void onModelFilling();
132    void onModelEmptyCheck();
133    void onCurrentIndexChanged( const QModelIndex& newIndex, const QModelIndex& oldIndex );
134
135    void onCustomContextMenu( const QPoint& pos );
136
137    void autoPlayResolveFinished( const Tomahawk::query_ptr& query, int row );
138
139    void verifySize();
140
141private:
142    void startAutoPlay( const QModelIndex& index );
143    bool tryToPlayItem( const QModelIndex& index );
144    void updateHoverIndex( const QPoint& pos );
145
146    QString m_guid;
147    QPointer<PlayableModel> m_model;
148    PlayableProxyModel* m_proxyModel;
149    PlaylistItemDelegate* m_delegate;
150    ViewHeader* m_header;
151    OverlayWidget* m_overlay;
152    AnimatedSpinner* m_loadingSpinner;
153
154    QString m_emptyTip;
155    bool m_resizing;
156    bool m_dragging;
157    QRect m_dropRect;
158
159    bool m_autoResize;
160    bool m_alternatingRowColors;
161    bool m_autoExpanding;
162
163    QModelIndex m_contextMenuIndex;
164
165    Tomahawk::query_ptr m_autoPlaying;
166    Tomahawk::ContextMenu* m_contextMenu;
167
168    QTimer m_timer;
169};
170
171#endif // TRACKVIEW_H