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