-rw-r--r-- | korganizer/timeline.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/korganizer/timeline.cpp b/korganizer/timeline.cpp new file mode 100644 index 0000000..6f9c8dd --- a/dev/null +++ b/korganizer/timeline.cpp | |||
@@ -0,0 +1,63 @@ | |||
1 | #include <qpainter.h> | ||
2 | |||
3 | #include <kdebug.h> | ||
4 | |||
5 | #include "timeline.h" | ||
6 | #include "timeline.moc" | ||
7 | |||
8 | TimeLine::TimeLine( QWidget *parent, const char *name ) : | ||
9 | QScrollView( parent, name ) | ||
10 | { | ||
11 | mPixelWidth = 1000; | ||
12 | |||
13 | resizeContents( mPixelWidth, 20 ); | ||
14 | |||
15 | viewport()->setBackgroundMode( PaletteBackground ); | ||
16 | |||
17 | setHScrollBarMode(AlwaysOff); | ||
18 | setVScrollBarMode(AlwaysOff); | ||
19 | } | ||
20 | |||
21 | TimeLine::~TimeLine() | ||
22 | { | ||
23 | } | ||
24 | |||
25 | void TimeLine::drawContents(QPainter* p, int cx, int cy, int cw, int ch) | ||
26 | { | ||
27 | int spacingX = mDaySpacing; | ||
28 | int offsetX = mDayOffset; | ||
29 | |||
30 | // Draw vertical lines of grid | ||
31 | // kdDebug() << "drawContents cx: " << cx << " cy: " << cy << " cw: " << cw << " ch: " << ch << endl; | ||
32 | int cell = int( (cx - ( spacingX - offsetX ) ) / spacingX ); | ||
33 | int x = cell * spacingX + ( spacingX - offsetX ); | ||
34 | // kdDebug() << " x: " << x << endl; | ||
35 | while (x < cx + cw) { | ||
36 | // kdDebug() << " x: " << x << endl; | ||
37 | p->drawLine(x,cy,x,cy+ch); | ||
38 | p->drawText( x + 5, 15, QString::number( mStartDate.addDays( cell + 1 ).date().day() ) ); | ||
39 | |||
40 | x += spacingX; | ||
41 | cell++; | ||
42 | } | ||
43 | } | ||
44 | |||
45 | void TimeLine::setDateRange( const QDateTime &start, const QDateTime &end ) | ||
46 | { | ||
47 | mStartDate = start; | ||
48 | mEndDate = end; | ||
49 | |||
50 | mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mPixelWidth; | ||
51 | |||
52 | mDaySpacing = 60 * 60 * 24 / mSecsPerPixel; | ||
53 | |||
54 | mDayOffset = QDateTime( mStartDate.date() ).secsTo( mStartDate ) / mSecsPerPixel; | ||
55 | |||
56 | kdDebug() << "TimeLines::setDateRange(): mDaySpacing: " << mDaySpacing << " mDayOffset: " | ||
57 | << mDayOffset << " mSecsPerPixel: " << mSecsPerPixel << endl; | ||
58 | } | ||
59 | |||
60 | void TimeLine::setContentsPos( int pos ) | ||
61 | { | ||
62 | QScrollView::setContentsPos ( pos, 0 ); | ||
63 | } | ||