korganizer

lineview.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 "koprefs.h"
00030 
00031 #include "lineview.h"
00032 #include "lineview.moc"
00033 
00034 LineView::LineView( QWidget *parent, const char *name ) :
00035   QScrollView( parent, name )
00036 {
00037   mPixelWidth = 1000;
00038 
00039   mLines.setAutoDelete( true );
00040 
00041   resizeContents( mPixelWidth, contentsHeight() );
00042 
00043   viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
00044 }
00045 
00046 LineView::~LineView()
00047 {
00048 }
00049 
00050 int LineView::pixelWidth()
00051 {
00052   return mPixelWidth;
00053 }
00054 
00055 void LineView::addLine( int start, int end )
00056 {
00057   int count = mLines.count();
00058   
00059   if( start < 0 ) start = 0;
00060   if( end > mPixelWidth) end = mPixelWidth;
00061   
00062   kdDebug(5850) << "LineView::addLine() col: " << count << "  start: " << start
00063             << "  end: " << end << endl;
00064   
00065   mLines.append( new Line( count, start, end ) );
00066 }
00067 
00068 void LineView::clear()
00069 {
00070   mLines.clear();
00071   update();
00072 }
00073 
00074 void LineView::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
00075 {
00076 //  kdDebug(5850) << "LineView::drawContents()" << endl;
00077 
00078 //  int mGridSpacingX = 10;
00079   int mGridSpacingY = 20;
00080 
00081 #if 0
00082   // Draw vertical lines of grid
00083   //  kdDebug(5850) << "drawContents cx: " << cx << " cy: " << cy << " cw: " << cw << " ch: " << ch << endl;
00084   int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
00085   while (x < cx + cw) {
00086     p->drawLine(x,cy,x,cy+ch);
00087     x+=mGridSpacingX;
00088   }
00089 #endif
00090 
00091   // Draw horizontal lines of grid
00092   int y = ((int)(cy/mGridSpacingY))*mGridSpacingY + 10;
00093   while (y < cy + ch) {
00094 //    kdDebug(5850) << " y: " << y << endl;
00095     p->drawLine(cx,y,cx+cw,y);
00096     y+=mGridSpacingY;
00097   }
00098   
00099   Line *line;
00100   for( line = mLines.first(); line; line = mLines.next() ) {
00101     int ctop = line->column * 20 + 10 - 5;
00102     int cbottom = line->column * 20 + 10 + 5;
00103     int s = line->start;
00104     int e = line->end;
00105 //    kdDebug(5850) << "  LineView::drawContents(): ctop: " << ctop << "  cbottom: "
00106 //              << cbottom << "  s: " << s << "  e: " << e << endl;
00107     if ( ctop <= (cy+ch) && cbottom >= cy &&
00108          s <= (cx+cw) && e >= cx ) {
00109       if ( s < cx ) s = cx;
00110       if ( e > (cx+cw) ) e = cx+cw;
00111       if ( ctop < cy ) ctop = cy;
00112       if ( cbottom > (cy+ch) ) cbottom = cy+ch;
00113 //      kdDebug(5850) << "            drawContents(): ctop: " << ctop << "  cbottom: "
00114 //                << cbottom << "  s: " << s << "  e: " << e << endl;
00115       p->fillRect( s, ctop, e - s + 1, cbottom - ctop + 1, QBrush("red") );
00116     }
00117   }
00118 }
KDE Home | KDE Accessibility Home | Description of Access Keys