kdgantt

KDGanttViewSubwidgets.h
1/*
2 $Id$
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 KDIntervalColorRectangle;
71class KDCanvasWhatsThis;
72class KDToolTip;
73class KDCanvasRectangle;
74class KDTimeHeaderToolTip;
75
76class KDTimeHeaderWidget : public TQWidget
77{
78 TQ_OBJECT
79
80
81public:
82 typedef KDGanttView::Scale Scale;
83 typedef KDGanttView::YearFormat YearFormat;
84 typedef KDGanttView::HourFormat HourFormat;
85 struct DateTimeColor {
86 TQDateTime datetime;
87 TQDateTime end;
88 TQColor color;
89 Scale minScaleView;
90 Scale maxScaleView;
91 //KDCanvasLine* canvasLine;
92 KDCanvasRectangle* canvasRect;
93 };
94 typedef TQValueList<DateTimeColor> ColumnColorList;
95 typedef TQValueList<KDIntervalColorRectangle *> IntervalColorList;
96 /*
97 enum Scale { Minute, Hour, Day, Week, Month, Auto };
98 enum YearFormat { FourDigit, TwoDigit, TwoDigitApostrophe };
99 enum HourFormat { Hour_24, Hour_12 };
100 */
101
102 KDTimeHeaderWidget (TQWidget* parent,KDGanttView* gant);
103 ~KDTimeHeaderWidget();
104
105 TQString getToolTipText(TQPoint p);
106 void zoomToFit();
107 void zoom(double, bool absolute = true);
108 void zoomToSelection( TQDateTime startTime, TQDateTime endTime);
109 double zoomFactor();
110 void setAutoScaleMinorTickCount( int count );
111 int autoScaleMinorTickCount();
112 void setHorizonStart( const TQDateTime& start );
113 TQDateTime horizonStart() const;
114 void setHorizonEnd( const TQDateTime& start );
115 TQDateTime horizonEnd() const;
116
117 void setMaximumScale( Scale );
118 KDTimeHeaderWidget::Scale maximumScale() const;
119 void setMinimumScale( Scale );
120 KDTimeHeaderWidget::Scale minimumScale() const;
121 KDTimeHeaderWidget::Scale scale() const;
122 void setMajorScaleCount( int count );
123 int majorScaleCount() const;
124 void setMinorScaleCount( int count );
125 int minorScaleCount() const;
126 void setMinimumColumnWidth( int width );
127 int minimumColumnWidth() const;
128 void setYearFormat( YearFormat format );
129 KDTimeHeaderWidget::YearFormat yearFormat() const;
130 void setHourFormat( HourFormat format );
131 KDTimeHeaderWidget::HourFormat hourFormat() const;
132 void setShowMajorTicks( bool );
133 bool showMajorTicks() const;
134 void setShowMinorTicks( bool );
135 void setScale( Scale unit);
136 bool showMinorTicks() const;
137 void setColumnBackgroundColor( const TQDateTime& column,
138 const TQColor& color,
139 Scale mini = KDGanttView::Minute ,
140 Scale maxi = KDGanttView::Month);
141#if 0
142 // This API has been replaced with KDIntervalColorRectangle and addIntervalBackgroundColor
143 void setIntervalBackgroundColor( const TQDateTime& start,
144 const TQDateTime& end,
145 const TQColor& color,
146 Scale mini = KDGanttView::Minute ,
147 Scale maxi = KDGanttView::Month);
148 bool changeBackgroundInterval( const TQDateTime& oldstart,
149 const TQDateTime& oldend,
150 const TQDateTime& newstart,
151 const TQDateTime& newend );
152 bool deleteBackgroundInterval( const TQDateTime& start,
153 const TQDateTime& end );
154#endif
155 void addIntervalBackgroundColor( KDIntervalColorRectangle* newItem );
156 void clearBackgroundColor();
157 TQColor columnBackgroundColor( const TQDateTime& column ) const;
158 void setWeekendBackgroundColor( const TQColor& color );
159 TQColor weekendBackgroundColor() const;
160 void setWeekdayBackgroundColor( const TQColor& color, int weekday );
161 TQColor weekdayBackgroundColor(int weekday) const;
162 void setWeekendDays( int start, int end );
163 void weekendDays( int& start, int& end ) const;
164 void computeTicks(bool doNotComputeRealScale = false);
165 void paintEvent(TQPaintEvent *);
166 int getCoordX(TQDate);
167 int getCoordX(TQDateTime);
168 TQDateTime getDateTimeForIndex(int coordX, bool local = true );
169 void setShowPopupMenu( bool show, bool showZoom, bool showScale,bool showTime,
170 bool showYear,bool showGrid, bool showPrint);
171 bool registerStartTime();
172 bool registerEndTime();
173 bool showPopupMenu() const;
174 ColumnColorList columnBackgroundColorList() const {
175 return ccList;
176 }
177 TQColor weekdayColor[8];
178 void repaintMe(int left, int wid, TQPainter *p = 0);
179
180 void centerDateTime( const TQDateTime& center );
181
182public slots:
183 void setSettings(int);
184 void checkWidth( int );
185 void addTickRight( int num = 1 );
186 void addTickLeft( int num = 1 );
187 void preparePopupMenu();
188signals:
189 void sizeChanged( int );
190
191private:
192 friend class KDTimeTableWidget;
193 friend class KDGanttViewItem;
194 friend class KDGanttView;
195 friend class KDGanttCanvasView; // calls computeIntervals
196 virtual void mousePressEvent ( TQMouseEvent * e );
197 virtual void mouseReleaseEvent ( TQMouseEvent * e );
198 virtual void mouseDoubleClickEvent ( TQMouseEvent * e );
199 virtual void mouseMoveEvent ( TQMouseEvent * e );
200 double secsFromTo( TQDateTime begin, TQDateTime end );
201 void updateTimeTable();
202 void computeIntervals( int height );
203 bool getColumnColor(TQColor& col,int coordLow, int coordHigh);
204 void moveTimeLineTo(int x);
205 //void mousePressEvent ( TQMouseEvent * ) ;
206 void resizeEvent ( TQResizeEvent * ) ;
207 TQValueList<int> majorTicks;
208 TQValueList<TQString> minorText;
209 TQValueList<TQString> majorText;
210 TQDateTime myHorizonStart, myHorizonEnd, myRealEnd,myRealStart;
211 TQDateTime myCenterDateTime;
212 void saveCenterDateTime();
213 Scale myScale,myRealScale,myMaxScale,myMinScale;
214 YearFormat myYearFormat;
215 HourFormat myHourFormat;
216 int myMinimumColumWidth;
217 bool flagShowMajorTicks, flagShowMinorTicks, flagShowPopupMenu;
218 bool flagShowZoom, flagShowScale ,flagShowTime ,flagShowYear;
219 bool flagShowGrid ,flagShowPrint;
220 bool flagStartTimeSet,flagEndTimeSet;
221 TQColor myWeekendBackgroundColor;
222 int myWeekendDaysStart, myWeekendDaysEnd;
223 ColumnColorList ccList;
224 IntervalColorList icList;
225 int myMinorScaleCount,myMajorScaleCount;
226 int myRealMinorScaleCount,myRealMajorScaleCount;
227 bool flagDoNotRecomputeAfterChange,flagDoNotRepaintAfterChange;
228 TQString getYear(TQDate);
229 TQString getHour(TQTime);
230 TQDateTime getEvenTimeDate(TQDateTime ,Scale);
231 void computeRealScale(TQDateTime start);
232 int myGridMinorWidth;
233 int myMajorGridHeight;
234 TQPopupMenu * myPopupMenu, *scalePopupMenu, *timePopupMenu;
235 TQPopupMenu * yearPopupMenu, *gridPopupMenu;
236 KDGanttView* myGanttView;
237 double myZoomFactor;
238 int myAutoScaleMinorTickcount;
239 bool flagZoomToFit;
240 int mySizeHint;
241 int myMinimumWidth;
242 int getTickTime();
243 KDTimeHeaderToolTip* myToolTip;
244 bool mouseDown;
245 int beginMouseDown;
246 int endMouseDown;
247 bool autoComputeTimeLine;
248 TQPixmap paintPix;
249};
250
251/* KDTimeTableWidget */
252class KDListView ;
253
254class KDTimeTableWidget : public TQCanvas
255{
256 TQ_OBJECT
257
258
259public:
260 KDTimeTableWidget (TQWidget* parent,KDGanttView* my);
261
262 void setBlockUpdating( bool block = true );
263 bool blockUpdating();
264 void inc_blockUpdating();
265 void dec_blockUpdating();
266 void setShowTaskLinks( bool show );
267 bool showTaskLinks();
268 TQPtrList<KDGanttViewTaskLink>taskLinks();
269 void clearTaskLinks();
270 void updateMyContent();
271 void removeItemFromTasklinks( KDGanttViewItem * );
272 void setHorBackgroundLines( int count, TQBrush brush );
273 int horBackgroundLines( TQBrush& brush );
274
275 void setNoInformationBrush( const TQBrush& brush );
276 TQBrush noInformationBrush() const;
277
278 int getCoordX( TQDateTime dt );
279
280signals:
281 void heightComputed( int );
282
283public slots:
284 void expandItem(TQListViewItem * );
285 void collapseItem(TQListViewItem * );
286 void highlightItem(TQListViewItem * );
287 void resetWidth( int );
288 void checkHeight( int );
289private:
290 friend class KDGanttViewTaskLink;
291 friend class KDTimeHeaderWidget;
292 friend class KDGanttView;
293 friend class KDGanttViewTaskItem;
295
296 bool taskLinksVisible;
297
298 TQPtrList<KDGanttViewTaskLink> myTaskLinkList;
299
300 TQPtrList<KDCanvasLine> verGridList;
301 TQPtrList<KDCanvasLine> horGridList;
302 TQPtrList<KDCanvasRectangle> horDenseList;
303 TQPtrList<KDCanvasRectangle> showNoInfoList;
304 int denseLineCount;
305 TQBrush denseLineBrush, noInfoLineBrush;
306 TQPtrList<KDCanvasRectangle> columnColorList;
307
308 int computeHeight();
309 void computeVerticalGrid();
310 void computeHorizontalGrid();
311 void computeDenseLines();
312 void computeShowNoInformation();
313 void computeTaskLinks();
314 void computeMinorGrid();
315 void computeMajorGrid();
316
317 void showMajorGrid();
318 void showMinorGrid();
319 void hideGrid();
320
321 TQPen gridPen;
322 int maximumComputedGridHeight;
323 int minimumHeight;
324 int int_blockUpdating;
325 bool flag_blockUpdating;
326 int pendingHeight;
327 int pendingWidth;
328
329};
330
331class KDLegendWidget : public KDGanttSemiSizingControl
332{
333 TQ_OBJECT
334
335
336public:
337 KDLegendWidget ( TQWidget* parent, KDGanttMinimizeSplitter* legendParent );
338 void showMe(bool);
339 bool isShown();
340 void addLegendItem( KDGanttViewItem::Shape shape, const TQColor& shapeColor, const TQString& text );
341 void clearLegend();
342 void setFont( TQFont );
343 void drawToPainter( TQPainter *p );
344 void setAsDoctwindow( bool dockwin );
345 bool asDoctwindow();
346 TQDockWindow* dockwindow();
347 TQSize legendSize();
348 TQSize legendSizeHint();
349 private:
350 TQGroupBox * myLegend;
351 TQLabel* myLabel;
352 TQScrollView * scroll;
353 TQDockWindow* dock;
354 KDGanttMinimizeSplitter* myLegendParent;
355};
356
357class KDGanttView;
358class KDListView : public TQListView
359{
360 TQ_OBJECT
361
362
363public:
364 KDListView (TQWidget* parent,KDGanttView* gv );
365 KDGanttView* myGanttView;
366 void drawToPainter( TQPainter *p, bool drawHeader=false );
367 void setCalendarMode( bool mode );
368 bool calendarMode() { return _calendarMode; };
369 TQString getWhatsThisText(TQPoint p);
370 void setOpen ( TQListViewItem * item, bool open );
371 void dragEnterEvent ( TQDragEnterEvent * );
372 void dragMoveEvent ( TQDragMoveEvent * );
373 void dragLeaveEvent ( TQDragLeaveEvent * );
374 void dropEvent ( TQDropEvent * );
375 TQDragObject * dragObject ();
376 void startDrag ();
377 void paintemptyarea ( TQPainter * p, const TQRect & rect ){ TQListView::paintEmptyArea( p, rect );};
378
379public:
380 class DrawableItem {
381 public:
382 DrawableItem(int level, int ypos, TQListViewItem *item ) { y = ypos; l = level; i = item; };
383 int y;
384 int l;
385 TQListViewItem * i;
386 };
387protected:
388 void drawAllContents(TQPainter * p, int cx, int cy, int cw, int ch);
389 int buildDrawables(TQPtrList<KDListView::DrawableItem> &lst, int level, int ypos, TQListViewItem *item, int ymin, int ymax) const;
390
391private slots:
392 void dragItem( TQListViewItem * );
393 private:
394 void resizeEvent ( TQResizeEvent * ) ;
395 void contentsMouseDoubleClickEvent ( TQMouseEvent * e );
396 bool _calendarMode;
397
398
399
400};
401
402
403class KDCanvasText : public TQCanvasText
404{
405public:
406 KDCanvasText( KDTimeTableWidget* canvas, void* parentItem, int type );
407 int myParentType;
408 void* myParentItem;
409};
410
411
412class KDCanvasLine : public TQCanvasLine
413{
414public:
415 KDCanvasLine( KDTimeTableWidget* canvas, void* parentItem, int type );
416 int myParentType;
417 void* myParentItem;
418};
419
420
421class KDCanvasPolygonItem: public TQCanvasPolygonalItem
422{
423public:
424 KDCanvasPolygonItem( KDTimeTableWidget* canvas, void* parentItem,
425 int type );
426 int myParentType;
427 void* myParentItem;
428};
429
430
431class KDCanvasPolygon: public TQCanvasPolygon
432{
433public:
434 KDCanvasPolygon( KDTimeTableWidget* canvas, void* parentItem, int type );
435 int myParentType;
436 void* myParentItem;
437};
438
439
440class KDCanvasEllipse: public TQCanvasEllipse
441{
442public:
443 KDCanvasEllipse( KDTimeTableWidget* canvas, void* parentItem, int type );
444 int myParentType;
445 void* myParentItem;
446};
447
448
449class KDCanvasRectangle: public TQCanvasRectangle
450{
451public:
452 KDCanvasRectangle( KDTimeTableWidget* canvas, void* parentItem, int type );
453 int myParentType;
454 void* myParentItem;
455};
456
457
458// Interval-color-rectangle, such as the one used in the freebusy view for the current event
459class KDIntervalColorRectangle: public KDCanvasRectangle
460{
461public:
462 KDIntervalColorRectangle( KDGanttView* view );
463
464 void setDateTimes( const TQDateTime& start,
465 const TQDateTime& end );
466 TQDateTime start() const { return mStart; }
467 TQDateTime end() const { return mEnd; }
468
469 void setColor( const TQColor& color );
470
471 enum HitTest { Start, Middle, End };
472 HitTest hitTest( KDTimeHeaderWidget* timeHeader, const TQPoint& pos ) const;
473
474 void layout( KDTimeHeaderWidget* timeHeader, int height );
475
476 static const int RTTI = 0x0c58;
477 /*reimp*/ int rtti() const { return RTTI; }
478
479private:
480 TQColor mColor;
481 TQDateTime mStart;
482 TQDateTime mEnd;
483};
484
485class KDCanvasToolTip;
486
487class KDGanttCanvasView : public TQCanvasView
488{
489 TQ_OBJECT
490
491
492public:
493 KDGanttCanvasView(KDGanttView* sender, TQCanvas* canvas = 0, TQWidget* parent = 0, const char* name = 0 );
494 ~KDGanttCanvasView();
495 TQString getToolTipText(TQPoint p);
496 TQString getWhatsThisText(TQPoint p);
497 void drawToPainter ( TQPainter * p );
498 void resetCutPaste( KDGanttViewItem* );
499 void setShowPopupMenu( bool show );
500 bool showPopupMenu();
501 void cutItem ( KDGanttViewItem* );
502 void insertItemAsRoot( KDGanttViewItem* );
503 void insertItemAsChild( KDGanttViewItem* , KDGanttViewItem* );
504 void insertItemAfter( KDGanttViewItem* , KDGanttViewItem* );
505protected:
506 friend class KDGanttView;
507 friend class KDListView;
508 virtual void contentsMousePressEvent ( TQMouseEvent * ) ;
509 virtual void contentsMouseReleaseEvent ( TQMouseEvent * );
510 virtual void contentsMouseDoubleClickEvent ( TQMouseEvent * );
511 virtual void contentsMouseMoveEvent ( TQMouseEvent * ) ;
512 virtual void viewportPaintEvent ( TQPaintEvent * pe );
513 void resizeEvent ( TQResizeEvent * ) ;
514 void set_MouseTracking(bool on);
515 int getType(TQCanvasItem*);
516 KDGanttViewItem* getItem(TQCanvasItem*);
517 KDGanttViewTaskLink* getLink(TQCanvasItem*);
518 int getItemArea(KDGanttViewItem *item, int x);
519 int getLinkType(int from, int to);
520
521 KDGanttView* mySignalSender;
522 KDGanttViewItem* currentItem, *lastClickedItem, *cuttedItem;
523 TQCanvasRectangle* movingItem;
524 KDGanttViewTaskItem* movingGVItem;
525 TQPoint movingStart;
526 TQDateTime movingStartDate;
527 enum MovingOperation { Moving, ResizingLeft, ResizingRight };
528 MovingOperation movingOperation;
529 KDGanttViewTaskLink* currentLink;
530 KDCanvasWhatsThis* myWhatsThis;
531 TQPopupMenu* onItem;
532 bool _showItemAddPopupMenu;
533 int myMyContentsHeight;
534 KDGanttViewItem *fromItem;
535 bool linkItemsEnabled;
536 TQCanvasLine *linkLine;
537 int fromArea;
538 bool autoScrollEnabled;
539 bool mouseDown;
540
541signals:
542 void heightResized( int );
543 void widthResized( int );
544
545public slots:
546 void set_Mouse_Tracking(bool on);
547 void moveMyContent( int, int );
548 void setMyContentsHeight( int );
549 void updateHorScrollBar();
550private slots:
551 void cutItem();
552 void pasteItem( int );
553 void newRootItem( int );
554 void newChildItem( int );
555 void slotScrollTimer();
556 void myUpdateScrollBars();
557
558private:
559 MovingOperation gvItemHitTest( KDGanttViewItem *item, KDTimeHeaderWidget* timeHeader, const TQPoint &pos );
560private:
561 KDCanvasToolTip* myToolTip;
562 TQTimer *myScrollTimer;
563 TQPoint mousePos;
564 TQTimer scrollBarTimer;
565};
566
567class KDTimeHeaderToolTip :public TQToolTip
568{
569
570public:
571 KDTimeHeaderToolTip( TQWidget *wid, KDTimeHeaderWidget* header ) : TQToolTip( wid ), _wid(wid),_header (header) {
572
573};
574
575protected:
576 virtual void maybeTip( const TQPoint& p)
577 {
578 static bool ishidden = true;
579 if (TQToolTip::isGloballyEnabled () ) {
580 if (ishidden) {
581 tip( TQRect( p.x(),p.y(),5,5), _header->getToolTipText(p));
582 }
583 else
584 hide();
585 ishidden = !ishidden;
586 }
587 }
588private:
589 TQWidget* _wid;
590 KDTimeHeaderWidget * _header;
591};
592
593class KDCanvasToolTip :public TQToolTip
594{
595
596public:
597 KDCanvasToolTip( TQWidget *wid, KDGanttCanvasView* canview ) : TQToolTip( wid ), _wid(wid),_canview (canview) {
598
599};
600
601protected:
602 virtual void maybeTip( const TQPoint& p)
603 {
604 static bool ishidden = true;
605 if (TQToolTip::isGloballyEnabled () ) {
606 if (ishidden) {
607 tip( TQRect( p.x()-2,p.y()-2,5,5), _canview->getToolTipText(p));
608 }
609 else
610 hide();
611 ishidden = !ishidden;
612 }
613 }
614private:
615 TQWidget* _wid;
616 KDGanttCanvasView * _canview;
617};
618
619class KDCanvasWhatsThis :public TQWhatsThis
620{
621public:
622 KDCanvasWhatsThis( TQWidget *wid, KDGanttCanvasView* canview ) : TQWhatsThis( wid ), _wid(wid),_canview (canview) { };
623
624protected:
625 virtual TQString text( const TQPoint& p)
626 {
627 return _canview->getWhatsThisText(p) ;
628 }
629private:
630 TQWidget* _wid;
631 KDGanttCanvasView * _canview;
632};
633
634class KDListViewWhatsThis :public TQWhatsThis
635{
636public:
637 KDListViewWhatsThis( TQWidget *wid, KDListView* view ) : TQWhatsThis( wid ), _wid(wid),_view (view) { };
638
639protected:
640 virtual TQString text( const TQPoint& p)
641 {
642 return _view->getWhatsThisText(p) ;
643 }
644private:
645 TQWidget* _wid;
646 KDListView * _view;
647};
648
649
650
651#endif
The KDGanttMinimizeSplitter class implements a splitter widget with minimize buttons.
KDGanttView * myGanttView