lineview.cpp
00001 #include <qpainter.h>
00002
00003 #include <kdebug.h>
00004
00005 #include "koprefs.h"
00006
00007 #include "lineview.h"
00008 #include "lineview.moc"
00009
00010 LineView::LineView( QWidget *parent, const char *name ) :
00011 QScrollView( parent, name )
00012 {
00013 mPixelWidth = 1000;
00014
00015 mLines.setAutoDelete( true );
00016
00017 resizeContents( mPixelWidth, contentsHeight() );
00018
00019 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
00020 }
00021
00022 LineView::~LineView()
00023 {
00024 }
00025
00026 int LineView::pixelWidth()
00027 {
00028 return mPixelWidth;
00029 }
00030
00031 void LineView::addLine( int start, int end )
00032 {
00033 int count = mLines.count();
00034
00035 if( start < 0 ) start = 0;
00036 if( end > mPixelWidth) end = mPixelWidth;
00037
00038 kdDebug() << "LineView::addLine() col: " << count << " start: " << start
00039 << " end: " << end << endl;
00040
00041 mLines.append( new Line( count, start, end ) );
00042 }
00043
00044 void LineView::clear()
00045 {
00046 mLines.clear();
00047 update();
00048 }
00049
00050 void LineView::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
00051 {
00052
00053
00054 int mGridSpacingX = 10;
00055 int mGridSpacingY = 20;
00056
00057 #if 0
00058
00059
00060 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
00061 while (x < cx + cw) {
00062 p->drawLine(x,cy,x,cy+ch);
00063 x+=mGridSpacingX;
00064 }
00065 #endif
00066
00067
00068 int y = ((int)(cy/mGridSpacingY))*mGridSpacingY + 10;
00069 while (y < cy + ch) {
00070
00071 p->drawLine(cx,y,cx+cw,y);
00072 y+=mGridSpacingY;
00073 }
00074
00075 Line *line;
00076 for( line = mLines.first(); line; line = mLines.next() ) {
00077 int ctop = line->column * 20 + 10 - 5;
00078 int cbottom = line->column * 20 + 10 + 5;
00079 int s = line->start;
00080 int e = line->end;
00081
00082
00083 if ( ctop <= (cy+ch) && cbottom >= cy &&
00084 s <= (cx+cw) && e >= cx ) {
00085 if ( s < cx ) s = cx;
00086 if ( e > (cx+cw) ) e = cx+cw;
00087 if ( ctop < cy ) ctop = cy;
00088 if ( cbottom > (cy+ch) ) cbottom = cy+ch;
00089
00090
00091 p->fillRect( s, ctop, e - s + 1, cbottom - ctop + 1, QBrush("red") );
00092 }
00093 }
00094 }
This file is part of the documentation for kdelibs Version 3.1.4.