[vlc-commits] Qt: EPGView: use bounding rects for simplification
Francois Cartegnie
git at videolan.org
Sat Mar 9 20:30:39 CET 2013
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Sat Mar 9 16:52:23 2013 +0100| [726e595bd59586e393de7b931d693c26b37f9cea] | committer: Francois Cartegnie
Qt: EPGView: use bounding rects for simplification
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=726e595bd59586e393de7b931d693c26b37f9cea
---
modules/gui/qt4/components/epg/EPGRuler.cpp | 44 ++++++++++++++-------------
1 file changed, 23 insertions(+), 21 deletions(-)
diff --git a/modules/gui/qt4/components/epg/EPGRuler.cpp b/modules/gui/qt4/components/epg/EPGRuler.cpp
index fa5c103..ac898c1 100644
--- a/modules/gui/qt4/components/epg/EPGRuler.cpp
+++ b/modules/gui/qt4/components/epg/EPGRuler.cpp
@@ -28,6 +28,9 @@
#include <QPaintEvent>
#include <QtDebug>
#include <QDateTime>
+#include <QPoint>
+#include <QRect>
+#include <QSize>
EPGRuler::EPGRuler( QWidget* parent )
: QWidget( parent )
@@ -66,41 +69,40 @@ void EPGRuler::paintEvent( QPaintEvent *event )
{
Q_UNUSED( event );
+ const QSize margin( 0, 15 );
+ const QSize header( 0, 15 );
+ const int spacing = m_scale * 3600;
QPainter p( this );
- int secondsOffset = m_offset / m_scale;
-
QDateTime localStartTime;
- localStartTime = m_startTime.addSecs( secondsOffset );
+ localStartTime = m_startTime.addSecs( m_offset / m_scale );
QDateTime diff( localStartTime );
diff.setTime( QTime( localStartTime.time().hour(), 0, 0, 0 ) );
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 ) );
-
- int spacing = ( m_scale * 60 ) * 60;
- int posx = secondsToHour * m_scale;
-
- // Count the number of items to draw
- int itemsToDraw = ( width() / spacing ) + 1;
-
- for ( ; itemsToDraw >= 0; --itemsToDraw )
+ current = current.addSecs( -3600 );
+ while ( here.rx() < width() + spacing )
{
- p.drawLine( posx, 15, posx, 30 );
- p.drawText( posx + 1, 12, 50, 15, Qt::AlignLeft, current.toString( "hh'h'" ) );
- posx += spacing;
- current = current.addSecs( 60 * 60 );
+ QRect area( QPoint( previous.x() + 1, margin.height() ), here );
+ area.adjust( 0, 0, 0, header.height() );
+ p.drawLine( area.topRight(), area.bottomRight() );
+ p.drawText( area, Qt::AlignLeft, current.toString( "hh'h'" ) );
+ previous = here;
+ here.rx() += spacing;
+ current = current.addSecs( 3600 );
}
/* draw current time line */
- posx = localStartTime.secsTo( QDateTime::currentDateTime() ) * m_scale;
- if ( posx <= width() && posx >= 0 )
+ here.rx() = localStartTime.secsTo( QDateTime::currentDateTime() ) * m_scale;
+ if ( here.x() <= width() && here.x() >= 0 )
{
- QPen pen( QPen( QColor( 255, 0 , 0, 128 ) ) );
- pen.setWidth( 3 );
- p.setPen( pen );
- p.drawLine( posx - 1, 15, posx - 1, 30 );
+ p.setPen( QPen( QColor( 255, 0 , 0, 128 ) ) );
+ p.drawLine( here, QPoint( here.x(), here.y() + header.height() ) );
}
}
More information about the vlc-commits
mailing list