1 /*****************************************************************************
3 ****************************************************************************
4 * Copyright © 2009-2010 VideoLAN
7 * Authors: Ludovic Fauvet <etix@l0cal.com>
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.
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.
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 *****************************************************************************/
26 #include <QFontMetrics>
29 #include <QFocusEvent>
30 #include <QGraphicsScene>
32 #include "EPGItem.hpp"
33 #include "EPGView.hpp"
34 #include "EPGEvent.hpp"
36 EPGItem::EPGItem( EPGView *view )
41 m_boundingRect.setHeight( TRACKS_HEIGHT );
42 setFlags( QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsFocusable);
45 QRectF EPGItem::boundingRect() const
47 return m_boundingRect;
50 void EPGItem::paint( QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*)
52 // Draw in view's coordinates
53 painter->setWorldMatrixEnabled( false );
55 // Draw high-quality items
56 //painter->setRenderHint( QPainter::Antialiasing );
58 // Get the transformations required to map the text on the viewport
59 QTransform viewPortTransform = m_view->viewportTransform();
60 QRectF mapped = deviceTransform( viewPortTransform ).mapRect( boundingRect() );
62 painter->setPen( QPen( Qt::black ) );
65 painter->setBrush( QBrush( QColor( 100, 100, 100 ) ) );
67 painter->setBrush( QBrush( QColor( 150, 150, 150 ) ) );
69 painter->drawRect( mapped );
75 QFont f = painter->font();
77 // Get the font metrics
78 QFontMetrics fm = painter->fontMetrics();
80 // Adjust the drawing rect
81 mapped.adjust( 6, 6, -6, -6 );
83 painter->setPen( Qt::white );
85 painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft, fm.elidedText( m_name, Qt::ElideRight, mapped.width() ) );
87 mapped.adjust( 0, 20, 0, 0 );
89 QDateTime m_end = m_start.addSecs( m_duration );
92 painter->setFont( f );
95 painter->drawText( mapped, Qt::AlignTop | Qt::AlignLeft,
96 fm.elidedText( m_start.toString( "hh:mm" ) + " - " +
97 m_end.toString( "hh:mm" ),
98 Qt::ElideRight, mapped.width() ) );
101 const QDateTime& EPGItem::start() const
106 int EPGItem::duration() const
111 void EPGItem::setChannel( int channelNb )
113 //qDebug() << "Channel" << channelNb;
114 m_channelNb = channelNb;
115 setPos( pos().x(), m_channelNb * TRACKS_HEIGHT );
118 void EPGItem::setStart( const QDateTime& start )
121 int x = m_view->startTime().secsTo( start );
122 setPos( x, pos().y() );
125 void EPGItem::setDuration( int duration )
127 m_duration = duration;
128 m_boundingRect.setWidth( duration );
131 void EPGItem::setName( const QString& name )
136 void EPGItem::setDescription( const QString& description )
138 m_description = description;
141 void EPGItem::setShortDescription( const QString& shortDescription )
143 m_shortDescription = shortDescription;
146 void EPGItem::setCurrent( bool current )
151 void EPGItem::focusInEvent( QFocusEvent * event )
153 EPGEvent *evEPG = new EPGEvent( m_name );
154 evEPG->description = m_description;
155 evEPG->shortDescription = m_shortDescription;
156 evEPG->start = m_start;
157 evEPG->duration = m_duration;
158 m_view->eventFocused( evEPG );