/src/libtomahawk/playlist/collectionview.cpp

http://github.com/tomahawk-player/tomahawk · C++ · 97 lines · 58 code · 22 blank · 17 comment · 2 complexity · 7fc470255e2e090ddffb0eb7eecb638f 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. *
  5. * Tomahawk is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * Tomahawk is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "collectionview.h"
  19. #include <QDragEnterEvent>
  20. #include <QPainter>
  21. #include "collectionproxymodel.h"
  22. #include "trackmodel.h"
  23. #include "widgets/overlaywidget.h"
  24. #include "utils/logger.h"
  25. using namespace Tomahawk;
  26. CollectionView::CollectionView( QWidget* parent )
  27. : TrackView( parent )
  28. {
  29. setProxyModel( new CollectionProxyModel( this ) );
  30. setDragDropMode( QAbstractItemView::DragOnly );
  31. }
  32. CollectionView::~CollectionView()
  33. {
  34. qDebug() << Q_FUNC_INFO;
  35. }
  36. void
  37. CollectionView::setModel( QAbstractItemModel* model )
  38. {
  39. Q_UNUSED( model );
  40. qDebug() << "Explicitly use setTrackModel instead";
  41. Q_ASSERT( false );
  42. }
  43. void
  44. CollectionView::setTrackModel( TrackModel* model )
  45. {
  46. TrackView::setTrackModel( model );
  47. setColumnHidden( TrackModel::Score, true ); // Hide score column per default
  48. setColumnHidden( TrackModel::Origin, true ); // Hide origin column per default
  49. setColumnHidden( TrackModel::Composer, true ); //Hide composer column per default
  50. setGuid( QString( "collectionview/%1" ).arg( model->columnCount() ) );
  51. sortByColumn( TrackModel::Artist, Qt::AscendingOrder );
  52. connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
  53. }
  54. void
  55. CollectionView::dragEnterEvent( QDragEnterEvent* event )
  56. {
  57. event->ignore();
  58. }
  59. void
  60. CollectionView::onTrackCountChanged( unsigned int tracks )
  61. {
  62. if ( tracks == 0 )
  63. {
  64. overlay()->setText( tr( "This collection is empty." ) );
  65. overlay()->show();
  66. }
  67. else
  68. overlay()->hide();
  69. }
  70. bool
  71. CollectionView::jumpToCurrentTrack()
  72. {
  73. scrollTo( proxyModel()->currentIndex(), QAbstractItemView::PositionAtCenter );
  74. return true;
  75. }