summaryrefslogtreecommitdiffabout
path: root/korganizer/lineview.cpp
Unidiff
Diffstat (limited to 'korganizer/lineview.cpp') (more/less context) (show whitespace changes)
-rw-r--r--korganizer/lineview.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/korganizer/lineview.cpp b/korganizer/lineview.cpp
new file mode 100644
index 0000000..f1ff29f
--- a/dev/null
+++ b/korganizer/lineview.cpp
@@ -0,0 +1,94 @@
1#include <qpainter.h>
2
3#include <kdebug.h>
4
5#include "koprefs.h"
6
7#include "lineview.h"
8#include "lineview.moc"
9
10LineView::LineView( QWidget *parent, const char *name ) :
11 QScrollView( parent, name )
12{
13 mPixelWidth = 1000;
14
15 mLines.setAutoDelete( true );
16
17 resizeContents( mPixelWidth, contentsHeight() );
18
19 viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
20}
21
22LineView::~LineView()
23{
24}
25
26int LineView::pixelWidth()
27{
28 return mPixelWidth;
29}
30
31void LineView::addLine( int start, int end )
32{
33 int count = mLines.count();
34
35 if( start < 0 ) start = 0;
36 if( end > mPixelWidth) end = mPixelWidth;
37
38 kdDebug() << "LineView::addLine() col: " << count << " start: " << start
39 << " end: " << end << endl;
40
41 mLines.append( new Line( count, start, end ) );
42}
43
44void LineView::clear()
45{
46 mLines.clear();
47 update();
48}
49
50void LineView::drawContents(QPainter* p, int cx, int cy, int cw, int ch)
51{
52// kdDebug() << "LineView::drawContents()" << endl;
53
54 int mGridSpacingX = 10;
55 int mGridSpacingY = 20;
56
57#if 0
58 // Draw vertical lines of grid
59 // kdDebug() << "drawContents cx: " << cx << " cy: " << cy << " cw: " << cw << " ch: " << ch << endl;
60 int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
61 while (x < cx + cw) {
62 p->drawLine(x,cy,x,cy+ch);
63 x+=mGridSpacingX;
64 }
65#endif
66
67 // Draw horizontal lines of grid
68 int y = ((int)(cy/mGridSpacingY))*mGridSpacingY + 10;
69 while (y < cy + ch) {
70// kdDebug() << " y: " << y << endl;
71 p->drawLine(cx,y,cx+cw,y);
72 y+=mGridSpacingY;
73 }
74
75 Line *line;
76 for( line = mLines.first(); line; line = mLines.next() ) {
77 int ctop = line->column * 20 + 10 - 5;
78 int cbottom = line->column * 20 + 10 + 5;
79 int s = line->start;
80 int e = line->end;
81// kdDebug() << " LineView::drawContents(): ctop: " << ctop << " cbottom: "
82// << cbottom << " s: " << s << " e: " << e << endl;
83 if ( ctop <= (cy+ch) && cbottom >= cy &&
84 s <= (cx+cw) && e >= cx ) {
85 if ( s < cx ) s = cx;
86 if ( e > (cx+cw) ) e = cx+cw;
87 if ( ctop < cy ) ctop = cy;
88 if ( cbottom > (cy+ch) ) cbottom = cy+ch;
89// kdDebug() << " drawContents(): ctop: " << ctop << " cbottom: "
90// << cbottom << " s: " << s << " e: " << e << endl;
91 p->fillRect( s, ctop, e - s + 1, cbottom - ctop + 1, QBrush("red") );
92 }
93 }
94}