00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef KDGANTTVIEWSUBWIDGETS_H
00037 #define KDGANTTVIEWSUBWIDGETS_H
00038
00039
00040 #include <qwidget.h>
00041 #include <qlistview.h>
00042 #include <qsplitter.h>
00043 #include <qevent.h>
00044 #include <qvaluelist.h>
00045 #include <qcanvas.h>
00046 #include <qwhatsthis.h>
00047 #include <qpopupmenu.h>
00048 #include <qtooltip.h>
00049 #include <qtimer.h>
00050 #include <qgroupbox.h>
00051 #include <qvgroupbox.h>
00052 #include <qlayout.h>
00053 #include <qlabel.h>
00054 #include <qbrush.h>
00055 #include <qvbox.h>
00056 #include <qdockwindow.h>
00057 #include <qtimer.h>
00058
00059 #include "KDGanttView.h"
00060 #include "KDGanttViewTaskLink.h"
00061 #include "KDGanttViewTaskLinkGroup.h"
00062 #include "KDGanttViewSummaryItem.h"
00063 #include "KDGanttSemiSizingControl.h"
00064 #include "KDGanttViewItemDrag.h"
00065
00066 #define Type_is_KDGanttGridItem 1
00067 #define Type_is_KDGanttViewItem 2
00068 #define Type_is_KDGanttTaskLink 3
00069
00070 class KDIntervalColorRectangle;
00071 class KDCanvasWhatsThis;
00072 class KDToolTip;
00073 class KDCanvasRectangle;
00074 class KDTimeHeaderToolTip;
00075
00076 class KDTimeHeaderWidget : public QWidget
00077 {
00078 Q_OBJECT
00079
00080 public:
00081 typedef KDGanttView::Scale Scale;
00082 typedef KDGanttView::YearFormat YearFormat;
00083 typedef KDGanttView::HourFormat HourFormat;
00084 struct DateTimeColor {
00085 QDateTime datetime;
00086 QDateTime end;
00087 QColor color;
00088 Scale minScaleView;
00089 Scale maxScaleView;
00090
00091 KDCanvasRectangle* canvasRect;
00092 };
00093 typedef QValueList<DateTimeColor> ColumnColorList;
00094 typedef QValueList<KDIntervalColorRectangle *> IntervalColorList;
00095
00096
00097
00098
00099
00100
00101 KDTimeHeaderWidget (QWidget* parent,KDGanttView* gant);
00102 ~KDTimeHeaderWidget();
00103
00104 QString getToolTipText(QPoint p);
00105 void zoomToFit();
00106 void zoom(double, bool absolute = true);
00107 void zoomToSelection( QDateTime startTime, QDateTime endTime);
00108 double zoomFactor();
00109 void setAutoScaleMinorTickCount( int count );
00110 int autoScaleMinorTickCount();
00111 void setHorizonStart( const QDateTime& start );
00112 QDateTime horizonStart() const;
00113 void setHorizonEnd( const QDateTime& start );
00114 QDateTime horizonEnd() const;
00115
00116 void setMaximumScale( Scale );
00117 KDTimeHeaderWidget::Scale maximumScale() const;
00118 void setMinimumScale( Scale );
00119 KDTimeHeaderWidget::Scale minimumScale() const;
00120 KDTimeHeaderWidget::Scale scale() const;
00121 void setMajorScaleCount( int count );
00122 int majorScaleCount() const;
00123 void setMinorScaleCount( int count );
00124 int minorScaleCount() const;
00125 void setMinimumColumnWidth( int width );
00126 int minimumColumnWidth() const;
00127 void setYearFormat( YearFormat format );
00128 KDTimeHeaderWidget::YearFormat yearFormat() const;
00129 void setHourFormat( HourFormat format );
00130 KDTimeHeaderWidget::HourFormat hourFormat() const;
00131 void setShowMajorTicks( bool );
00132 bool showMajorTicks() const;
00133 void setShowMinorTicks( bool );
00134 void setScale( Scale unit);
00135 bool showMinorTicks() const;
00136 void setColumnBackgroundColor( const QDateTime& column,
00137 const QColor& color,
00138 Scale mini = KDGanttView::Minute ,
00139 Scale maxi = KDGanttView::Month);
00140 #if 0
00141
00142 void setIntervalBackgroundColor( const QDateTime& start,
00143 const QDateTime& end,
00144 const QColor& color,
00145 Scale mini = KDGanttView::Minute ,
00146 Scale maxi = KDGanttView::Month);
00147 bool changeBackgroundInterval( const QDateTime& oldstart,
00148 const QDateTime& oldend,
00149 const QDateTime& newstart,
00150 const QDateTime& newend );
00151 bool deleteBackgroundInterval( const QDateTime& start,
00152 const QDateTime& end );
00153 #endif
00154 void addIntervalBackgroundColor( KDIntervalColorRectangle* newItem );
00155 void clearBackgroundColor();
00156 QColor columnBackgroundColor( const QDateTime& column ) const;
00157 void setWeekendBackgroundColor( const QColor& color );
00158 QColor weekendBackgroundColor() const;
00159 void setWeekdayBackgroundColor( const QColor& color, int weekday );
00160 QColor weekdayBackgroundColor(int weekday) const;
00161 void setWeekendDays( int start, int end );
00162 void weekendDays( int& start, int& end ) const;
00163 void computeTicks(bool doNotComputeRealScale = false);
00164 void paintEvent(QPaintEvent *);
00165 int getCoordX(QDate);
00166 int getCoordX(QDateTime);
00167 QDateTime getDateTimeForIndex(int coordX, bool local = true );
00168 void setShowPopupMenu( bool show, bool showZoom, bool showScale,bool showTime,
00169 bool showYear,bool showGrid, bool showPrint);
00170 bool registerStartTime();
00171 bool registerEndTime();
00172 bool showPopupMenu() const;
00173 ColumnColorList columnBackgroundColorList() const {
00174 return ccList;
00175 }
00176 QColor weekdayColor[8];
00177 void repaintMe(int left, int wid, QPainter *p = 0);
00178
00179 void centerDateTime( const QDateTime& center );
00180
00181 public slots:
00182 void setSettings(int);
00183 void checkWidth( int );
00184 void addTickRight( int num = 1 );
00185 void addTickLeft( int num = 1 );
00186 void preparePopupMenu();
00187 signals:
00188 void sizeChanged( int );
00189
00190 private:
00191 friend class KDTimeTableWidget;
00192 friend class KDGanttViewItem;
00193 friend class KDGanttView;
00194 friend class KDGanttCanvasView;
00195 virtual void mousePressEvent ( QMouseEvent * e );
00196 virtual void mouseReleaseEvent ( QMouseEvent * e );
00197 virtual void mouseDoubleClickEvent ( QMouseEvent * e );
00198 virtual void mouseMoveEvent ( QMouseEvent * e );
00199 double secsFromTo( QDateTime begin, QDateTime end );
00200 void updateTimeTable();
00201 void computeIntervals( int height );
00202 bool getColumnColor(QColor& col,int coordLow, int coordHigh);
00203 void moveTimeLineTo(int x);
00204
00205 void resizeEvent ( QResizeEvent * ) ;
00206 QValueList<int> majorTicks;
00207 QValueList<QString> minorText;
00208 QValueList<QString> majorText;
00209 QDateTime myHorizonStart, myHorizonEnd, myRealEnd,myRealStart;
00210 QDateTime myCenterDateTime;
00211 void saveCenterDateTime();
00212 Scale myScale,myRealScale,myMaxScale,myMinScale;
00213 YearFormat myYearFormat;
00214 HourFormat myHourFormat;
00215 int myMinimumColumWidth;
00216 bool flagShowMajorTicks, flagShowMinorTicks, flagShowPopupMenu;
00217 bool flagShowZoom, flagShowScale ,flagShowTime ,flagShowYear;
00218 bool flagShowGrid ,flagShowPrint;
00219 bool flagStartTimeSet,flagEndTimeSet;
00220 QColor myWeekendBackgroundColor;
00221 int myWeekendDaysStart, myWeekendDaysEnd;
00222 ColumnColorList ccList;
00223 IntervalColorList icList;
00224 int myMinorScaleCount,myMajorScaleCount;
00225 int myRealMinorScaleCount,myRealMajorScaleCount;
00226 bool flagDoNotRecomputeAfterChange,flagDoNotRepaintAfterChange;
00227 QString getYear(QDate);
00228 QString getHour(QTime);
00229 QDateTime getEvenTimeDate(QDateTime ,Scale);
00230 void computeRealScale(QDateTime start);
00231 int myGridMinorWidth;
00232 int myMajorGridHeight;
00233 QPopupMenu * myPopupMenu, *scalePopupMenu, *timePopupMenu;
00234 QPopupMenu * yearPopupMenu, *gridPopupMenu;
00235 KDGanttView* myGanttView;
00236 double myZoomFactor;
00237 int myAutoScaleMinorTickcount;
00238 bool flagZoomToFit;
00239 int mySizeHint;
00240 int myMinimumWidth;
00241 int getTickTime();
00242 KDTimeHeaderToolTip* myToolTip;
00243 bool mouseDown;
00244 int beginMouseDown;
00245 int endMouseDown;
00246 bool autoComputeTimeLine;
00247 QPixmap paintPix;
00248 };
00249
00250
00251 class KDListView ;
00252
00253 class KDTimeTableWidget : public QCanvas
00254 {
00255 Q_OBJECT
00256
00257 public:
00258 KDTimeTableWidget (QWidget* parent,KDGanttView* my);
00259
00260 void setBlockUpdating( bool block = true );
00261 bool blockUpdating();
00262 void inc_blockUpdating();
00263 void dec_blockUpdating();
00264 void setShowTaskLinks( bool show );
00265 bool showTaskLinks();
00266 QPtrList<KDGanttViewTaskLink>taskLinks();
00267 void clearTaskLinks();
00268 void updateMyContent();
00269 void removeItemFromTasklinks( KDGanttViewItem * );
00270 void setHorBackgroundLines( int count, QBrush brush );
00271 int horBackgroundLines( QBrush& brush );
00272
00273 void setNoInformationBrush( const QBrush& brush );
00274 QBrush noInformationBrush() const;
00275
00276 int getCoordX( QDateTime dt );
00277
00278 signals:
00279 void heightComputed( int );
00280
00281 public slots:
00282 void expandItem(QListViewItem * );
00283 void collapseItem(QListViewItem * );
00284 void highlightItem(QListViewItem * );
00285 void resetWidth( int );
00286 void checkHeight( int );
00287 private:
00288 friend class KDGanttViewTaskLink;
00289 friend class KDTimeHeaderWidget;
00290 friend class KDGanttView;
00291 friend class KDGanttViewTaskItem;
00292 KDGanttView* myGanttView;
00293
00294 bool taskLinksVisible;
00295
00296 QPtrList<KDGanttViewTaskLink> myTaskLinkList;
00297
00298 QPtrList<KDCanvasLine> verGridList;
00299 QPtrList<KDCanvasLine> horGridList;
00300 QPtrList<KDCanvasRectangle> horDenseList;
00301 QPtrList<KDCanvasRectangle> showNoInfoList;
00302 int denseLineCount;
00303 QBrush denseLineBrush, noInfoLineBrush;
00304 QPtrList<KDCanvasRectangle> columnColorList;
00305
00306 int computeHeight();
00307 void computeVerticalGrid();
00308 void computeHorizontalGrid();
00309 void computeDenseLines();
00310 void computeShowNoInformation();
00311 void computeTaskLinks();
00312 void computeMinorGrid();
00313 void computeMajorGrid();
00314
00315 void showMajorGrid();
00316 void showMinorGrid();
00317 void hideGrid();
00318
00319 QPen gridPen;
00320 int maximumComputedGridHeight;
00321 int minimumHeight;
00322 int int_blockUpdating;
00323 bool flag_blockUpdating;
00324 int pendingHeight;
00325 int pendingWidth;
00326
00327 };
00328
00329 class KDLegendWidget : public KDGanttSemiSizingControl
00330 {
00331 Q_OBJECT
00332
00333 public:
00334 KDLegendWidget ( QWidget* parent, KDGanttMinimizeSplitter* legendParent );
00335 void showMe(bool);
00336 bool isShown();
00337 void addLegendItem( KDGanttViewItem::Shape shape, const QColor& shapeColor, const QString& text );
00338 void clearLegend();
00339 void setFont( QFont );
00340 void drawToPainter( QPainter *p );
00341 void setAsDockwindow( bool dockwin );
00342 bool asDockwindow();
00343 QDockWindow* dockwindow();
00344 QSize legendSize();
00345 QSize legendSizeHint();
00346 private:
00347 QGroupBox * myLegend;
00348 QLabel* myLabel;
00349 QScrollView * scroll;
00350 QDockWindow* dock;
00351 KDGanttMinimizeSplitter* myLegendParent;
00352 };
00353
00354 class KDGanttView;
00355 class KDListView : public QListView
00356 {
00357 Q_OBJECT
00358
00359 public:
00360 KDListView (QWidget* parent,KDGanttView* gv );
00361 KDGanttView* myGanttView;
00362 void drawToPainter( QPainter *p, bool drawHeader=false );
00363 void setCalendarMode( bool mode );
00364 bool calendarMode() { return _calendarMode; };
00365 QString getWhatsThisText(QPoint p);
00366 void setOpen ( QListViewItem * item, bool open );
00367 void dragEnterEvent ( QDragEnterEvent * );
00368 void dragMoveEvent ( QDragMoveEvent * );
00369 void dragLeaveEvent ( QDragLeaveEvent * );
00370 void dropEvent ( QDropEvent * );
00371 QDragObject * dragObject ();
00372 void startDrag ();
00373 void paintemptyarea ( QPainter * p, const QRect & rect ){ QListView::paintEmptyArea( p, rect );};
00374
00375 public:
00376 class DrawableItem {
00377 public:
00378 DrawableItem(int level, int ypos, QListViewItem *item ) { y = ypos; l = level; i = item; };
00379 int y;
00380 int l;
00381 QListViewItem * i;
00382 };
00383 protected:
00384 void drawAllContents(QPainter * p, int cx, int cy, int cw, int ch);
00385 int buildDrawables(QPtrList<KDListView::DrawableItem> &lst, int level, int ypos, QListViewItem *item, int ymin, int ymax) const;
00386
00387 private slots:
00388 void dragItem( QListViewItem * );
00389 private:
00390 void resizeEvent ( QResizeEvent * ) ;
00391 void contentsMouseDoubleClickEvent ( QMouseEvent * e );
00392 bool _calendarMode;
00393
00394
00395
00396 };
00397
00398
00399 class KDCanvasText : public QCanvasText
00400 {
00401 public:
00402 KDCanvasText( KDTimeTableWidget* canvas, void* parentItem, int type );
00403 int myParentType;
00404 void* myParentItem;
00405 };
00406
00407
00408 class KDCanvasLine : public QCanvasLine
00409 {
00410 public:
00411 KDCanvasLine( KDTimeTableWidget* canvas, void* parentItem, int type );
00412 int myParentType;
00413 void* myParentItem;
00414 };
00415
00416
00417 class KDCanvasPolygonItem: public QCanvasPolygonalItem
00418 {
00419 public:
00420 KDCanvasPolygonItem( KDTimeTableWidget* canvas, void* parentItem,
00421 int type );
00422 int myParentType;
00423 void* myParentItem;
00424 };
00425
00426
00427 class KDCanvasPolygon: public QCanvasPolygon
00428 {
00429 public:
00430 KDCanvasPolygon( KDTimeTableWidget* canvas, void* parentItem, int type );
00431 int myParentType;
00432 void* myParentItem;
00433 };
00434
00435
00436 class KDCanvasEllipse: public QCanvasEllipse
00437 {
00438 public:
00439 KDCanvasEllipse( KDTimeTableWidget* canvas, void* parentItem, int type );
00440 int myParentType;
00441 void* myParentItem;
00442 };
00443
00444
00445 class KDCanvasRectangle: public QCanvasRectangle
00446 {
00447 public:
00448 KDCanvasRectangle( KDTimeTableWidget* canvas, void* parentItem, int type );
00449 int myParentType;
00450 void* myParentItem;
00451 };
00452
00453
00454
00455 class KDIntervalColorRectangle: public KDCanvasRectangle
00456 {
00457 public:
00458 KDIntervalColorRectangle( KDGanttView* view );
00459
00460 void setDateTimes( const QDateTime& start,
00461 const QDateTime& end );
00462 QDateTime start() const { return mStart; }
00463 QDateTime end() const { return mEnd; }
00464
00465 void setColor( const QColor& color );
00466
00467 enum HitTest { Start, Middle, End };
00468 HitTest hitTest( KDTimeHeaderWidget* timeHeader, const QPoint& pos ) const;
00469
00470 void layout( KDTimeHeaderWidget* timeHeader, int height );
00471
00472 static const int RTTI = 0x0c58;
00473 int rtti() const { return RTTI; }
00474
00475 private:
00476 QColor mColor;
00477 QDateTime mStart;
00478 QDateTime mEnd;
00479 };
00480
00481 class KDCanvasToolTip;
00482
00483 class KDGanttCanvasView : public QCanvasView
00484 {
00485 Q_OBJECT
00486
00487 public:
00488 KDGanttCanvasView(KDGanttView* sender, QCanvas* canvas = 0, QWidget* parent = 0, const char* name = 0 );
00489 ~KDGanttCanvasView();
00490 QString getToolTipText(QPoint p);
00491 QString getWhatsThisText(QPoint p);
00492 void drawToPainter ( QPainter * p );
00493 void resetCutPaste( KDGanttViewItem* );
00494 void setShowPopupMenu( bool show );
00495 bool showPopupMenu();
00496 void cutItem ( KDGanttViewItem* );
00497 void insertItemAsRoot( KDGanttViewItem* );
00498 void insertItemAsChild( KDGanttViewItem* , KDGanttViewItem* );
00499 void insertItemAfter( KDGanttViewItem* , KDGanttViewItem* );
00500 protected:
00501 friend class KDGanttView;
00502 friend class KDListView;
00503 virtual void contentsMousePressEvent ( QMouseEvent * ) ;
00504 virtual void contentsMouseReleaseEvent ( QMouseEvent * );
00505 virtual void contentsMouseDoubleClickEvent ( QMouseEvent * );
00506 virtual void contentsMouseMoveEvent ( QMouseEvent * ) ;
00507 virtual void viewportPaintEvent ( QPaintEvent * pe );
00508 void resizeEvent ( QResizeEvent * ) ;
00509 void set_MouseTracking(bool on);
00510 int getType(QCanvasItem*);
00511 KDGanttViewItem* getItem(QCanvasItem*);
00512 KDGanttViewTaskLink* getLink(QCanvasItem*);
00513 int getItemArea(KDGanttViewItem *item, int x);
00514 int getLinkType(int from, int to);
00515
00516 KDGanttView* mySignalSender;
00517 KDGanttViewItem* currentItem, *lastClickedItem, *cuttedItem;
00518 QCanvasRectangle* movingItem;
00519 KDGanttViewTaskItem* movingGVItem;
00520 QPoint movingStart;
00521 QDateTime movingStartDate;
00522 enum MovingOperation { Moving, ResizingLeft, ResizingRight };
00523 MovingOperation movingOperation;
00524 KDGanttViewTaskLink* currentLink;
00525 KDCanvasWhatsThis* myWhatsThis;
00526 QPopupMenu* onItem;
00527 bool _showItemAddPopupMenu;
00528 int myMyContentsHeight;
00529 KDGanttViewItem *fromItem;
00530 bool linkItemsEnabled;
00531 QCanvasLine *linkLine;
00532 int fromArea;
00533 bool autoScrollEnabled;
00534 bool mouseDown;
00535
00536 signals:
00537 void heightResized( int );
00538 void widthResized( int );
00539
00540 public slots:
00541 void set_Mouse_Tracking(bool on);
00542 void moveMyContent( int, int );
00543 void setMyContentsHeight( int );
00544 void updateHorScrollBar();
00545 private slots:
00546 void cutItem();
00547 void pasteItem( int );
00548 void newRootItem( int );
00549 void newChildItem( int );
00550 void slotScrollTimer();
00551 void myUpdateScrollBars();
00552
00553 private:
00554 MovingOperation gvItemHitTest( KDGanttViewItem *item, KDTimeHeaderWidget* timeHeader, const QPoint &pos );
00555 private:
00556 KDCanvasToolTip* myToolTip;
00557 QTimer *myScrollTimer;
00558 QPoint mousePos;
00559 QTimer scrollBarTimer;
00560 };
00561
00562 class KDTimeHeaderToolTip :public QToolTip
00563 {
00564
00565 public:
00566 KDTimeHeaderToolTip( QWidget *wid, KDTimeHeaderWidget* header ) : QToolTip( wid ), _wid(wid),_header (header) {
00567
00568 };
00569
00570 protected:
00571 virtual void maybeTip( const QPoint& p)
00572 {
00573 static bool ishidden = true;
00574 if (QToolTip::isGloballyEnabled () ) {
00575 if (ishidden) {
00576 tip( QRect( p.x(),p.y(),5,5), _header->getToolTipText(p));
00577 }
00578 else
00579 hide();
00580 ishidden = !ishidden;
00581 }
00582 }
00583 private:
00584 QWidget* _wid;
00585 KDTimeHeaderWidget * _header;
00586 };
00587
00588 class KDCanvasToolTip :public QToolTip
00589 {
00590
00591 public:
00592 KDCanvasToolTip( QWidget *wid, KDGanttCanvasView* canview ) : QToolTip( wid ), _wid(wid),_canview (canview) {
00593
00594 };
00595
00596 protected:
00597 virtual void maybeTip( const QPoint& p)
00598 {
00599 static bool ishidden = true;
00600 if (QToolTip::isGloballyEnabled () ) {
00601 if (ishidden) {
00602 tip( QRect( p.x()-2,p.y()-2,5,5), _canview->getToolTipText(p));
00603 }
00604 else
00605 hide();
00606 ishidden = !ishidden;
00607 }
00608 }
00609 private:
00610 QWidget* _wid;
00611 KDGanttCanvasView * _canview;
00612 };
00613
00614 class KDCanvasWhatsThis :public QWhatsThis
00615 {
00616 public:
00617 KDCanvasWhatsThis( QWidget *wid, KDGanttCanvasView* canview ) : QWhatsThis( wid ), _wid(wid),_canview (canview) { };
00618
00619 protected:
00620 virtual QString text( const QPoint& p)
00621 {
00622 return _canview->getWhatsThisText(p) ;
00623 }
00624 private:
00625 QWidget* _wid;
00626 KDGanttCanvasView * _canview;
00627 };
00628
00629 class KDListViewWhatsThis :public QWhatsThis
00630 {
00631 public:
00632 KDListViewWhatsThis( QWidget *wid, KDListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
00633
00634 protected:
00635 virtual QString text( const QPoint& p)
00636 {
00637 return _view->getWhatsThisText(p) ;
00638 }
00639 private:
00640 QWidget* _wid;
00641 KDListView * _view;
00642 };
00643
00644
00645
00646 #endif