]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/playlist/vlc_model.cpp
Qt: PLModel: move zoom value out of model
[vlc] / modules / gui / qt4 / components / playlist / vlc_model.cpp
1 /*****************************************************************************
2  * vlc_model.cpp : base for playlist and ml model
3  ****************************************************************************
4  * Copyright (C) 2010 the VideoLAN team and AUTHORS
5  * $Id$
6  *
7  * Authors: Srikanth Raju <srikiraju#gmail#com>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include "vlc_model.hpp"
25
26 VLCModel::VLCModel( intf_thread_t *_p_intf, QObject *parent )
27         : QAbstractItemModel( parent ), p_intf(_p_intf)
28 {
29 }
30
31 VLCModel::~VLCModel()
32 {
33 }
34
35 QString VLCModel::getMeta( const QModelIndex & index, int meta )
36 {
37     return index.model()->index( index.row(), columnFromMeta( meta ), index.parent() ).
38         data().toString();
39 }
40
41 QString VLCModel::getArtUrl( const QModelIndex & index )
42 {
43     return index.model()->index( index.row(),
44                     columnFromMeta( COLUMN_COVER ),
45                     index.parent() )
46            .data().toString();
47 }
48
49 QPixmap VLCModel::getArtPixmap( const QModelIndex & index, const QSize & size )
50 {
51     QString artUrl = VLCModel::getArtUrl( index ) ;
52
53     QPixmap artPix;
54
55     QString key = artUrl + QString("%1%2").arg(size.width()).arg(size.height());
56
57     if( !QPixmapCache::find( key, artPix ))
58     {
59         if( artUrl.isEmpty() || !artPix.load( artUrl ) )
60         {
61             key = QString("noart%1%2").arg(size.width()).arg(size.height());
62             if( !QPixmapCache::find( key, artPix ) )
63             {
64                 artPix = QPixmap( ":/noart" ).scaled( size,
65                                                       Qt::KeepAspectRatio,
66                                                       Qt::SmoothTransformation );
67                 QPixmapCache::insert( key, artPix );
68             }
69         }
70         else
71         {
72             artPix = artPix.scaled( size, Qt::KeepAspectRatio, Qt::SmoothTransformation );
73             QPixmapCache::insert( key, artPix );
74         }
75     }
76
77     return artPix;
78 }