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 *****************************************************************************/
24 #include "EPGView.hpp"
25 #include "EPGItem.hpp"
31 EPGView::EPGView( QWidget *parent ) : QGraphicsView( parent )
33 setContentsMargins( 0, 0, 0, 0 );
34 setFrameStyle( QFrame::NoFrame );
35 setAlignment( Qt::AlignLeft | Qt::AlignTop );
37 m_startTime = QDateTime::currentDateTime();
40 setSceneRect( 0, 0, 20000, 200 );
42 QGraphicsScene *EPGscene = new QGraphicsScene( this );
47 void EPGView::setScale( double scaleFactor )
49 m_scaleFactor = scaleFactor;
51 matrix.scale( scaleFactor, 1 );
55 void EPGView::setStartTime( const QDateTime& startTime )
57 QList<QGraphicsItem*> itemList = items();
59 int diff = startTime.secsTo( m_startTime );
61 for ( int i = 0; i < itemList.count(); ++i )
63 EPGItem* item = static_cast<EPGItem*>( itemList.at( i ) );
64 item->setStart( item->start().addSecs( diff ) );
67 m_startTime = startTime;
69 // Our start time has changed
70 emit startTimeChanged( startTime );
73 const QDateTime& EPGView::startTime()
78 void EPGView::addEvent( EPGEvent* event )
80 if ( !m_channels.contains( event->channelName ) )
81 m_channels.append( event->channelName );
83 EPGItem* item = new EPGItem( this );
84 item->setChannel( m_channels.indexOf( event->channelName ) );
85 item->setStart( event->start );
86 item->setDuration( event->duration );
87 item->setName( event->name );
88 item->setDescription( event->description );
89 item->setShortDescription( event->shortDescription );
90 item->setCurrent( event->current );
92 scene()->addItem( item );
95 void EPGView::updateEvent( EPGEvent* event )
97 //qDebug() << "Update event: " << event->name;
100 void EPGView::delEvent( EPGEvent* event )
102 //qDebug() << "Del event: " << event->name;
105 void EPGView::drawBackground( QPainter *painter, const QRectF &rect )
107 painter->setPen( QPen( QColor( 72, 72, 72 ) ) );
109 QPointF p = mapToScene( width(), 0 );
112 for ( int i = 0; i < m_channels.count() + 1; ++i )
114 painter->drawLine( 0,
122 void EPGView::updateDuration()
125 QList<QGraphicsItem*> list = items();
127 for ( int i = 0; i < list.count(); ++i )
129 EPGItem* item = static_cast<EPGItem*>( list.at( i ) );
130 QDateTime itemEnd = item->start().addSecs( item->duration() );
132 if ( itemEnd > lastItem )
135 m_duration = m_startTime.secsTo( lastItem );
136 emit durationChanged( m_duration );
139 void EPGView::eventFocused( EPGEvent *ev )
141 emit eventFocusedChanged( ev );