Commit 726e595b authored by Francois Cartegnie's avatar Francois Cartegnie

Qt: EPGView: use bounding rects for simplification

parent 11315607
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
#include <QPaintEvent> #include <QPaintEvent>
#include <QtDebug> #include <QtDebug>
#include <QDateTime> #include <QDateTime>
#include <QPoint>
#include <QRect>
#include <QSize>
EPGRuler::EPGRuler( QWidget* parent ) EPGRuler::EPGRuler( QWidget* parent )
: QWidget( parent ) : QWidget( parent )
...@@ -66,41 +69,40 @@ void EPGRuler::paintEvent( QPaintEvent *event ) ...@@ -66,41 +69,40 @@ void EPGRuler::paintEvent( QPaintEvent *event )
{ {
Q_UNUSED( event ); Q_UNUSED( event );
const QSize margin( 0, 15 );
const QSize header( 0, 15 );
const int spacing = m_scale * 3600;
QPainter p( this ); QPainter p( this );
int secondsOffset = m_offset / m_scale;
QDateTime localStartTime; QDateTime localStartTime;
localStartTime = m_startTime.addSecs( secondsOffset ); localStartTime = m_startTime.addSecs( m_offset / m_scale );
QDateTime diff( localStartTime ); QDateTime diff( localStartTime );
diff.setTime( QTime( localStartTime.time().hour(), 0, 0, 0 ) ); diff.setTime( QTime( localStartTime.time().hour(), 0, 0, 0 ) );
int secondsToHour = localStartTime.secsTo( diff ); int secondsToHour = localStartTime.secsTo( diff );
/* draw hour blocks, with right bound being hourmark */
QPoint here( secondsToHour * m_scale, margin.height() );
QPoint previous( -1, 0 );
QDateTime current( localStartTime.addSecs( secondsToHour ) ); QDateTime current( localStartTime.addSecs( secondsToHour ) );
current = current.addSecs( -3600 );
int spacing = ( m_scale * 60 ) * 60; while ( here.rx() < width() + spacing )
int posx = secondsToHour * m_scale;
// Count the number of items to draw
int itemsToDraw = ( width() / spacing ) + 1;
for ( ; itemsToDraw >= 0; --itemsToDraw )
{ {
p.drawLine( posx, 15, posx, 30 ); QRect area( QPoint( previous.x() + 1, margin.height() ), here );
p.drawText( posx + 1, 12, 50, 15, Qt::AlignLeft, current.toString( "hh'h'" ) ); area.adjust( 0, 0, 0, header.height() );
posx += spacing; p.drawLine( area.topRight(), area.bottomRight() );
current = current.addSecs( 60 * 60 ); p.drawText( area, Qt::AlignLeft, current.toString( "hh'h'" ) );
previous = here;
here.rx() += spacing;
current = current.addSecs( 3600 );
} }
/* draw current time line */ /* draw current time line */
posx = localStartTime.secsTo( QDateTime::currentDateTime() ) * m_scale; here.rx() = localStartTime.secsTo( QDateTime::currentDateTime() ) * m_scale;
if ( posx <= width() && posx >= 0 ) if ( here.x() <= width() && here.x() >= 0 )
{ {
QPen pen( QPen( QColor( 255, 0 , 0, 128 ) ) ); p.setPen( QPen( QColor( 255, 0 , 0, 128 ) ) );
pen.setWidth( 3 ); p.drawLine( here, QPoint( here.x(), here.y() + header.height() ) );
p.setPen( pen );
p.drawLine( posx - 1, 15, posx - 1, 30 );
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment