PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 8ms RepoModel.GetById 33ms app.codeStats 0ms

/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
19#include "collectionview.h"
20
21#include <QDragEnterEvent>
22#include <QPainter>
23
24#include "collectionproxymodel.h"
25#include "trackmodel.h"
26#include "widgets/overlaywidget.h"
27#include "utils/logger.h"
28
29using namespace Tomahawk;
30
31
32CollectionView::CollectionView( QWidget* parent )
33    : TrackView( parent )
34{
35    setProxyModel( new CollectionProxyModel( this ) );
36
37    setDragDropMode( QAbstractItemView::DragOnly );
38}
39
40
41CollectionView::~CollectionView()
42{
43    qDebug() << Q_FUNC_INFO;
44}
45
46
47void
48CollectionView::setModel( QAbstractItemModel* model )
49{
50    Q_UNUSED( model );
51    qDebug() << "Explicitly use setTrackModel instead";
52    Q_ASSERT( false );
53}
54
55
56void
57CollectionView::setTrackModel( TrackModel* model )
58{
59    TrackView::setTrackModel( model );
60
61    setColumnHidden( TrackModel::Score, true ); // Hide score column per default
62    setColumnHidden( TrackModel::Origin, true ); // Hide origin column per default
63    setColumnHidden( TrackModel::Composer, true ); //Hide composer column per default
64
65    setGuid( QString( "collectionview/%1" ).arg( model->columnCount() ) );
66    sortByColumn( TrackModel::Artist, Qt::AscendingOrder );
67
68    connect( model, SIGNAL( trackCountChanged( unsigned int ) ), SLOT( onTrackCountChanged( unsigned int ) ) );
69}
70
71
72void
73CollectionView::dragEnterEvent( QDragEnterEvent* event )
74{
75    event->ignore();
76}
77
78
79void
80CollectionView::onTrackCountChanged( unsigned int tracks )
81{
82    if ( tracks == 0 )
83    {
84        overlay()->setText( tr( "This collection is empty." ) );
85        overlay()->show();
86    }
87    else
88        overlay()->hide();
89}
90
91
92bool
93CollectionView::jumpToCurrentTrack()
94{
95    scrollTo( proxyModel()->currentIndex(), QAbstractItemView::PositionAtCenter );
96    return true;
97}