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"
29 #include <QPaintEvent>
32 #include <QGraphicsTextItem>
34 EPGView::EPGView( QWidget *parent ) : QGraphicsView( parent )
36 setContentsMargins( 0, 0, 0, 0 );
37 setFrameStyle( QFrame::Box );
38 setAlignment( Qt::AlignLeft | Qt::AlignTop );
40 m_startTime = QDateTime::currentDateTime();
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 )
64 EPGItem* item = dynamic_cast<EPGItem*>( itemList.at( i ) );
68 if ( !item ) continue;
69 item->setStart( item->start().addSecs( diff ) );
72 m_startTime = startTime;
74 // Our start time has changed
75 emit startTimeChanged( startTime );
78 const QDateTime& EPGView::startTime()
83 void EPGView::addEvent( EPGEvent* event )
85 if ( !m_channels.contains( event->channelName ) )
86 m_channels.append( event->channelName );
88 EPGItem* item = new EPGItem( this );
89 item->setChannel( m_channels.indexOf( event->channelName ) );
90 item->setStart( event->start );
91 item->setDuration( event->duration );
92 item->setName( event->name );
93 item->setDescription( event->description );
94 item->setShortDescription( event->shortDescription );
95 item->setCurrent( event->current );
97 scene()->addItem( item );
100 void EPGView::updateEvent( EPGEvent* event )
102 //qDebug() << "Update event: " << event->name;
105 void EPGView::delEvent( EPGEvent* event )
107 //qDebug() << "Del event: " << event->name;
110 void EPGView::updateDuration()
113 QList<QGraphicsItem*> list = items();
115 for ( int i = 0; i < list.count(); ++i )
118 EPGItem* item = dynamic_cast<EPGItem*>( list.at( i ) );
120 EPGItem *item = NULL;
122 if ( !item ) continue;
123 QDateTime itemEnd = item->start().addSecs( item->duration() );
125 if ( itemEnd > lastItem )
128 m_duration = m_startTime.secsTo( lastItem );
129 emit durationChanged( m_duration );
132 QList<QString> EPGView::getChannelList()
137 void EPGView::eventFocused( EPGEvent *ev )
139 emit eventFocusedChanged( ev );