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>
31 EPGRuler::EPGRuler( QWidget* parent )
34 setContentsMargins( 0, 0, 0, 0 );
35 setMinimumHeight( 30 );
36 setMaximumHeight( 30 );
40 void EPGRuler::setScale( double scale )
46 void EPGRuler::setStartTime( const QDateTime& startTime )
48 m_startTime = startTime;
52 void EPGRuler::setDuration( int duration )
54 m_duration = duration;
58 void EPGRuler::setOffset( int offset )
64 void EPGRuler::paintEvent( QPaintEvent *event )
70 int secondsOffset = m_offset / m_scale;
72 QDateTime localStartTime;
73 localStartTime = m_startTime.addSecs( secondsOffset );
75 QDateTime diff( localStartTime );
76 diff.setTime( QTime( localStartTime.time().hour(), 0, 0, 0 ) );
78 int secondsToHour = localStartTime.secsTo( diff );
80 QDateTime current( localStartTime.addSecs( secondsToHour ) );
82 int spacing = ( m_scale * 60 ) * 60;
83 int posx = secondsToHour * m_scale;
85 // Count the number of items to draw
86 int itemsToDraw = ( width() / spacing ) + 1;
88 for ( ; itemsToDraw >= 0; --itemsToDraw )
90 p.setFont( QFont( "Verdana", 8 ) );
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 );