kgantt Library API Documentation

xQGanttBarView.cpp

00001 //
00002 //  file    : xQGanttBarView.C
00003 //  date    : 26 oct 2000
00004 //  changed : 28 nov 2000
00005 //  author  : jh
00006 //
00007 
00008 
00009 #include "xQGanttBarView.h"
00010 #include "KGanttBarConfig.h"
00011 
00012 
00013 
00014 xQGanttBarView::xQGanttBarView(KGanttItem* toplevelitem,
00015                    QWidget* parent, 
00016                    const char * name, WFlags f)
00017   : QScrollView(parent,name,f)
00018 {     
00019   _config = NULL;
00020 
00021   _toplevelitem = toplevelitem;
00022 
00023   setFrameStyle(QFrame::Sunken);
00024   setLineWidth(1);
00025 
00026   _headerBackBrush = QBrush(QColor(250,250,250));
00027 
00028   setMargins( 1, TOPMARGIN , 1, 1 );
00029 
00030   _viewport = new xQGanttBarViewPort(toplevelitem, this );
00031 
00032   addChild(_viewport);
00033 
00034   _viewport->setMode(xQGanttBarViewPort::Select);
00035 
00036   connect(_viewport, SIGNAL(scroll(int,int)),
00037       this, SLOT(scrollBy(int,int)) );  
00038 
00039   connect(_viewport, SIGNAL(recalculated()),
00040       this, SLOT(drawHeader()) );  
00041 
00042   connect(horizontalScrollBar(), SIGNAL(valueChanged(int)),
00043       this, SLOT(horizontalScrollBarChanged(int)) ); 
00044 
00045 }
00046 
00047 
00048 
00049 xQGanttBarView::~xQGanttBarView()
00051 {
00052 }
00053 
00054 
00055 
00056 void
00057 xQGanttBarView::horizontalScrollBarChanged(int x)
00059 {
00060   printf("xQGanttBarView::horizontalScrollBarChanged()\n");
00061   drawHeader();
00062 }
00063 
00064 
00065 
00066 void 
00067 xQGanttBarView::drawHeader()
00069 {
00070   static QPen _dotPen( QColor(35,35,35), 0, DotLine);
00071   static QPen _normalPen(QColor(0,0,0));
00072   static QPen _redPen(QColor(254,0,0));
00073   static QPen _greyPen(QColor(150,150,150));
00074 
00075   QPainter p(this);
00076   p.setPen( _normalPen );
00077 
00078   p.fillRect(0,0,width(),TOPMARGIN, _headerBackBrush );
00079 
00080   static int top = 1;
00081   static int height = 20;
00082   static int skip = 1;
00083  
00084   int a,e,tmp;
00085   bool drawDays = false;
00086   double dayWidth = (double) ((_viewport->screenX(144000) - _viewport->screenX(0))/100.);
00087 
00088   int wx = _viewport->worldX(contentsX());
00089 
00090   QDate startDate = _toplevelitem->getStart().addSecs( wx * 60 ).date();
00091 
00092   wx = _viewport->worldX(contentsX()+width());
00093   QDate endDate = _toplevelitem->getStart().addSecs( wx * 60 ).date();
00094   endDate = endDate.addDays(1);
00095 
00096   int end = (int) startDate.daysTo(endDate);  
00097   drawDays = (end < 12);
00098 
00099   //  draw week, which first day is not visible
00100 
00101   QDate t = startDate.addDays(-startDate.dayOfWeek()+1);    
00102    
00103   tmp = _toplevelitem->getStart().secsTo(t)/60;
00104   a = _viewport->screenX(tmp) - contentsX();
00105   
00106   p.fillRect(a, top, (int) (5. * dayWidth), height, QBrush(QColor(240,240,240))); 
00107   p.drawRect(a, top, (int) (5. * dayWidth), height );
00108 
00109   //  draw month, which first day is not visible
00110 
00111   t = startDate.addDays(-startDate.day()+1);    
00112    
00113   tmp = _toplevelitem->getStart().secsTo(t)/60;
00114   a = _viewport->screenX(tmp) - contentsX();
00115 
00116   e = t.daysInMonth();
00117   p.fillRect(a, top + height + skip, (int) (e*dayWidth), height, QBrush(QColor(240,240,240))); 
00118   p.drawRect(a, top + height + skip, (int) (e*dayWidth), height );
00119 
00120   if(a<0) a = 0;
00121   p.drawText(a+5, top + height + skip + (0.8*height), 
00122          t.shortMonthName(t.month()) + " " + QString::number(t.year()) );  
00123 
00124 
00125   //  draw snapgrid for first month
00126 
00127   tmp = _toplevelitem->getStart().secsTo(startDate)/60;
00128   a = _viewport->screenX(tmp) - contentsX()+1;
00129   double dx = (double) 
00130     ((_viewport->screenX(_viewport->_snapgrid*1000) - _viewport->screenX(0))/1000.);
00131   double limit = ((1+e-startDate.day()) * 1440)/_viewport->_snapgrid;
00132 
00133   for(double k=1.; k<limit; k++) {  
00134     p.setPen(_greyPen);
00135     p.drawLine(a + (int)(k * dx + 0.5), top + skip + 2 * height + 1, 
00136            a + (int)(k * dx + 0.5), top + skip + 2 * height + 2);
00137   }
00138 
00139 
00140   //  draw from start to end
00141 
00142   t = startDate;
00143 
00144   for(int i=0; i<end; i++, t = t.addDays(1) ) {          
00145 
00146     tmp = _toplevelitem->getStart().secsTo(t)/60;
00147     a = _viewport->screenX(tmp) - contentsX();
00148    
00149     p.setPen( QPen(QColor(black)) );
00150 
00151     if(t.dayOfWeek() == 1) {
00152     
00153       p.fillRect(a, top, (int) (5. * dayWidth), height, QBrush(QColor(240,240,240))); 
00154       p.drawRect(a, top, (int) (5. * dayWidth), height );
00155     
00156       if(!drawDays)
00157     p.drawText(a+5, (int) (top + (0.8*height)), QString::number(t.day()) );      
00158 
00159     }
00160 
00161     if(drawDays) {
00162 
00163       if(a<0) a = 0;
00164 
00165       QString str = t.shortDayName(t.dayOfWeek()) + " " + QString::number(t.day());
00166       QRect rect = p.boundingRect(a+5, (0.8 * height), 
00167                   (int) dayWidth, height, AlignLeft, str );
00168 
00169       if(t.dayOfWeek() > 5)
00170     p.fillRect(rect.x(), rect.y(), rect.width(), -rect.height(), _headerBackBrush );
00171       else
00172     p.fillRect(rect.x(), rect.y(), 
00173            rect.width(), -rect.height(), QBrush(QColor(240,240,240)));
00174 
00175       p.drawText(a+5, (0.8 * height), str );
00176 
00177       if(t.dayOfWeek()>1 && t.dayOfWeek()<6) {
00178     p.setPen(_dotPen);
00179     p.drawLine(a, top, a, height);
00180       }
00181     
00182     }
00183 
00184     if(t.day()==1) {
00185 
00186       e = t.daysInMonth();
00187 
00188       p.setPen(_normalPen);
00189 
00190       p.fillRect(a, top + height + skip, 
00191          (int) (e * dayWidth), height, QBrush(QColor(240,240,240))); 
00192       p.drawRect(a, top + height + skip, (int) (e * dayWidth), height );
00193       
00194       p.drawText(a+5, 
00195          top + (1.8 * height) + skip, 
00196          t.shortMonthName(t.month()) + " " + QString::number(t.year()) );  
00197 
00198       //  draw snapgrid
00199 
00200       double limit = (e * 1440)/_viewport->_snapgrid;
00201       for(double k=1.; k<limit; k++) {  
00202     p.setPen(_greyPen);
00203     p.drawLine(a + 1 + (int)(k * dx + 0.5), top + skip + 2 * height + 1, 
00204            a + 1 + (int)(k * dx + 0.5), top + skip + 2 * height + 2);
00205       }
00206      
00207 
00208     }
00209     
00210   } 
00211   
00212 }
00213 
00214 
00215 
00216 void 
00217 xQGanttBarView::paintEvent(QPaintEvent * e)
00218 {      
00219   drawHeader();
00220 }
00221 
00222 
00223 
00224 KGanttBarConfig* 
00225 xQGanttBarView::getConfig() 
00226 {
00227   if(_config)
00228     return _config;
00229   else {
00230     _config = new KGanttBarConfig(this);
00231     return _config;
00232   }
00233 
00234 }
00235 
00236 
00237 
00238 void 
00239 xQGanttBarView::showConfig()
00240 {
00241   getConfig()->show();
00242 }
00243 
00244 
00245 
00246 void
00247 xQGanttBarView::hideConfig()
00248 {
00249   if(_config)
00250     _config->hide();
00251 }
00252 #include "xQGanttBarView.moc"
KDE Logo
This file is part of the documentation for kgantt Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:42 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003