summaryrefslogtreecommitdiffabout
path: root/korganizer/timeline.cpp
authorzautrix <zautrix>2004-06-26 19:01:18 (UTC)
committer zautrix <zautrix>2004-06-26 19:01:18 (UTC)
commitb9aad1f15dc600e4dbe4c62d3fcced6363188ba3 (patch) (unidiff)
tree2c3d4004fb21c72cba65793859f9bcd8ffd3a49c /korganizer/timeline.cpp
downloadkdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.zip
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.gz
kdepimpi-b9aad1f15dc600e4dbe4c62d3fcced6363188ba3.tar.bz2
Initial revision
Diffstat (limited to 'korganizer/timeline.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/timeline.cpp63
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
8TimeLine::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
21TimeLine::~TimeLine()
22{
23}
24
25void 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
45void 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
60void TimeLine::setContentsPos( int pos )
61{
62 QScrollView::setContentsPos ( pos, 0 );
63}