lineview.cpp
1 /*
2  This file is part of KOrganizer.
3 
4  Copyright (c) 2001 Cornelius Schumacher <schumacher@kde.org>
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20  As a special exception, permission is given to link this program
21  with any edition of TQt, and distribute the resulting executable,
22  without including the source code for TQt in the source distribution.
23 */
24 
25 #include <tqpainter.h>
26 
27 #include <kdebug.h>
28 
29 #include "koprefs.h"
30 
31 #include "lineview.h"
32 #include "lineview.moc"
33 
34 LineView::LineView( TQWidget *parent, const char *name ) :
35  TQScrollView( parent, name )
36 {
37  mPixelWidth = 1000;
38 
39  mLines.setAutoDelete( true );
40 
41  resizeContents( mPixelWidth, contentsHeight() );
42 
43  viewport()->setBackgroundColor(KOPrefs::instance()->mAgendaBgColor);
44 }
45 
46 LineView::~LineView()
47 {
48 }
49 
50 int LineView::pixelWidth()
51 {
52  return mPixelWidth;
53 }
54 
55 void LineView::addLine( int start, int end )
56 {
57  int count = mLines.count();
58 
59  if( start < 0 ) start = 0;
60  if( end > mPixelWidth) end = mPixelWidth;
61 
62  kdDebug(5850) << "LineView::addLine() col: " << count << " start: " << start
63  << " end: " << end << endl;
64 
65  mLines.append( new Line( count, start, end ) );
66 }
67 
68 void LineView::clear()
69 {
70  mLines.clear();
71  update();
72 }
73 
74 void LineView::drawContents(TQPainter* p, int cx, int cy, int cw, int ch)
75 {
76 // kdDebug(5850) << "LineView::drawContents()" << endl;
77 
78 // int mGridSpacingX = 10;
79  int mGridSpacingY = 20;
80 
81 #if 0
82  // Draw vertical lines of grid
83  // kdDebug(5850) << "drawContents cx: " << cx << " cy: " << cy << " cw: " << cw << " ch: " << ch << endl;
84  int x = ((int)(cx/mGridSpacingX))*mGridSpacingX;
85  while (x < cx + cw) {
86  p->drawLine(x,cy,x,cy+ch);
87  x+=mGridSpacingX;
88  }
89 #endif
90 
91  // Draw horizontal lines of grid
92  int y = ((int)(cy/mGridSpacingY))*mGridSpacingY + 10;
93  while (y < cy + ch) {
94 // kdDebug(5850) << " y: " << y << endl;
95  p->drawLine(cx,y,cx+cw,y);
96  y+=mGridSpacingY;
97  }
98 
99  Line *line;
100  for( line = mLines.first(); line; line = mLines.next() ) {
101  int ctop = line->column * 20 + 10 - 5;
102  int cbottom = line->column * 20 + 10 + 5;
103  int s = line->start;
104  int e = line->end;
105 // kdDebug(5850) << " LineView::drawContents(): ctop: " << ctop << " cbottom: "
106 // << cbottom << " s: " << s << " e: " << e << endl;
107  if ( ctop <= (cy+ch) && cbottom >= cy &&
108  s <= (cx+cw) && e >= cx ) {
109  if ( s < cx ) s = cx;
110  if ( e > (cx+cw) ) e = cx+cw;
111  if ( ctop < cy ) ctop = cy;
112  if ( cbottom > (cy+ch) ) cbottom = cy+ch;
113 // kdDebug(5850) << " drawContents(): ctop: " << ctop << " cbottom: "
114 // << cbottom << " s: " << s << " e: " << e << endl;
115  p->fillRect( s, ctop, e - s + 1, cbottom - ctop + 1, TQBrush("red") );
116  }
117  }
118 }