korganizer
lineview.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00077
00078
00079 int mGridSpacingY = 20;
00080
00081 #if 0
00082
00083
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
00092 int y = ((int)(cy/mGridSpacingY))*mGridSpacingY + 10;
00093 while (y < cy + ch) {
00094
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
00106
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
00114
00115 p->fillRect( s, ctop, e - s + 1, cbottom - ctop + 1, QBrush("red") );
00116 }
00117 }
00118 }
|