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