korganizer
timeline.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <qpainter.h>
00026
00027 #include <kdebug.h>
00028
00029 #include "timeline.h"
00030 #include "timeline.moc"
00031
00032 TimeLine::TimeLine( QWidget *parent, const char *name ) :
00033 QScrollView( parent, name )
00034 {
00035 mPixelWidth = 1000;
00036
00037 resizeContents( mPixelWidth, 20 );
00038
00039 viewport()->setBackgroundMode( PaletteBackground );
00040
00041 setHScrollBarMode(AlwaysOff);
00042 setVScrollBarMode(AlwaysOff);
00043 }
00044
00045 TimeLine::~TimeLine()
00046 {
00047 }
00048
00049 void TimeLine::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
00050 {
00051 int spacingX = mDaySpacing;
00052 int offsetX = mDayOffset;
00053
00054
00055
00056 int cell = int( (cx - ( spacingX - offsetX ) ) / spacingX );
00057 int x = cell * spacingX + ( spacingX - offsetX );
00058
00059 while (x < cx + cw) {
00060
00061 p->drawLine(x,cy,x,cy+ch);
00062 p->drawText( x + 5, 15, QString::number( mStartDate.addDays( cell + 1 ).date().day() ) );
00063
00064 x += spacingX;
00065 cell++;
00066 }
00067 }
00068
00069 void TimeLine::setDateRange( const QDateTime &start, const QDateTime &end )
00070 {
00071 mStartDate = start;
00072 mEndDate = end;
00073
00074 mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mPixelWidth;
00075
00076 mDaySpacing = 60 * 60 * 24 / mSecsPerPixel;
00077
00078 mDayOffset = QDateTime( mStartDate.date() ).secsTo( mStartDate ) / mSecsPerPixel;
00079
00080 kdDebug(5850) << "TimeLines::setDateRange(): mDaySpacing: " << mDaySpacing << " mDayOffset: "
00081 << mDayOffset << " mSecsPerPixel: " << mSecsPerPixel << endl;
00082 }
00083
00084 void TimeLine::setContentsPos( int pos )
00085 {
00086 QScrollView::setContentsPos ( pos, 0 );
00087 }
|