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 *****************************************************************************/
25 #include "EPGView.hpp"
26 #include "EPGItem.hpp"
29 EPGView::EPGView( QWidget *parent ) : QGraphicsView( parent )
31 setContentsMargins( 0, 0, 0, 0 );
32 setFrameStyle( QFrame::NoFrame );
33 setAlignment( Qt::AlignLeft | Qt::AlignTop );
35 m_startTime = QDateTime::currentDateTime();
38 setSceneRect( 0, 0, 20000, 200 );
40 QGraphicsScene *EPGscene = new QGraphicsScene( this );
45 void EPGView::setScale( double scaleFactor )
47 m_scaleFactor = scaleFactor;
49 matrix.scale( scaleFactor, 1 );
53 void EPGView::setStartTime( const QDateTime& startTime )
55 QList<QGraphicsItem*> itemList = items();
57 int diff = startTime.secsTo( m_startTime );
59 for ( int i = 0; i < itemList.count(); ++i )
61 EPGItem* item = static_cast<EPGItem*>( itemList.at( i ) );
62 item->setStart( item->start().addSecs( diff ) );
65 m_startTime = startTime;
67 // Our start time has changed
68 emit startTimeChanged( startTime );
71 const QDateTime& EPGView::startTime()
76 void EPGView::addEvent( EPGEvent* event )
78 if ( !m_channels.contains( event->channelName ) )
79 m_channels.append( event->channelName );
81 EPGItem* item = new EPGItem( this );
82 item->setChannel( m_channels.indexOf( event->channelName ) );
83 item->setStart( event->start );
84 item->setDuration( event->duration );
85 item->setName( event->name );
86 item->setDescription( event->description );
87 item->setShortDescription( event->shortDescription );
88 item->setCurrent( event->current );
90 scene()->addItem( item );
93 void EPGView::updateEvent( EPGEvent* event )
95 qDebug() << "Update event: " << event->name;
98 void EPGView::delEvent( EPGEvent* event )
100 qDebug() << "Del event: " << event->name;
103 void EPGView::drawBackground( QPainter *painter, const QRectF &rect )
105 painter->setPen( QPen( QColor( 72, 72, 72 ) ) );
107 QPointF p = mapToScene( width(), 0 );
110 for ( int i = 0; i < m_channels.count() + 1; ++i )
112 painter->drawLine( 0,
120 void EPGView::updateDuration()
123 QList<QGraphicsItem*> list = items();
125 for ( int i = 0; i < list.count(); ++i )
127 EPGItem* item = static_cast<EPGItem*>( list.at( i ) );
128 QDateTime itemEnd = item->start().addSecs( item->duration() );
130 if ( itemEnd > lastItem )
133 m_duration = m_startTime.secsTo( lastItem );
134 emit durationChanged( m_duration );