kplato

kptcanvasitem.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 - 2004 Dag Andersen <danders@get2net.dk>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation;
00007    version 2 of the License.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef KPTCANVASITEM_H
00021 #define KPTCANVASITEM_H
00022 
00023 #include "kptnode.h"
00024 #include "KDGanttView.h"
00025 #include "KDGanttViewItem.h"
00026 #include "KDGanttViewSummaryItem.h"
00027 #include "KDGanttViewTaskItem.h"
00028 #include "KDGanttViewEventItem.h"
00029 
00030 #include <qcanvas.h>
00031 #include <qrect.h>
00032 
00033 class QPainter;
00034 
00035 namespace KPlato
00036 {
00037 
00038 class Task;
00039 class Relation;
00040 class PertCanvas;
00041 class PertRelationItem;
00042 class PertNodeItem;
00043 class GanttView;
00044 
00045 class PertNodeItem : public QCanvasPolygon
00046 {
00047 private:
00048     class PertNodeRelation
00049     {
00050     public:
00051         PertNodeRelation(Relation *r, PertNodeItem *n) { relation = r; childItem = n; }
00052         ~PertNodeRelation() {}
00053         Relation *relation;
00054         PertNodeItem * childItem;
00055     };
00056 
00057 public:
00058     PertNodeItem( PertCanvas *view, Node &node, int row, int col );
00059     virtual ~PertNodeItem();
00060 
00061     virtual int rtti() const;
00062     static int RTTI;
00063 
00064     void setVisible(bool yes);
00065     void move(PertCanvas *view, int row, int col);
00066 
00067     QPoint exitPoint(Relation::Type type) const;
00068     QPoint entryPoint(Relation::Type type) const;
00069 
00070     Node &node() const { return m_node; }
00071 
00072     QRect rect() const { return QRect(m_left, m_right); }
00073     void setRow(int row) { m_row = row; }
00074     int row() const { return m_row; }
00075     void setColumn(int col) { m_col = col; }
00076     int column() const { return m_col; }
00077     int x() const { return m_x; }
00078     int x(int col) const { return m_wgap + col*(m_width+m_wgap); }
00079     int y() const { return m_y; }
00080     int y(int row) const { return m_hgap + row*(m_height+m_hgap); }
00081     int width() const { return m_width; }
00082     int height() const { return m_height; }
00083 
00084     void addChildRelation(Relation *relation, PertNodeItem *node)
00085         { m_childRelations.append(new PertNodeRelation(relation, node)); }
00086 
00087     bool hasParent() { return m_node.numDependParentNodes(); }
00088     bool hasChild() { return m_node.numDependChildNodes(); }
00089 
00090 protected:
00091     void drawShape(QPainter & p);
00092 
00093     int m_wgap;
00094     int m_hgap;
00095     int m_width;
00096     int m_height;
00097     int m_x;
00098     int m_y;
00099 
00100     QPtrList<PertNodeRelation> m_childRelations;
00101 
00102 private:
00103     Node &m_node;
00104     int m_row, m_col;
00105     QPoint m_right; // Entry/exit point
00106     QPoint m_left;  // Entry/exit point
00107     QCanvasText *m_name;
00108     QCanvasText *m_leader;
00109 
00110 #ifndef NDEBUG
00111     void printDebug( int );
00112 #endif
00113 
00114 };
00115 
00116 class PertProjectItem : public PertNodeItem
00117 {
00118 public:
00119     PertProjectItem( PertCanvas *view, Node &node, int row=-1, int col=-1 );
00120     virtual ~PertProjectItem();
00121 
00122     virtual int rtti() const;
00123     static int RTTI;
00124 
00125 #ifndef NDEBUG
00126     void printDebug( int );
00127 #endif
00128 
00129 };
00130 
00131 class PertTaskItem : public PertNodeItem
00132 {
00133 public:
00134     PertTaskItem( PertCanvas *view, Node &node, int row=-1, int col=-1 );
00135     virtual ~PertTaskItem();
00136 
00137     virtual int rtti() const;
00138     static int RTTI;
00139 
00140 #ifndef NDEBUG
00141     void printDebug( int );
00142 #endif
00143 
00144 };
00145 
00146 class PertMilestoneItem : public PertNodeItem
00147 {
00148 public:
00149     PertMilestoneItem( PertCanvas *view, Node &node, int row=-1, int col=-1 );
00150     virtual ~PertMilestoneItem();
00151 
00152     virtual int rtti() const;
00153     static int RTTI;
00154 
00155     void draw();
00156 
00157 #ifndef NDEBUG
00158     void printDebug( int );
00159 #endif
00160 
00161 };
00162 
00164 
00165 class PertRelationItem : public QCanvasPolygon
00166 {
00167 public:
00168     PertRelationItem(PertCanvas *view, PertNodeItem *parent, PertNodeItem *child, Relation *rel);
00169     virtual ~PertRelationItem();
00170 
00171     virtual int rtti() const;
00172     static int RTTI;
00173 
00174     Relation::Type type() { return m_rel->type(); }
00175     void draw();
00176 
00177     void setFinishStartPoints();
00178     void setFinishFinishPoints();
00179     void setStartStartPoints();
00180     QPointArray areaPoints() const;
00181 
00182     bool rowFree(int row, int startCol, int endCol);
00183 
00184 protected:
00185     void drawShape(QPainter &p);
00186 
00187 private:
00188     PertCanvas *m_view;
00189     Relation *m_rel;
00190     PertNodeItem *m_parentItem;
00191     PertNodeItem *m_childItem;
00192     int left, top, right, bottom;
00193 
00194     int parentTop;
00195     int parentBottom;
00196     int childTop;
00197 
00198     int childRow;
00199     int childCol;
00200     int parentRow;
00201     int parentCol;
00202 
00203     int wgap;
00204     int hgap;
00205 
00206 
00207 #ifndef NDEBUG
00208     void printDebug( int );
00209 #endif
00210 
00211 };
00212 
00213 class ItemBase
00214 {
00215 protected:
00216     KDGanttViewTaskLink::LinkType kdLinkType(int relationType);
00217 };
00218 
00219 
00221 
00222 class GanttViewSummaryItem : public KDGanttViewSummaryItem, public ItemBase
00223 {
00224 public:
00225     GanttViewSummaryItem(KDGanttView *parent, Node *node);
00226     GanttViewSummaryItem(KDGanttViewItem *parent, Node *node);
00227 
00228     Node *getNode() { return m_node; }
00229     void insertRelations(GanttView *view);
00230     KDGanttViewItem *find(Node *node);
00231     KDGanttViewItem *find(KDGanttViewItem *item, Node *node);
00232     KDGanttView *ganttView() const { return m_view; }
00233     bool isDrawn() const { return m_drawn; }
00234     void setDrawn(bool drawn) { m_drawn = drawn; }
00235 
00236 protected:
00237     Node *m_node;  // can be Project or Task
00238     KDGanttView *m_view;
00239     bool m_drawn;
00240 };
00241 
00243 
00244 class GanttViewTaskItem : public KDGanttViewTaskItem, public ItemBase
00245 {
00246 public:
00247     GanttViewTaskItem(KDGanttView *parent, KPlato::Task *task);
00248     GanttViewTaskItem(KDGanttViewItem *parent, KPlato::Task *task);
00249 
00250     KPlato::Task *getTask() const { return m_task; }
00251     void insertRelations(GanttView *view);
00252     KDGanttViewItem *find(Node *node);
00253     KDGanttViewItem *find(KDGanttViewItem *item, Node *node);
00254     KDGanttView *ganttView() const { return m_view; }
00255     bool isDrawn() const { return m_drawn; }
00256     void setDrawn(bool drawn) { m_drawn = drawn; }
00257     
00258 protected:
00259     KPlato::Task *m_task;
00260     KDGanttView *m_view;
00261     bool m_drawn;
00262 };
00263 
00265 
00266 class GanttViewEventItem : public KDGanttViewEventItem, public ItemBase
00267 {
00268 public:
00269     GanttViewEventItem(KDGanttView *parent, KPlato::Task *task);
00270     GanttViewEventItem(KDGanttViewItem *parent, KPlato::Task *task);
00271 
00272     KPlato::Task *getTask() { return m_task; }
00273     void insertRelations(GanttView *view);
00274     KDGanttViewItem *find(Node *node);
00275     KDGanttViewItem *find(KDGanttViewItem *item, Node *node);
00276     KDGanttView *ganttView() const { return m_view; }
00277     bool isDrawn() const { return m_drawn; }
00278     void setDrawn(bool drawn) { m_drawn = drawn; }
00279     
00280 protected:
00281     KPlato::Task *m_task;
00282     KDGanttView *m_view;
00283     bool m_drawn;
00284 };
00285 
00286 }  //KPlato namespace
00287 
00288 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys