00001
00002
00003
00004
00005
00006
00007
00008 #include "xQGanttListViewPort.h"
00009
00010 #include <qcolor.h>
00011
00012
00013 int xQGanttListViewPort::_ListViewCounter = 0;
00014
00015
00016 xQGanttListViewPort::xQGanttListViewPort(KGanttItem* toplevelitem, QWidget* parent,
00017 const char * name, WFlags f )
00018 : QFrame(parent,name,f)
00019 {
00020 _toplevelitem = toplevelitem;
00021
00022 setBackgroundColor(QColor(white));
00023
00024 _barviewport = NULL;
00025
00026 _width = 1000;
00027
00028 brush1 = QBrush(QColor(200,200,230));
00029 brush2 = QBrush(QColor(240,240,240));
00030
00031 }
00032
00033
00034
00035 xQGanttListViewPort::~xQGanttListViewPort()
00037 {
00038 }
00039
00040
00041
00042 void
00043 xQGanttListViewPort::setBarViewPort(xQGanttBarViewPort* v)
00044 {
00045 _barviewport = v;
00046
00047
00048
00049 resize(500, _barviewport->height());
00050
00051 printf("setBarViewPort()\n");
00052
00053 connect(_barviewport, SIGNAL(resized()),
00054 this, SLOT(barViewResized()));
00055
00056
00057 connect(_barviewport, SIGNAL(recalculated()),
00058 this, SLOT(update()));
00059
00060
00061
00062
00063
00064 }
00065
00066
00067
00068 void
00069 xQGanttListViewPort::barViewResized()
00071 {
00072 printf("xQGanttListViewPort::barViewResized()\n");
00073
00074 static int _h = 0;
00075
00076 int h = _barviewport->height();
00077
00078 if(h!=_h) {
00079 _h = h;
00080 resize(_width, _h);
00081 }
00082
00083 }
00084
00085
00086
00087 void
00088 xQGanttListViewPort::drawContents(QPainter* p, int x1, int y1, int x2, int y2)
00090 {
00091
00092
00093
00094
00095 _ListViewCounter = 0;
00096
00097 if(_barviewport) {
00098 drawItem(_toplevelitem, p, QRect(x1, y1, x2-x1, y2-y1), 5 );
00099 }
00100
00101 }
00102
00103
00104
00105 void
00106 xQGanttListViewPort::drawItem(KGanttItem* item, QPainter* p, const QRect& rect,
00107 int offsetX )
00109 {
00110 static int margin = 2;
00111
00112 xQTaskPosition* tpos = _barviewport->_gItemList[item];
00113
00114 if(!tpos) return;
00115
00116 if( (tpos->_screenY+5 >= rect.y() &&
00117 tpos->_screenY-5 <= rect.y() + rect.height()) ||
00118 ((tpos->_screenY + tpos->_screenH)+5 >= rect.y() &&
00119 (tpos->_screenY + tpos->_screenH)-5 <= rect.y() + rect.height() ) ) {
00120
00121 p->setPen(QPen(QColor(black)));
00122
00123 int y = tpos->_screenY;
00124 int h = tpos->_screenH;
00125
00126 if(tpos->_nr % 2 == 0)
00127 p->fillRect(0 + margin, y + margin ,
00128 _width - 2 * margin, h - 2 * margin, brush1);
00129 else
00130 p->fillRect(0 + margin, y + margin,
00131 _width - 2* margin, h - 2* margin, brush2);
00132
00133 QString str = item->getText() + " [" +
00134 item->getStart().toString() + " / " +
00135 item->getEnd().toString() + "]";
00136
00137 p->drawText(offsetX, tpos->_textPosY, str );
00138
00139 }
00140
00141
00142 if(item->isOpen() && item->getSubItems().count()>0) {
00143
00144 for(KGanttItem* subitem = item->getSubItems().first();
00145 subitem != 0;
00146 subitem = item->getSubItems().next() ) {
00147
00148 drawItem(subitem, p, rect, offsetX + 20);
00149
00150 }
00151
00152 p->setPen(QPen(QColor(blue),2));
00153 p->drawLine(offsetX + 3, tpos->_textPosY + 3,
00154 offsetX + 3, tpos->_screenY + tpos->_screenHS - 3);
00155
00156 }
00157
00158 }
00159
00160
00161 void
00162 xQGanttListViewPort::update(int x1, int y1, int x2, int y2)
00164 {
00165 QPainter p(this);
00166
00167
00168
00169
00170
00171 drawContents(&p, x1, y1, x2, y2);
00172
00173 }
00174
00175 #include "xQGanttListViewPort.moc"