timeline.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqpainter.h>
26 
27 #include <kdebug.h>
28 
29 #include "timeline.h"
30 #include "timeline.moc"
31 
32 TimeLine::TimeLine( TQWidget *parent, const char *name ) :
33  TQScrollView( parent, name )
34 {
35  mPixelWidth = 1000;
36 
37  resizeContents( mPixelWidth, 20 );
38 
39  viewport()->setBackgroundMode( PaletteBackground );
40 
41  setHScrollBarMode(AlwaysOff);
42  setVScrollBarMode(AlwaysOff);
43 }
44 
45 TimeLine::~TimeLine()
46 {
47 }
48 
49 void TimeLine::drawContents(TQPainter* p, int cx, int cy, int cw, int ch)
50 {
51  int spacingX = mDaySpacing;
52  int offsetX = mDayOffset;
53 
54  // Draw vertical lines of grid
55 // kdDebug(5850) << "drawContents cx: " << cx << " cy: " << cy << " cw: " << cw << " ch: " << ch << endl;
56  int cell = int( (cx - ( spacingX - offsetX ) ) / spacingX );
57  int x = cell * spacingX + ( spacingX - offsetX );
58 // kdDebug(5850) << " x: " << x << endl;
59  while (x < cx + cw) {
60 // kdDebug(5850) << " x: " << x << endl;
61  p->drawLine(x,cy,x,cy+ch);
62  p->drawText( x + 5, 15, TQString::number( mStartDate.addDays( cell + 1 ).date().day() ) );
63 
64  x += spacingX;
65  cell++;
66  }
67 }
68 
69 void TimeLine::setDateRange( const TQDateTime &start, const TQDateTime &end )
70 {
71  mStartDate = start;
72  mEndDate = end;
73 
74  mSecsPerPixel = mStartDate.secsTo( mEndDate ) / mPixelWidth;
75 
76  mDaySpacing = 60 * 60 * 24 / mSecsPerPixel;
77 
78  mDayOffset = TQDateTime( mStartDate.date() ).secsTo( mStartDate ) / mSecsPerPixel;
79 
80  kdDebug(5850) << "TimeLines::setDateRange(): mDaySpacing: " << mDaySpacing << " mDayOffset: "
81  << mDayOffset << " mSecsPerPixel: " << mSecsPerPixel << endl;
82 }
83 
84 void TimeLine::setContentsPos( int pos )
85 {
86  TQScrollView::setContentsPos ( pos, 0 );
87 }