korganizer

timeline.cpp

00001 /*
00002     This file is part of KOrganizer.
00003 
00004     Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
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   // Draw vertical lines of grid
00055 //  kdDebug(5850) << "drawContents cx: " << cx << " cy: " << cy << " cw: " << cw << " ch: " << ch << endl;
00056   int cell = int( (cx - ( spacingX - offsetX ) ) / spacingX );
00057   int x = cell * spacingX + ( spacingX - offsetX );
00058 //  kdDebug(5850) << "  x: " << x << endl;
00059   while (x < cx + cw) {
00060 //    kdDebug(5850) << "    x: " << x << endl;
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 }
KDE Home | KDE Accessibility Home | Description of Access Keys