]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/epg/EPGChannels.cpp
Qt: remove the bottom line of the channel list widget.
[vlc] / modules / gui / qt4 / components / epg / EPGChannels.cpp
1 /*****************************************************************************
2  * EPGChannels.cpp: EPGChannels
3  ****************************************************************************
4  * Copyright © 2009-2010 VideoLAN
5  *
6  * Authors: Adrien Maglo <magsoft@videolan.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21  *****************************************************************************/
22
23 #include "EPGChannels.hpp"
24 #include "EPGView.hpp"
25
26 #include <QPainter>
27 #include <QFont>
28 #include <QPaintEvent>
29
30 EPGChannels::EPGChannels( QWidget *parent, EPGView *m_epgView )
31     : QWidget( parent ), m_epgView( m_epgView ), m_offset( 0 )
32 {
33     setContentsMargins( 0, 0, 0, 0 );
34 }
35
36 void EPGChannels::setOffset( int offset )
37 {
38     m_offset = offset;
39     update();
40 }
41
42 void EPGChannels::paintEvent( QPaintEvent *event )
43 {
44     Q_UNUSED( event );
45
46     QPainter p( this );
47
48     /* Draw the top and the bottom lines. */
49     p.drawLine( 0, 0, width() - 1, 0 );
50
51     p.setFont( QFont( "Verdana", 8 ) );
52
53     QList<QString> channels = m_epgView->getChannelList();
54
55     for( int i = 0; i < channels.count(); ++i )
56     {
57         p.drawText( 0, - m_offset + ( i + 0.5 ) * TRACKS_HEIGHT - 4,
58                     width(), 20, Qt::AlignLeft, channels[i] );
59
60         int i_width = fontMetrics().width( channels[i] );
61         if( width() < i_width )
62             setMinimumWidth( i_width );
63     }
64 }