kdgantt

KDGanttViewSubwidgets.h
1/*
2 $Id: KDGanttViewSubwidgets.h 516548 2006-03-07 14:58:04Z danders $
3 KDGantt - a multi-platform charting engine
4*/
5
6/****************************************************************************
7 ** Copyright (C) 2002-2004 Klarälvdalens Datakonsult AB. All rights reserved.
8 **
9 ** This file is part of the KDGantt library.
10 **
11 ** This file may be distributed and/or modified under the terms of the
12 ** GNU General Public License version 2 as published by the Free Software
13 ** Foundation and appearing in the file LICENSE.GPL included in the
14 ** packaging of this file.
15 **
16 ** Licensees holding valid commercial KDGantt licenses may use this file in
17 ** accordance with the KDGantt Commercial License Agreement provided with
18 ** the Software.
19 **
20 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
21 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22 **
23 ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
24 ** information about KDGantt Commercial License Agreements.
25 **
26 ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
27 ** licensing are not clear to you.
28 **
29 ** As a special exception, permission is given to link this program
30 ** with any edition of TQt, and distribute the resulting executable,
31 ** without including the source code for TQt in the source distribution.
32 **
33 **********************************************************************/
34
35
36#ifndef KDGANTTVIEWSUBWIDGETS_H
37#define KDGANTTVIEWSUBWIDGETS_H
38
39
40#include <tqwidget.h>
41#include <tqlistview.h>
42#include <tqsplitter.h>
43#include <tqevent.h>
44#include <tqvaluelist.h>
45#include <tqcanvas.h>
46#include <tqwhatsthis.h>
47#include <tqpopupmenu.h>
48#include <tqtooltip.h>
49#include <tqtimer.h>
50#include <tqgroupbox.h>
51#include <tqvgroupbox.h>
52#include <tqlayout.h>
53#include <tqlabel.h>
54#include <tqbrush.h>
55#include <tqvbox.h>
56#include <tqdockwindow.h>
57#include <tqtimer.h>
58
59#include "KDGanttView.h"
60#include "KDGanttViewTaskLink.h"
61#include "KDGanttViewTaskLinkGroup.h"
62#include "KDGanttViewSummaryItem.h"
63#include "KDGanttSemiSizingControl.h"
64#include "KDGanttViewItemDrag.h"
65
66#define Type_is_KDGanttGridItem 1
67#define Type_is_KDGanttViewItem 2
68#define Type_is_KDGanttTaskLink 3
69
70class KDCanvasWhatsThis;
71class KDToolTip;
72class KDCanvasRectangle;
73class KDTimeHeaderToolTip;
74
75class KDTimeHeaderWidget : public TQWidget
76{
77 TQ_OBJECT
78
79
80public:
81 typedef KDGanttView::Scale Scale;
82 typedef KDGanttView::YearFormat YearFormat;
83 typedef KDGanttView::HourFormat HourFormat;
84 struct DateTimeColor {
85 TQDateTime datetime;
86 TQDateTime end;
87 TQColor color;
88 Scale minScaleView;
89 Scale maxScaleView;
90 //KDCanvasLine* canvasLine;
91 KDCanvasRectangle* canvasRect;
92 };
93 typedef TQValueList<DateTimeColor> ColumnColorList;
94 typedef TQValueList<DateTimeColor> IntervalColorList;
95 /*
96 enum Scale { Minute, Hour, Day, Week, Month, Auto };
97 enum YearFormat { FourDigit, TwoDigit, TwoDigitApostrophe };
98 enum HourFormat { Hour_24, Hour_12 };
99 */
100
101 KDTimeHeaderWidget (TQWidget* parent,KDGanttView* gant);
102 ~KDTimeHeaderWidget();
103
104 TQString getToolTipText(TQPoint p);
105 void zoomToFit();
106 void zoom(double, bool absolute = true);
107 void zoomToSelection( TQDateTime startTime, TQDateTime endTime);
108 double zoomFactor();
109 void setAutoScaleMinorTickCount( int count );
110 int autoScaleMinorTickCount();
111 void setHorizonStart( const TQDateTime& start );
112 TQDateTime horizonStart() const;
113 void setHorizonEnd( const TQDateTime& start );
114 TQDateTime horizonEnd() const;
115
116 void setMaximumScale( Scale );
117 KDTimeHeaderWidget::Scale maximumScale() const;
118 void setMinimumScale( Scale );
119 KDTimeHeaderWidget::Scale minimumScale() const;
120 KDTimeHeaderWidget::Scale scale() const;
121 void setMajorScaleCount( int count );
122 int majorScaleCount() const;
123 void setMinorScaleCount( int count );
124 int minorScaleCount() const;
125 void setMinimumColumnWidth( int width );
126 int minimumColumnWidth() const;
127 void setYearFormat( YearFormat format );
128 KDTimeHeaderWidget::YearFormat yearFormat() const;
129 void setHourFormat( HourFormat format );
130 KDTimeHeaderWidget::HourFormat hourFormat() const;
131 void setShowMajorTicks( bool );
132 bool showMajorTicks() const;
133 void setShowMinorTicks( bool );
134 void setScale( Scale unit);
135 bool showMinorTicks() const;
136 void setColumnBackgroundColor( const TQDateTime& column,
137 const TQColor& color,
138 Scale mini = KDGanttView::Minute ,
139 Scale maxi = KDGanttView::Month);
140 void setIntervalBackgroundColor( const TQDateTime& start,
141 const TQDateTime& end,
142 const TQColor& color,
143 Scale mini = KDGanttView::Minute ,
144 Scale maxi = KDGanttView::Month);
145 bool changeBackgroundInterval( const TQDateTime& oldstart,
146 const TQDateTime& oldend,
147 const TQDateTime& newstart,
148 const TQDateTime& newend );
149 bool deleteBackgroundInterval( const TQDateTime& start,
150 const TQDateTime& end );
151 void clearBackgroundColor();
152 TQColor columnBackgroundColor( const TQDateTime& column ) const;
153 void setWeekendBackgroundColor( const TQColor& color );
154 TQColor weekendBackgroundColor() const;
155 void setWeekdayBackgroundColor( const TQColor& color, int weekday );
156 TQColor weekdayBackgroundColor(int weekday) const;
157 void setWeekendDays( int start, int end );
158 void weekendDays( int& start, int& end ) const;
159 void computeTicks(bool doNotComputeRealScale = false);
160 void paintEvent(TQPaintEvent *);
161 int getCoordX(TQDate);
162 int getCoordX(TQDateTime);
163 TQDateTime getDateTimeForIndex(int coordX, bool local = true );
164 void setShowPopupMenu( bool show, bool showZoom, bool showScale,bool showTime,
165 bool showYear,bool showGrid, bool showPrint);
166 bool registerStartTime();
167 bool registerEndTime();
168 bool showPopupMenu() const;
169 ColumnColorList columnBackgroundColorList() const {
170 return ccList;
171 }
172 TQColor weekdayColor[8];
173 void repaintMe(int left, int wid, TQPainter *p = 0);
174
175 void centerDateTime( const TQDateTime& center );
176
177public slots:
178 void setSettings(int);
179 void checkWidth( int );
180 void addTickRight( int num = 1 );
181 void addTickLeft( int num = 1 );
182 void preparePopupMenu();
183signals:
184 void sizeChanged( int );
185
186private:
187 friend class KDTimeTableWidget;
188 friend class KDGanttViewItem;
189 friend class KDGanttView;
190 virtual void mousePressEvent ( TQMouseEvent * e );
191 virtual void mouseReleaseEvent ( TQMouseEvent * e );
192 virtual void mouseDoubleClickEvent ( TQMouseEvent * e );
193 virtual void mouseMoveEvent ( TQMouseEvent * e );
194 double secsFromTo( TQDateTime begin, TQDateTime end );
195 void updateTimeTable();
196 void computeIntervals( int height );
197 bool getColumnColor(TQColor& col,int coordLow, int coordHigh);
198 void moveTimeLineTo(int x);
199 //void mousePressEvent ( TQMouseEvent * ) ;
200 void resizeEvent ( TQResizeEvent * ) ;
201 TQValueList<int> majorTicks;
202 TQValueList<TQString> minorText;
203 TQValueList<TQString> majorText;
204 TQDateTime myHorizonStart, myHorizonEnd, myRealEnd,myRealStart;
205 TQDateTime myCenterDateTime;
206 void saveCenterDateTime();
207 Scale myScale,myRealScale,myMaxScale,myMinScale;
208 YearFormat myYearFormat;
209 HourFormat myHourFormat;
210 int myMinimumColumWidth;
211 bool flagShowMajorTicks, flagShowMinorTicks, flagShowPopupMenu;
212 bool flagShowZoom, flagShowScale ,flagShowTime ,flagShowYear;
213 bool flagShowGrid ,flagShowPrint;
214 bool flagStartTimeSet,flagEndTimeSet;
215 TQColor myWeekendBackgroundColor;
216 int myWeekendDaysStart, myWeekendDaysEnd;
217 ColumnColorList ccList;
218 IntervalColorList icList;
219 int myMinorScaleCount,myMajorScaleCount;
220 int myRealMinorScaleCount,myRealMajorScaleCount;
221 bool flagDoNotRecomputeAfterChange,flagDoNotRepaintAfterChange;
222 TQString getYear(TQDate);
223 TQString getHour(TQTime);
224 TQDateTime getEvenTimeDate(TQDateTime ,Scale);
225 void computeRealScale(TQDateTime start);
226 int myGridMinorWidth;
227 int myMajorGridHeight;
228 TQPopupMenu * myPopupMenu, *scalePopupMenu, *timePopupMenu;
229 TQPopupMenu * yearPopupMenu, *gridPopupMenu;
230 KDGanttView* myGanttView;
231 double myZoomFactor;
232 int myAutoScaleMinorTickcount;
233 bool flagZoomToFit;
234 int mySizeHint;
235 int myMinimumWidth;
236 int getTickTime();
237 KDTimeHeaderToolTip* myToolTip;
238 bool mouseDown;
239 int beginMouseDown;
240 int endMouseDown;
241 bool autoComputeTimeLine;
242 TQPixmap paintPix;
243};
244
245/* KDTimeTableWidget */
246class KDListView ;
247
248class KDTimeTableWidget : public TQCanvas
249{
250 TQ_OBJECT
251
252
253public:
254 KDTimeTableWidget (TQWidget* parent,KDGanttView* my);
255
256 void setBlockUpdating( bool block = true );
257 bool blockUpdating();
258 void inc_blockUpdating();
259 void dec_blockUpdating();
260 void setShowTaskLinks( bool show );
261 bool showTaskLinks();
262 TQPtrList<KDGanttViewTaskLink>taskLinks();
263 void clearTaskLinks();
264 void updateMyContent();
265 void removeItemFromTasklinks( KDGanttViewItem * );
266 void setHorBackgroundLines( int count, TQBrush brush );
267 int horBackgroundLines( TQBrush& brush );
268
269 void setNoInformationBrush( const TQBrush& brush );
270 TQBrush noInformationBrush() const;
271
272 int getCoordX( TQDateTime dt );
273
274signals:
275 void heightComputed( int );
276
277public slots:
278 void expandItem(TQListViewItem * );
279 void collapseItem(TQListViewItem * );
280 void highlightItem(TQListViewItem * );
281 void resetWidth( int );
282 void checkHeight( int );
283private:
284 friend class KDGanttViewTaskLink;
285 friend class KDTimeHeaderWidget;
286 friend class KDGanttView;
287 friend class KDGanttViewTaskItem;
288 KDGanttView* myGanttView;
289
290 bool taskLinksVisible;
291
292 TQPtrList<KDGanttViewTaskLink> myTaskLinkList;
293
294 TQPtrList<KDCanvasLine> verGridList;
295 TQPtrList<KDCanvasLine> horGridList;
296 TQPtrList<KDCanvasRectangle> horDenseList;
297 TQPtrList<KDCanvasRectangle> showNoInfoList;
298 int denseLineCount;
299 TQBrush denseLineBrush, noInfoLineBrush;
300 TQPtrList<KDCanvasRectangle> columnColorList;
301
302 int computeHeight();
303 void computeVerticalGrid();
304 void computeHorizontalGrid();
305 void computeDenseLines();
306 void computeShowNoInformation();
307 void computeTaskLinks();
308 void computeMinorGrid();
309 void computeMajorGrid();
310
311 void showMajorGrid();
312 void showMinorGrid();
313 void hideGrid();
314
315 TQPen gridPen;
316 int maximumComputedGridHeight;
317 int minimumHeight;
318 int int_blockUpdating;
319 bool flag_blockUpdating;
320 int pendingHeight;
321 int pendingWidth;
322
323};
324
325class KDLegendWidget : public KDGanttSemiSizingControl
326{
327 TQ_OBJECT
328
329
330public:
331 KDLegendWidget ( TQWidget* parent, KDGanttMinimizeSplitter* legendParent );
332 void showMe(bool);
333 bool isShown();
334 void addLegendItem( KDGanttViewItem::Shape shape, const TQColor& shapeColor, const TQString& text );
335 void clearLegend();
336 void setFont( TQFont );
337 void drawToPainter( TQPainter *p );
338 void setAsDoctwindow( bool dockwin );
339 bool asDoctwindow();
340 TQDockWindow* dockwindow();
341 TQSize legendSize();
342 TQSize legendSizeHint();
343 private:
344 TQGroupBox * myLegend;
345 TQLabel* myLabel;
346 TQScrollView * scroll;
347 TQDockWindow* dock;
348 KDGanttMinimizeSplitter* myLegendParent;
349};
350
351class KDGanttView;
352class KDListView : public TQListView
353{
354 TQ_OBJECT
355
356
357public:
358 KDListView (TQWidget* parent,KDGanttView* gv );
359 KDGanttView* myGanttView;
360 void drawToPainter( TQPainter *p, bool drawHeader=false );
361 void setCalendarMode( bool mode );
362 bool calendarMode() { return _calendarMode; };
363 TQString getWhatsThisText(TQPoint p);
364 void setOpen ( TQListViewItem * item, bool open );
365 void dragEnterEvent ( TQDragEnterEvent * );
366 void dragMoveEvent ( TQDragMoveEvent * );
367 void dragLeaveEvent ( TQDragLeaveEvent * );
368 void dropEvent ( TQDropEvent * );
369 TQDragObject * dragObject ();
370 void startDrag ();
371 void paintemptyarea ( TQPainter * p, const TQRect & rect ){ TQListView::paintEmptyArea( p, rect );};
372
373public:
374 class DrawableItem {
375 public:
376 DrawableItem(int level, int ypos, TQListViewItem *item ) { y = ypos; l = level; i = item; };
377 int y;
378 int l;
379 TQListViewItem * i;
380 };
381protected:
382 void drawAllContents(TQPainter * p, int cx, int cy, int cw, int ch);
383 int buildDrawables(TQPtrList<KDListView::DrawableItem> &lst, int level, int ypos, TQListViewItem *item, int ymin, int ymax) const;
384
385private slots:
386 void dragItem( TQListViewItem * );
387 private:
388 void resizeEvent ( TQResizeEvent * ) ;
389 void contentsMouseDoubleClickEvent ( TQMouseEvent * e );
390 bool _calendarMode;
391
392
393
394};
395
396
397class KDCanvasText : public TQCanvasText
398{
399public:
400 KDCanvasText( KDTimeTableWidget* canvas, void* parentItem, int type );
401 int myParentType;
402 void* myParentItem;
403};
404
405
406class KDCanvasLine : public TQCanvasLine
407{
408public:
409 KDCanvasLine( KDTimeTableWidget* canvas, void* parentItem, int type );
410 int myParentType;
411 void* myParentItem;
412};
413
414
415class KDCanvasPolygonItem: public TQCanvasPolygonalItem
416{
417public:
418 KDCanvasPolygonItem( KDTimeTableWidget* canvas, void* parentItem,
419 int type );
420 int myParentType;
421 void* myParentItem;
422};
423
424
425class KDCanvasPolygon: public TQCanvasPolygon
426{
427public:
428 KDCanvasPolygon( KDTimeTableWidget* canvas, void* parentItem, int type );
429 int myParentType;
430 void* myParentItem;
431};
432
433
434class KDCanvasEllipse: public TQCanvasEllipse
435{
436public:
437 KDCanvasEllipse( KDTimeTableWidget* canvas, void* parentItem, int type );
438 int myParentType;
439 void* myParentItem;
440};
441
442
443class KDCanvasRectangle: public TQCanvasRectangle
444{
445public:
446 KDCanvasRectangle( KDTimeTableWidget* canvas, void* parentItem, int type );
447 int myParentType;
448 void* myParentItem;
449};
450
451
452class KDCanvasToolTip;
453
454class KDGanttCanvasView : public TQCanvasView
455{
456 TQ_OBJECT
457
458
459public:
460 KDGanttCanvasView(KDGanttView* sender, TQCanvas* canvas = 0, TQWidget* parent = 0, const char* name = 0 );
461 ~KDGanttCanvasView();
462 TQString getToolTipText(TQPoint p);
463 TQString getWhatsThisText(TQPoint p);
464 void drawToPainter ( TQPainter * p );
465 void resetCutPaste( KDGanttViewItem* );
466 void setShowPopupMenu( bool show );
467 bool showPopupMenu();
468 void cutItem ( KDGanttViewItem* );
469 void insertItemAsRoot( KDGanttViewItem* );
470 void insertItemAsChild( KDGanttViewItem* , KDGanttViewItem* );
471 void insertItemAfter( KDGanttViewItem* , KDGanttViewItem* );
472protected:
473 friend class KDGanttView;
474 friend class KDListView;
475 virtual void contentsMousePressEvent ( TQMouseEvent * ) ;
476 virtual void contentsMouseReleaseEvent ( TQMouseEvent * );
477 virtual void contentsMouseDoubleClickEvent ( TQMouseEvent * );
478 virtual void contentsMouseMoveEvent ( TQMouseEvent * ) ;
479 virtual void viewportPaintEvent ( TQPaintEvent * pe );
480 void resizeEvent ( TQResizeEvent * ) ;
481 void set_MouseTracking(bool on);
482 KDGanttView* mySignalSender;
483 KDGanttViewItem* currentItem, *lastClickedItem, *cuttedItem;
484 KDGanttViewTaskLink* currentLink;
485 int getType(TQCanvasItem*);
486 KDGanttViewItem* getItem(TQCanvasItem*);
487 KDGanttViewTaskLink* getLink(TQCanvasItem*);
488 KDCanvasWhatsThis* myWhatsThis;
489 TQPopupMenu* onItem;
490 bool _showItemAddPopupMenu;
491 int myMyContentsHeight;
492 KDGanttViewItem *fromItem;
493 bool linkItemsEnabled;
494 TQCanvasLine *linkLine;
495 int fromArea;
496 bool autoScrollEnabled;
497 int getItemArea(KDGanttViewItem *item, int x);
498 int getLinkType(int from, int to);
499
500signals:
501 void heightResized( int );
502 void widthResized( int );
503public slots:
504 void set_Mouse_Tracking(bool on);
505 void moveMyContent( int, int );
506 void setMyContentsHeight( int );
507 void updateHorScrollBar();
508private slots:
509 void cutItem();
510 void pasteItem( int );
511 void newRootItem( int );
512 void newChildItem( int );
513 void slotScrollTimer();
514 void myUpdateScrollBars();
515
516private:
517 KDCanvasToolTip* myToolTip;
518 TQTimer *myScrollTimer;
519 TQPoint mousePos;
520 TQTimer scrollBarTimer;
521};
522
523class KDTimeHeaderToolTip :public TQToolTip
524{
525
526public:
527 KDTimeHeaderToolTip( TQWidget *wid, KDTimeHeaderWidget* header ) : TQToolTip( wid ), _wid(wid),_header (header) {
528
529};
530
531protected:
532 virtual void maybeTip( const TQPoint& p)
533 {
534 static bool ishidden = true;
535 if (TQToolTip::isGloballyEnabled () ) {
536 if (ishidden) {
537 tip( TQRect( p.x(),p.y(),5,5), _header->getToolTipText(p));
538 }
539 else
540 hide();
541 ishidden = !ishidden;
542 }
543 }
544private:
545 TQWidget* _wid;
546 KDTimeHeaderWidget * _header;
547};
548
549class KDCanvasToolTip :public TQToolTip
550{
551
552public:
553 KDCanvasToolTip( TQWidget *wid, KDGanttCanvasView* canview ) : TQToolTip( wid ), _wid(wid),_canview (canview) {
554
555};
556
557protected:
558 virtual void maybeTip( const TQPoint& p)
559 {
560 static bool ishidden = true;
561 if (TQToolTip::isGloballyEnabled () ) {
562 if (ishidden) {
563 tip( TQRect( p.x()-2,p.y()-2,5,5), _canview->getToolTipText(p));
564 }
565 else
566 hide();
567 ishidden = !ishidden;
568 }
569 }
570private:
571 TQWidget* _wid;
572 KDGanttCanvasView * _canview;
573};
574
575class KDCanvasWhatsThis :public TQWhatsThis
576{
577public:
578 KDCanvasWhatsThis( TQWidget *wid, KDGanttCanvasView* canview ) : TQWhatsThis( wid ), _wid(wid),_canview (canview) { };
579
580protected:
581 virtual TQString text( const TQPoint& p)
582 {
583 return _canview->getWhatsThisText(p) ;
584 }
585private:
586 TQWidget* _wid;
587 KDGanttCanvasView * _canview;
588};
589
590class KDListViewWhatsThis :public TQWhatsThis
591{
592public:
593 KDListViewWhatsThis( TQWidget *wid, KDListView* view ) : TQWhatsThis( wid ), _wid(wid),_view (view) { };
594
595protected:
596 virtual TQString text( const TQPoint& p)
597 {
598 return _view->getWhatsThisText(p) ;
599 }
600private:
601 TQWidget* _wid;
602 KDListView * _view;
603};
604
605
606
607#endif
The KDGanttMinimizeSplitter class implements a splitter widget with minimize buttons.