]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/epg/EPGItem.cpp
Initial commit for EPG class for EPG Viewing
[vlc] / modules / gui / qt4 / components / epg / EPGItem.cpp
1 /*****************************************************************************
2  * EPGItem.cpp: EPGItem
3  ****************************************************************************
4  * Copyright © 2009-2010 VideoLAN
5  * $Id$
6  *
7  * Authors: Ludovic Fauvet <etix@l0cal.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 Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #include <QTransform>
25 #include <QFont>
26 #include <QFontMetrics>
27 #include <QDebug>
28
29 #include "EPGItem.hpp"
30 #include "EPGView.hpp"
31
32 EPGItem::EPGItem( EPGView *view )
33     : m_view( view )
34 {
35     m_current = false;
36
37     m_boundingRect.setHeight( TRACKS_HEIGHT );
38 }
39
40 QRectF EPGItem::boundingRect() const
41 {
42     return m_boundingRect;
43 }
44
45 void EPGItem::paint( QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
46 {
47     // Draw in view's coordinates
48     painter->setWorldMatrixEnabled( false );
49
50     // Draw high-quality items
51     //painter->setRenderHint( QPainter::Antialiasing );
52
53     // Get the transformations required to map the text on the viewport
54     QTransform viewPortTransform = m_view->viewportTransform();
55     QRectF mapped = deviceTransform( viewPortTransform ).mapRect( boundingRect() );
56
57     painter->setPen( QPen( Qt::black ) );
58     painter->setBrush( QBrush( Qt::blue ) );
59
60     painter->drawRect( mapped );
61
62
63     /* Draw text */
64
65     // Setup the font
66     QFont f = painter->font();
67     f.setPointSize( 9 );
68     f.setBold( true );
69     painter->setFont( f );
70
71     // Get the font metrics
72     QFontMetrics fm = painter->fontMetrics();
73
74     // Adjust the drawing rect
75     mapped.adjust( 2, 2, -2, -2 );
76
77     painter->setPen( Qt::white );
78     painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft, fm.elidedText( m_name, Qt::ElideRight, mapped.width() ) );
79
80
81     f.setBold( false );
82     f.setItalic( true );
83     f.setPointSize( 8 );
84     painter->setFont( f );
85
86     QTextOption textoption;
87     textoption.setWrapMode( QTextOption::WordWrap );
88     textoption.setAlignment( Qt::AlignTop | Qt::AlignLeft );
89
90     painter->drawText( mapped.adjusted( 0, 20, 0, 0 ),
91                        m_shortDescription,
92                        textoption );
93 }
94
95 const QDateTime& EPGItem::start() const
96 {
97     return m_start;
98 }
99
100 int EPGItem::duration() const
101 {
102     return m_duration;
103 }
104
105 void EPGItem::setChannel( int channelNb )
106 {
107     qDebug() << "Channel" << channelNb;
108     m_channelNb = channelNb;
109     setPos( pos().x(), m_channelNb * TRACKS_HEIGHT );
110 }
111
112 void EPGItem::setStart( const QDateTime& start )
113 {
114     m_start = start;
115     int x = m_view->startTime().secsTo( start );
116     setPos( x, pos().y() );
117 }
118
119 void EPGItem::setDuration( int duration )
120 {
121     m_duration = duration;
122     m_boundingRect.setWidth( duration );
123 }
124
125 void EPGItem::setName( const QString& name )
126 {
127     m_name = name;
128 }
129
130 void EPGItem::setDescription( const QString& description )
131 {
132     m_description = description;
133 }
134
135 void EPGItem::setShortDescription( const QString& shortDescription )
136 {
137     m_shortDescription = shortDescription;
138 }
139
140 void EPGItem::setCurrent( bool current )
141 {
142     m_current = current;
143 }