1 /*****************************************************************************
2 * EPGRuler.coo: EPGRuler
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 "EPGRuler.hpp"
28 #include <QPaintEvent>
32 EPGRuler::EPGRuler( QWidget* parent )
35 setContentsMargins( 0, 0, 0, 0 );
36 setMinimumHeight( 30 );
37 setMaximumHeight( 30 );
41 void EPGRuler::setScale( double scale )
47 void EPGRuler::setStartTime( const QDateTime& startTime )
49 m_startTime = startTime;
53 void EPGRuler::setDuration( int duration )
55 m_duration = duration;
59 void EPGRuler::setOffset( int offset )
65 void EPGRuler::paintEvent( QPaintEvent *event )
71 int secondsOffset = m_offset / m_scale;
73 QDateTime localStartTime;
74 localStartTime = m_startTime.addSecs( secondsOffset );
76 QDateTime diff( localStartTime );
77 diff.setTime( QTime( localStartTime.time().hour(), 0, 0, 0 ) );
79 int secondsToHour = localStartTime.secsTo( diff );
81 QDateTime current( localStartTime.addSecs( secondsToHour ) );
83 int spacing = ( m_scale * 60 ) * 60;
84 int posx = secondsToHour * m_scale;
86 // Count the number of items to draw
87 int itemsToDraw = ( width() / spacing ) + 1;
89 for ( ; itemsToDraw >= 0; --itemsToDraw )
91 p.drawLine( posx, 15, posx, 30 );
92 p.drawText( posx + 1, 12, 50, 15, Qt::AlignLeft, current.toString( "hh'h'" ) );
94 current = current.addSecs( 60 * 60 );
97 /* draw current time line */
98 posx = localStartTime.secsTo( QDateTime::currentDateTime() ) * m_scale;
99 if ( posx <= width() && posx >= 0 )
101 QPen pen( QPen( QColor( 255, 0 , 0, 128 ) ) );
104 p.drawLine( posx - 1, 15, posx - 1, 30 );