summaryrefslogtreecommitdiffstats
path: root/kgantt/kgantt/KGanttItem.h
blob: b64c73392fcc240a8d33d9c057a409cf44a9bc52 (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
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
#ifndef _KGANTTITEM_H_
#define _KGANTTITEM_H_
 
/*

    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; either
    version 2 of the License, or (at your option) any later version.

    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.

    author  : jh, jochen@ifb.bv.tu-berlin.de

    file    : KGanttItem.h
    date    : 26 oct 2000


    changelog : 26 dec 2000, jh
                09 jan 2001, jh - added signal destroyed(xTQTask*)

		11 jan 2001, jh changed to kde : xTQTask -> KGanttItem

*/


#include <tqobject.h>
#include <tqdatetime.h> 
#include <tqtextstream.h> 
#include <tqptrlist.h> 
#include <tqpainter.h>

#include <kdepimmacros.h>

#include "KGanttRelation.h"



///  KGanttItem.
/*!
 *   This class describes a item. It contains dates on which the item starts and
 *   ends. It also contains attributes that gouverns the graphical representation
 *   in a gantt diagramm.
 */
//////////////////////////////////
class KDE_EXPORT KGanttItem : public TQObject
//////////////////////////////////
{

  Q_OBJECT
  TQ_OBJECT


public:
  
  enum Change { 
    NoChange        = 0,
    StartChanged    = 1,
    EndChanged      = 2,
    
    ///  Height for this item has changed. The
    ///  height doesn't include the subitems.
    HeightChanged   = 4,
    
    ///  Total height has changed. This 
    ///  happens if the item was opened, closed
    ///  or subitems has been added or removed while
    ///  item is open.
    TotalHeightChanged = 8,
    
    ///  Style for drawing has changed.
    StyleChanged    = 16,
    TextChanged     = 32,
    ModeChanged     = 64,
    MinChanged      = 128,
    MaxChanged      = 256,
    
    /// Draw item including subitems.
    Opened          = 512,
    
    /// Draw item without subitems.
    Closed          = 1024,
    
    ///  Item has been selected.
    Selected        = 2048,
    
    ///  Item has been unselected.
    Unselected      = 4096,
    
    ///  Changes may occurred but the types are unknown
    Unknown         = 8192,

    ///  Relation between two subitems has been added
    RelationAdded   = 16384,

    /// Relation between two subitems has been removed
    RelationRemoved = 32768

  };



  enum Style {
    /// Set item invisible
    DrawNothing     = 0,
    
    /// Draw border.
    DrawBorder      = 1, 
    
    //  Fill item with brush.
    DrawFilled      = 2, 
    DrawText        = 4,
    
    //  Draw handlke for opening/closing item.
    DrawHandle      = 16,
    
    /// Draw handle only if item contains subitems
    DrawHandleWSubitems = 32,
    
    DrawAll         = 255 
  };


  enum Mode { 
    Normal, 
    Rubberband 
  };


  ///  Constructor.
  /*!
   * 
   */
  KGanttItem(KGanttItem* parentItem, const TQString& text, 
	 const TQDateTime& start, const TQDateTime& end);



  ///  Constructor.
  /*!
   * 
   */
  KGanttItem(KGanttItem* parentItem, const TQString& text, 
	 const TQDateTime& start, long durationMin);



  ///   Destructor.
  /*
   *    Emits signal destroyed(KGanttItem* this).
   */
  ~KGanttItem();



  ///   Add relation between two subitems.
  /*
   *
   */
  KGanttRelation* addRelation(KGanttItem* from, KGanttItem* to,
			      const TQString& text);



 
  ///  Returns true if item is open (subitems has to be drawn)
  /*!
   *
   */
  bool isOpen() {
    return _open;
  }



  ///  Open / Close item
  /*!
   *   Draw/don't draw subitems.
   */
  void open(bool f);



  ///  Set item editable or not.
  /*!
   *   If item is not editable these methods have no effect :
   *   setStart(), setEnd(), setText(), select(), setMode(), setStyle(), 
   *   setHeight(),
   *   
   */
  void setEditable(bool f) {
    _editable = f;
  }



  ///  Returns if item is editable.
  /*!
   *   See also setEditable().
   */
  bool isEditable() {
    return _editable;
  }



  ///  Returns true if item is selected.
  /*!
   *
   */
  bool isSelected() {
    return _selected;
  }



  ///  Select/unselect item.
  /*!
   *
   */
  void select(bool f);



  ///  Set mode.
  /*!
   *   If mode is 'Rubberband' and the number of subtaks is greater than 0,
   *   the start and end of the item is determined by the start and end of the
   *   earliest/latest subitem. <br>
   *   Default is 'Normal'.
   */
  void setMode(Mode flag);



  ///  Set drawing style.
  /*!  
   *   
   */
  void setStyle(int flag, bool includeSubitems = false);



  ///  Get drawing style.
  /*!
   *
   */
  int getStyle() {
    return _style;
  }



  ///  Set brush for filling
  /*!
   *
   */
  void setBrush(const TQBrush& brush);



  ///  Get brush that is used for filling the item.
  /*!
   *
   */
  TQBrush& getBrush() {
    return _brush;
  }



  ///  Get brush which has to be used for drawing this item as selected.
  /*!
   *
   */
  TQBrush& getSelectBrush() {
    return _selectBrush;
  }



  ///  Set pen for border.
  /*!
   *
   */
  void setPen(const TQPen& pen);



  ///
  /*!
   *
   */
  TQPen& getPen() {
    return _pen;
  }



  ///
  /*!
   *
   */
  void setTextPen(const TQPen& pen) {
    _textPen = pen;
  }



  ///
  /*!
   *
   */
  TQPen& getTextPen() {
    return _textPen;
  }



  ///  Set text.
  /*!
   *
   */
  void setText(const TQString& text);



  ///  Get text.
  /*!
   *
   */
  TQString getText() { return _text; }
  


  ///  Get date of starting.
  /*!
   *   If mode == ´Rubberband´ and this item tqcontains
   *   subitems, start of the item is determined by the start of the
   *   earliest subitem. <br>
   */
  TQDateTime getStart();



  ///  Get date of ending.
  /*!
   *
   */
  TQDateTime getEnd();



  ///  Set time/date of start.
  /*!
   *
   */
  void setStart(const TQDateTime& start);



  ///  Set time/date of end.
  /*!
   *
   */
  void setEnd(const TQDateTime& end);



  ///  Set height.
  /*!
   *   Set height in pixel. These are scaled when this item is drawn
   *   by the barview.
   */
  void setHeight(int h);



  ///  Get height.
  /*!
   *  Returns the height in pixel of this item. This does not include the height 
   *  of any subitems; getTotalHeight() returns that if the subitems have
   *  to be drawn.
   */
  int getHeight() {
    return _height;
  }



  ///  Get total height.
  /*!
   *   Returns the total height of this object in pixel, including any 
   *   visible subitems. Notice, that the pixels are no screen pixel since
   *   the barview scales the height of a item.
   */
  int getTotalHeight();

  

  ///  Get width in minutes.
  /*!
   *   
   */
  int getWidth();



  ///  Get list of subitems.
  /*!
   *
   */
  TQPtrList<KGanttItem>& getSubItems() {
    return _subitems;
  }



  ///  Get list of relations.
  /*!
   *
   */
  TQPtrList<KGanttRelation>& getRelations() {
    return _relations;
  }



  ///  Start a transaction.
  /*!
   *   If you want to add a lot of subitems -> block signals
   */
  void startTransaction(){
    blockSignals(true);
  }



  ///  End a transaction.
  /*!
   *   If you started a transaction and all signals have been blocked
   *   by method startTransaction(), invoke endTransaction() to unblock signals.<br>
   *   Signal changed(this,Unknown) is emitted.
   */
  void endTransaction();



  ///  Return a given change as a string.
  /*!
   *
   */
  static TQString ChangeAsString(Change c);




  ///  Dump to cout.
  /*!
   *
   */
  void dump(TQTextOStream& cout, const TQString& pre);


signals:

  ///  Item has changed.
  /*!
   *   This signal is emitted if any of the items
   *   properties have been changed.
   */
  void changed(KGanttItem*, KGanttItem::Change);



  ///  Item will be deleted.
  /*!
   *   This signal will be emitted immediately before
   *   the object will be deleted.
   */
  void destroyed(KGanttItem*);



private slots:
 
  void subItemChanged(KGanttItem*, KGanttItem::Change);

  void removeRelation(KGanttRelation* rel);


private:

  void registerItem(KGanttItem* item);
  void unregisterItem(KGanttItem* item);

  void init(KGanttItem* parentItem, const TQString& text,
	    const TQDateTime& start, const TQDateTime& end);


  //  set min/max date and time according to subitems
  Change adjustMinMax();

  /*  if min < start set start to _min,
      if max > end set end to max */      
  Change adjustStartEnd();


  // is item open/closed
  bool _open;
  bool _selected;


  // is this item editable by the user, if it is false, invoking
  // of some methods has no effect
  bool _editable;

  int _height, _style, _mode;


  KGanttItem*            _parentItem;
  TQPtrList<KGanttItem>      _subitems;  
  TQPtrList<KGanttRelation>  _relations;


  // start/end date. 
  // start must always be earlier then _minDateTime
  // end must always be later then _maxDateTime
  TQDateTime _start, _end, _minDateTime, _maxDateTime;
  
  TQString _text;

  TQBrush _brush;
  TQPen _pen, _textPen;

  static TQBrush _selectBrush;
 

};

#endif