summaryrefslogtreecommitdiffstats
path: root/kplato/kptcanvasitem.h
blob: fdd5891e4c0a5e76e497dddfcca365ba1903ef65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
/* This file is part of the KDE project
   Copyright (C) 2003 - 2004 Dag Andersen <danders@get2net.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation;
   version 2 of the License.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KPTCANVASITEM_H
#define KPTCANVASITEM_H

#include "kptnode.h"
#include "KDGanttView.h"
#include "KDGanttViewItem.h"
#include "KDGanttViewSummaryItem.h"
#include "KDGanttViewTaskItem.h"
#include "KDGanttViewEventItem.h"

#include <qcanvas.h>
#include <qrect.h>

class QPainter;

namespace KPlato
{

class Task;
class Relation;
class PertCanvas;
class PertRelationItem;
class PertNodeItem;
class GanttView;

class PertNodeItem : public QCanvasPolygon
{
private:
    class PertNodeRelation
    {
    public:
        PertNodeRelation(Relation *r, PertNodeItem *n) { relation = r; childItem = n; }
        ~PertNodeRelation() {}
        Relation *relation;
        PertNodeItem * childItem;
    };

public:
    PertNodeItem( PertCanvas *view, Node &node, int row, int col );
    virtual ~PertNodeItem();

    virtual int rtti() const;
    static int RTTI;

	void setVisible(bool yes);
    void move(PertCanvas *view, int row, int col);

    QPoint exitPoint(Relation::Type type) const;
	QPoint entryPoint(Relation::Type type) const;

	Node &node() const { return m_node; }

	QRect rect() const { return QRect(m_left, m_right); }
    void setRow(int row) { m_row = row; }
	int row() const { return m_row; }
    void setColumn(int col) { m_col = col; }
	int column() const { return m_col; }
	int x() const { return m_x; }
	int x(int col) const { return m_wgap + col*(m_width+m_wgap); }
	int y() const { return m_y; }
	int y(int row) const { return m_hgap + row*(m_height+m_hgap); }
	int width() const { return m_width; }
	int height() const { return m_height; }

    void addChildRelation(Relation *relation, PertNodeItem *node)
        { m_childRelations.append(new PertNodeRelation(relation, node)); }

    bool hasParent() { return m_node.numDependParentNodes(); }
    bool hasChild() { return m_node.numDependChildNodes(); }

protected:
    void drawShape(QPainter & p);

	int m_wgap;
	int m_hgap;
	int m_width;
	int m_height;
	int m_x;
	int m_y;

    QPtrList<PertNodeRelation> m_childRelations;

private:
    Node &m_node;
    int m_row, m_col;
	QPoint m_right; // Entry/exit point
	QPoint m_left;  // Entry/exit point
	QCanvasText *m_name;
	QCanvasText *m_leader;

#ifndef NDEBUG
    void printDebug( int );
#endif

};

class PertProjectItem : public PertNodeItem
{
public:
    PertProjectItem( PertCanvas *view, Node &node, int row=-1, int col=-1 );
    virtual ~PertProjectItem();

    virtual int rtti() const;
    static int RTTI;

#ifndef NDEBUG
    void printDebug( int );
#endif

};

class PertTaskItem : public PertNodeItem
{
public:
    PertTaskItem( PertCanvas *view, Node &node, int row=-1, int col=-1 );
    virtual ~PertTaskItem();

    virtual int rtti() const;
    static int RTTI;

#ifndef NDEBUG
    void printDebug( int );
#endif

};

class PertMilestoneItem : public PertNodeItem
{
public:
    PertMilestoneItem( PertCanvas *view, Node &node, int row=-1, int col=-1 );
    virtual ~PertMilestoneItem();

    virtual int rtti() const;
    static int RTTI;

	void draw();

#ifndef NDEBUG
    void printDebug( int );
#endif

};

/////////////////   PertRelationItem   ////////////////////

class PertRelationItem : public QCanvasPolygon
{
public:
    PertRelationItem(PertCanvas *view, PertNodeItem *parent, PertNodeItem *child, Relation *rel);
    virtual ~PertRelationItem();

    virtual int rtti() const;
    static int RTTI;

    Relation::Type type() { return m_rel->type(); }
    void draw();

	void setFinishStartPoints();
	void setFinishFinishPoints();
	void setStartStartPoints();
	QPointArray areaPoints() const;

	bool rowFree(int row, int startCol, int endCol);

protected:
    void drawShape(QPainter &p);

private:
    PertCanvas *m_view;
    Relation *m_rel;
    PertNodeItem *m_parentItem;
    PertNodeItem *m_childItem;
	int left, top, right, bottom;

	int parentTop;
	int parentBottom;
	int childTop;

	int childRow;
	int childCol;
	int parentRow;
	int parentCol;

	int wgap;
	int hgap;


#ifndef NDEBUG
    void printDebug( int );
#endif

};

class ItemBase
{
protected:
    KDGanttViewTaskLink::LinkType kdLinkType(int relationType);
};


/////////////////   GanttViewSummaryItem   ////////////////////

class GanttViewSummaryItem : public KDGanttViewSummaryItem, public ItemBase
{
public:
    GanttViewSummaryItem(KDGanttView *parent, Node *node);
    GanttViewSummaryItem(KDGanttViewItem *parent, Node *node);

    Node *getNode() { return m_node; }
    void insertRelations(GanttView *view);
    KDGanttViewItem *find(Node *node);
    KDGanttViewItem *find(KDGanttViewItem *item, Node *node);
    KDGanttView *ganttView() const { return m_view; }
    bool isDrawn() const { return m_drawn; }
    void setDrawn(bool drawn) { m_drawn = drawn; }

protected:
    Node *m_node;  // can be Project or Task
    KDGanttView *m_view;
    bool m_drawn;
};

/////////////////   GanttViewTaskItem   ////////////////////

class GanttViewTaskItem : public KDGanttViewTaskItem, public ItemBase
{
public:
    GanttViewTaskItem(KDGanttView *parent, KPlato::Task *task);
    GanttViewTaskItem(KDGanttViewItem *parent, KPlato::Task *task);

    KPlato::Task *getTask() const { return m_task; }
    void insertRelations(GanttView *view);
    KDGanttViewItem *find(Node *node);
    KDGanttViewItem *find(KDGanttViewItem *item, Node *node);
    KDGanttView *ganttView() const { return m_view; }
    bool isDrawn() const { return m_drawn; }
    void setDrawn(bool drawn) { m_drawn = drawn; }
    
protected:
    KPlato::Task *m_task;
    KDGanttView *m_view;
    bool m_drawn;
};

/////////////////   GanttViewEventItem   ////////////////////

class GanttViewEventItem : public KDGanttViewEventItem, public ItemBase
{
public:
    GanttViewEventItem(KDGanttView *parent, KPlato::Task *task);
    GanttViewEventItem(KDGanttViewItem *parent, KPlato::Task *task);

    KPlato::Task *getTask() { return m_task; }
    void insertRelations(GanttView *view);
    KDGanttViewItem *find(Node *node);
    KDGanttViewItem *find(KDGanttViewItem *item, Node *node);
    KDGanttView *ganttView() const { return m_view; }
    bool isDrawn() const { return m_drawn; }
    void setDrawn(bool drawn) { m_drawn = drawn; }
    
protected:
    KPlato::Task *m_task;
    KDGanttView *m_view;
    bool m_drawn;
};

}  //KPlato namespace

#endif