timeline.cpp
00001 #include <qpainter.h>
00002
00003 #include <kdebug.h>
00004
00005 #include "timeline.h"
00006 #include "timeline.moc"
00007
00008 TimeLine::TimeLine( QWidget *parent, const char *name ) :
00009 QScrollView( parent, name )
00010 {
00011 mPixelWidth = 1000;
00012
00013 resizeContents( mPixelWidth, 20 );
00014
00015 viewport()->setBackgroundMode( PaletteBackground );
00016
00017 setHScrollBarMode(AlwaysOff);
00018 setVScrollBarMode(AlwaysOff);
00019 }
00020
00021 TimeLine::~TimeLine()
00022 {
00023 }
00024
00025 void TimeLine::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
00026 {
00027 int spacingX = mDaySpacing;
00028 int offsetX = mDayOffset;
00029
00030
00031
00032 int cell = int( (cx - ( spacingX - offsetX ) ) / spacingX );
00033 int x = cell * spacingX + ( spacingX - offsetX );
00034
00035 while (x < cx + cw) {
00036
00037 p->drawLine(x,cy,x,cy+ch);
00038 p->drawText( x + 5, 15, QString::number( mStartDate.addDays( cell + 1 ).date().day() ) );
00039
00040 x += spacingX;
00041 cell++;
00042 }
00043 }
00044
00045 void TimeLine::setDateRange( const QDateTime &start, const QDateTime &end )
00046 {
00047 mStartDate = start;
00048 mEndDate = end;
00049
00050 mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mPixelWidth;
00051
00052 mDaySpacing = 60 * 60 * 24 / mSecsPerPixel;
00053
00054 mDayOffset = QDateTime( mStartDate.date() ).secsTo( mStartDate ) / mSecsPerPixel;
00055
00056 kdDebug() << "TimeLines::setDateRange(): mDaySpacing: " << mDaySpacing << " mDayOffset: "
00057 << mDayOffset << " mSecsPerPixel: " << mSecsPerPixel << endl;
00058 }
00059
00060 void TimeLine::setContentsPos( int pos )
00061 {
00062 QScrollView::setContentsPos ( pos, 0 );
00063 }
This file is part of the documentation for kdelibs Version 3.1.4.