kdgantt

KDGanttViewSubwidgets.h

00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttViewSubwidgets.h 516548 2006-03-07 14:58:04Z danders $
00003    KDGantt - a multi-platform charting engine
00004 */
00005 
00006 /****************************************************************************
00007  ** Copyright (C)  2002-2004 Klarälvdalens Datakonsult AB.  All rights reserved.
00008  **
00009  ** This file is part of the KDGantt library.
00010  **
00011  ** This file may be distributed and/or modified under the terms of the
00012  ** GNU General Public License version 2 as published by the Free Software
00013  ** Foundation and appearing in the file LICENSE.GPL included in the
00014  ** packaging of this file.
00015  **
00016  ** Licensees holding valid commercial KDGantt licenses may use this file in
00017  ** accordance with the KDGantt Commercial License Agreement provided with
00018  ** the Software.
00019  **
00020  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00021  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00022  **
00023  ** See http://www.klaralvdalens-datakonsult.se/Public/products/ for
00024  **   information about KDGantt Commercial License Agreements.
00025  **
00026  ** Contact info@klaralvdalens-datakonsult.se if any conditions of this
00027  ** licensing are not clear to you.
00028  **
00029  ** As a special exception, permission is given to link this program
00030  ** with any edition of Qt, and distribute the resulting executable,
00031  ** without including the source code for Qt in the source distribution.
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 KDCanvasWhatsThis;
00071 class KDToolTip;
00072 class KDCanvasRectangle;
00073 class KDTimeHeaderToolTip;
00074 
00075 class KDTimeHeaderWidget : public QWidget
00076 {
00077    Q_OBJECT
00078 
00079 public:
00080    typedef KDGanttView::Scale Scale;
00081    typedef KDGanttView::YearFormat YearFormat;
00082    typedef KDGanttView::HourFormat HourFormat;
00083    struct DateTimeColor {
00084      QDateTime datetime;
00085      QDateTime end;
00086      QColor color;
00087      Scale minScaleView;
00088      Scale maxScaleView;
00089      //KDCanvasLine* canvasLine;
00090      KDCanvasRectangle* canvasRect;
00091    };
00092    typedef QValueList<DateTimeColor> ColumnColorList;
00093   typedef QValueList<DateTimeColor> IntervalColorList;
00094    /*
00095      enum Scale { Minute, Hour, Day, Week, Month, Auto };
00096      enum YearFormat { FourDigit, TwoDigit, TwoDigitApostrophe };
00097      enum HourFormat { Hour_24, Hour_12 };
00098    */
00099 
00100    KDTimeHeaderWidget (QWidget* parent,KDGanttView* gant);
00101   ~KDTimeHeaderWidget();
00102 
00103    QString getToolTipText(QPoint p);
00104    void zoomToFit();
00105    void zoom(double, bool absolute = true);
00106    void zoomToSelection( QDateTime startTime, QDateTime endTime);
00107    double zoomFactor();
00108    void setAutoScaleMinorTickCount( int count );
00109    int autoScaleMinorTickCount();
00110    void setHorizonStart( const QDateTime& start );
00111    QDateTime horizonStart() const;
00112    void setHorizonEnd( const QDateTime& start );
00113    QDateTime horizonEnd() const;
00114 
00115    void setMaximumScale( Scale );
00116    KDTimeHeaderWidget::Scale maximumScale() const;
00117    void setMinimumScale( Scale );
00118    KDTimeHeaderWidget::Scale minimumScale() const;
00119    KDTimeHeaderWidget::Scale scale() const;
00120    void setMajorScaleCount( int count );
00121    int majorScaleCount() const;
00122    void setMinorScaleCount( int count );
00123    int minorScaleCount() const;
00124    void setMinimumColumnWidth( int width );
00125    int minimumColumnWidth() const;
00126    void setYearFormat( YearFormat format );
00127    KDTimeHeaderWidget::YearFormat yearFormat() const;
00128    void setHourFormat( HourFormat format );
00129    KDTimeHeaderWidget::HourFormat hourFormat() const;
00130    void setShowMajorTicks( bool );
00131    bool showMajorTicks() const;
00132    void setShowMinorTicks( bool );
00133    void setScale( Scale unit);
00134    bool showMinorTicks() const;
00135    void setColumnBackgroundColor( const QDateTime& column,
00136                   const QColor& color,
00137                   Scale mini =  KDGanttView::Minute ,
00138                   Scale maxi =  KDGanttView::Month);
00139    void setIntervalBackgroundColor( const QDateTime& start,
00140                     const QDateTime& end,
00141                   const QColor& color,
00142                   Scale mini =  KDGanttView::Minute ,
00143                   Scale maxi =  KDGanttView::Month);
00144    bool changeBackgroundInterval( const QDateTime& oldstart,
00145                   const QDateTime& oldend,
00146                   const QDateTime& newstart,
00147                   const QDateTime& newend );
00148    bool deleteBackgroundInterval( const QDateTime& start,
00149                   const QDateTime& end );
00150    void clearBackgroundColor();
00151    QColor columnBackgroundColor( const QDateTime& column ) const;
00152    void setWeekendBackgroundColor( const QColor& color );
00153    QColor weekendBackgroundColor() const;
00154    void setWeekdayBackgroundColor( const QColor& color, int weekday );
00155    QColor weekdayBackgroundColor(int weekday) const;
00156    void setWeekendDays( int start, int end );
00157    void weekendDays( int& start, int& end ) const;
00158    void computeTicks(bool doNotComputeRealScale = false);
00159    void paintEvent(QPaintEvent *);
00160    int getCoordX(QDate);
00161    int getCoordX(QDateTime);
00162    QDateTime getDateTimeForIndex(int coordX, bool local = true );
00163    void setShowPopupMenu( bool show, bool showZoom, bool showScale,bool showTime,
00164                           bool showYear,bool showGrid, bool showPrint);
00165    bool registerStartTime();
00166    bool registerEndTime();
00167    bool showPopupMenu() const;
00168    ColumnColorList columnBackgroundColorList() const {
00169       return ccList;
00170     }
00171    QColor weekdayColor[8];
00172    void repaintMe(int left, int wid, QPainter *p = 0);
00173 
00174    void centerDateTime( const QDateTime& center );
00175 
00176 public slots:
00177     void setSettings(int);
00178     void checkWidth( int );
00179     void addTickRight( int num = 1 );
00180     void addTickLeft( int num = 1 );
00181     void preparePopupMenu();
00182 signals:
00183     void sizeChanged( int );
00184 
00185 private:
00186     friend class KDTimeTableWidget;
00187     friend class KDGanttViewItem;
00188     friend class KDGanttView;
00189     virtual void mousePressEvent ( QMouseEvent * e );
00190     virtual void mouseReleaseEvent ( QMouseEvent * e );
00191     virtual void mouseDoubleClickEvent ( QMouseEvent * e );
00192     virtual void mouseMoveEvent ( QMouseEvent * e );
00193     double secsFromTo( QDateTime begin, QDateTime end );
00194     void updateTimeTable();
00195     void computeIntervals( int height );
00196     bool getColumnColor(QColor& col,int coordLow, int coordHigh);
00197     void moveTimeLineTo(int x);
00198     //void  mousePressEvent ( QMouseEvent * ) ;
00199     void resizeEvent ( QResizeEvent * ) ;
00200     QValueList<int> majorTicks;
00201     QValueList<QString> minorText;
00202     QValueList<QString> majorText;
00203     QDateTime myHorizonStart, myHorizonEnd, myRealEnd,myRealStart;
00204     QDateTime myCenterDateTime;
00205     void saveCenterDateTime();
00206     Scale myScale,myRealScale,myMaxScale,myMinScale;
00207     YearFormat myYearFormat;
00208     HourFormat myHourFormat;
00209     int myMinimumColumWidth;
00210     bool flagShowMajorTicks, flagShowMinorTicks, flagShowPopupMenu;
00211     bool flagShowZoom, flagShowScale ,flagShowTime ,flagShowYear;
00212     bool flagShowGrid ,flagShowPrint;
00213     bool flagStartTimeSet,flagEndTimeSet;
00214     QColor myWeekendBackgroundColor;
00215     int myWeekendDaysStart, myWeekendDaysEnd;
00216     ColumnColorList ccList;
00217     IntervalColorList icList;
00218     int myMinorScaleCount,myMajorScaleCount;
00219     int myRealMinorScaleCount,myRealMajorScaleCount;
00220     bool flagDoNotRecomputeAfterChange,flagDoNotRepaintAfterChange;
00221     QString getYear(QDate);
00222     QString getHour(QTime);
00223     QDateTime getEvenTimeDate(QDateTime ,Scale);
00224     void computeRealScale(QDateTime start);
00225     int myGridMinorWidth;
00226     int myMajorGridHeight;
00227     QPopupMenu * myPopupMenu, *scalePopupMenu, *timePopupMenu;
00228     QPopupMenu * yearPopupMenu, *gridPopupMenu;
00229     KDGanttView* myGanttView;
00230     double myZoomFactor;
00231     int myAutoScaleMinorTickcount;
00232     bool flagZoomToFit;
00233     int mySizeHint;
00234     int myMinimumWidth;
00235     int getTickTime();
00236     KDTimeHeaderToolTip* myToolTip;
00237     bool mouseDown;
00238     int beginMouseDown;
00239     int endMouseDown;
00240     bool autoComputeTimeLine;
00241     QPixmap paintPix;
00242 };
00243 
00244 /* KDTimeTableWidget */
00245 class KDListView ;
00246 
00247 class KDTimeTableWidget : public QCanvas
00248 {
00249    Q_OBJECT
00250 
00251 public:
00252    KDTimeTableWidget (QWidget* parent,KDGanttView* my);
00253 
00254     void setBlockUpdating( bool block = true );
00255     bool blockUpdating();
00256     void inc_blockUpdating();
00257     void dec_blockUpdating();
00258     void setShowTaskLinks( bool show );
00259     bool showTaskLinks();
00260     QPtrList<KDGanttViewTaskLink>taskLinks();
00261     void clearTaskLinks();
00262     void updateMyContent();
00263     void removeItemFromTasklinks( KDGanttViewItem * );
00264     void setHorBackgroundLines( int count, QBrush brush );
00265     int horBackgroundLines( QBrush& brush );
00266 
00267     void setNoInformationBrush( const QBrush& brush );
00268     QBrush noInformationBrush() const;
00269 
00270     int getCoordX( QDateTime dt );
00271     
00272 signals:
00273    void   heightComputed( int );
00274 
00275 public slots:
00276   void expandItem(QListViewItem * );
00277   void collapseItem(QListViewItem * );
00278   void highlightItem(QListViewItem * );
00279   void resetWidth( int );
00280   void checkHeight( int );
00281 private:
00282    friend class KDGanttViewTaskLink;
00283    friend class KDTimeHeaderWidget;
00284    friend class KDGanttView;
00285    friend class KDGanttViewTaskItem;
00286    KDGanttView* myGanttView;
00287 
00288    bool taskLinksVisible;
00289 
00290    QPtrList<KDGanttViewTaskLink> myTaskLinkList;
00291 
00292    QPtrList<KDCanvasLine> verGridList;
00293    QPtrList<KDCanvasLine> horGridList;
00294    QPtrList<KDCanvasRectangle> horDenseList;
00295    QPtrList<KDCanvasRectangle> showNoInfoList;
00296    int denseLineCount;
00297    QBrush denseLineBrush, noInfoLineBrush;
00298    QPtrList<KDCanvasRectangle> columnColorList;
00299 
00300   int computeHeight();
00301   void computeVerticalGrid();
00302   void computeHorizontalGrid();
00303   void computeDenseLines();
00304   void computeShowNoInformation();
00305   void computeTaskLinks();
00306   void computeMinorGrid();
00307   void computeMajorGrid();
00308 
00309    void showMajorGrid();
00310    void showMinorGrid();
00311    void hideGrid();
00312 
00313    QPen gridPen;
00314    int maximumComputedGridHeight;
00315   int minimumHeight;
00316   int int_blockUpdating;
00317   bool flag_blockUpdating;
00318   int pendingHeight;
00319   int pendingWidth;
00320 
00321 };
00322 
00323 class KDLegendWidget : public KDGanttSemiSizingControl
00324 {
00325    Q_OBJECT
00326 
00327 public:
00328   KDLegendWidget ( QWidget* parent, KDGanttMinimizeSplitter* legendParent );
00329   void showMe(bool);
00330   bool isShown();
00331   void addLegendItem( KDGanttViewItem::Shape shape, const QColor& shapeColor, const QString& text );
00332   void clearLegend();
00333   void setFont( QFont );
00334   void drawToPainter( QPainter *p );
00335   void setAsDockwindow( bool dockwin );
00336   bool asDockwindow();
00337   QDockWindow* dockwindow();
00338   QSize legendSize();
00339   QSize legendSizeHint();
00340  private:
00341   QGroupBox * myLegend;
00342   QLabel* myLabel;
00343   QScrollView * scroll;
00344   QDockWindow* dock;
00345   KDGanttMinimizeSplitter* myLegendParent;
00346 };
00347 
00348 class KDGanttView;
00349 class KDListView : public QListView
00350 {
00351    Q_OBJECT
00352 
00353 public:
00354    KDListView (QWidget* parent,KDGanttView* gv );
00355    KDGanttView* myGanttView;
00356    void drawToPainter( QPainter *p, bool drawHeader=false );
00357    void setCalendarMode( bool mode );
00358   bool calendarMode() { return _calendarMode; };
00359   QString getWhatsThisText(QPoint p);
00360   void setOpen ( QListViewItem * item, bool open );
00361   void dragEnterEvent ( QDragEnterEvent * );
00362   void dragMoveEvent ( QDragMoveEvent * );
00363   void dragLeaveEvent ( QDragLeaveEvent * );
00364   void dropEvent ( QDropEvent * );
00365   QDragObject * dragObject ();
00366   void startDrag ();
00367   void paintemptyarea ( QPainter * p, const QRect & rect ){ QListView::paintEmptyArea( p, rect );};
00368 
00369 public:
00370     class DrawableItem {
00371     public:
00372         DrawableItem(int level, int ypos, QListViewItem *item ) { y = ypos; l = level; i = item; };
00373         int y;
00374         int l;
00375         QListViewItem * i;
00376     };
00377 protected:
00378     void drawAllContents(QPainter * p, int cx, int cy, int cw, int ch);
00379     int buildDrawables(QPtrList<KDListView::DrawableItem> &lst, int level, int ypos, QListViewItem *item, int ymin, int ymax) const;
00380 
00381 private slots:
00382   void dragItem( QListViewItem * );
00383  private:
00384    void resizeEvent ( QResizeEvent * ) ;
00385   void contentsMouseDoubleClickEvent ( QMouseEvent * e );
00386   bool _calendarMode;
00387 
00388 
00389 
00390 };
00391 
00392 
00393 class KDCanvasText : public QCanvasText
00394 {
00395 public:
00396     KDCanvasText( KDTimeTableWidget* canvas, void* parentItem, int type );
00397     int myParentType;
00398     void* myParentItem;
00399 };
00400 
00401 
00402 class KDCanvasLine : public QCanvasLine
00403 {
00404 public:
00405     KDCanvasLine( KDTimeTableWidget* canvas, void* parentItem, int type );
00406     int myParentType;
00407     void* myParentItem;
00408 };
00409 
00410 
00411 class KDCanvasPolygonItem: public QCanvasPolygonalItem
00412 {
00413 public:
00414     KDCanvasPolygonItem( KDTimeTableWidget* canvas, void* parentItem,
00415                          int type );
00416     int myParentType;
00417     void* myParentItem;
00418 };
00419 
00420 
00421 class KDCanvasPolygon: public QCanvasPolygon
00422 {
00423 public:
00424     KDCanvasPolygon( KDTimeTableWidget* canvas, void* parentItem, int type );
00425     int myParentType;
00426     void* myParentItem;
00427 };
00428 
00429 
00430 class KDCanvasEllipse: public QCanvasEllipse
00431 {
00432 public:
00433     KDCanvasEllipse( KDTimeTableWidget* canvas, void* parentItem, int type );
00434     int myParentType;
00435     void* myParentItem;
00436 };
00437 
00438 
00439 class KDCanvasRectangle: public QCanvasRectangle
00440 {
00441 public:
00442     KDCanvasRectangle( KDTimeTableWidget* canvas, void* parentItem, int type );
00443     int myParentType;
00444     void* myParentItem;
00445 };
00446 
00447 
00448 class KDCanvasToolTip;
00449 
00450 class KDGanttCanvasView : public QCanvasView
00451 {
00452     Q_OBJECT
00453 
00454 public:
00455     KDGanttCanvasView(KDGanttView* sender, QCanvas* canvas = 0, QWidget* parent = 0, const char* name = 0 );
00456     ~KDGanttCanvasView();
00457     QString getToolTipText(QPoint p);
00458     QString getWhatsThisText(QPoint p);
00459     void drawToPainter ( QPainter * p );
00460     void resetCutPaste( KDGanttViewItem* );
00461     void setShowPopupMenu( bool show );
00462     bool showPopupMenu();
00463     void cutItem (  KDGanttViewItem* );
00464     void insertItemAsRoot( KDGanttViewItem* );
00465     void insertItemAsChild( KDGanttViewItem* , KDGanttViewItem* );
00466     void insertItemAfter( KDGanttViewItem* , KDGanttViewItem* );
00467 protected:
00468     friend class KDGanttView;
00469     friend class KDListView;
00470     virtual void contentsMousePressEvent ( QMouseEvent * ) ;
00471     virtual void contentsMouseReleaseEvent ( QMouseEvent * );
00472     virtual void contentsMouseDoubleClickEvent ( QMouseEvent * );
00473     virtual void contentsMouseMoveEvent ( QMouseEvent * ) ;
00474     virtual void viewportPaintEvent ( QPaintEvent * pe );
00475     void resizeEvent ( QResizeEvent * ) ;
00476     void set_MouseTracking(bool on);
00477     KDGanttView* mySignalSender;
00478     KDGanttViewItem* currentItem, *lastClickedItem, *cuttedItem;
00479     KDGanttViewTaskLink* currentLink;
00480     int getType(QCanvasItem*);
00481     KDGanttViewItem* getItem(QCanvasItem*);
00482     KDGanttViewTaskLink* getLink(QCanvasItem*);
00483     KDCanvasWhatsThis* myWhatsThis;
00484     QPopupMenu* onItem;
00485     bool _showItemAddPopupMenu;
00486     int myMyContentsHeight;
00487     KDGanttViewItem *fromItem;
00488     bool linkItemsEnabled;
00489     QCanvasLine *linkLine;
00490     int fromArea;
00491     bool autoScrollEnabled;
00492     int getItemArea(KDGanttViewItem *item, int x);
00493     int getLinkType(int from, int to);
00494 
00495 signals:
00496   void heightResized( int );
00497   void widthResized( int );
00498 public slots:
00499   void set_Mouse_Tracking(bool on);
00500   void moveMyContent( int, int );
00501   void setMyContentsHeight( int );
00502   void updateHorScrollBar();
00503 private slots:
00504   void cutItem();
00505   void pasteItem( int );
00506   void newRootItem( int );
00507   void newChildItem( int );
00508   void slotScrollTimer();
00509   void myUpdateScrollBars();
00510   
00511 private:
00512   KDCanvasToolTip* myToolTip;
00513   QTimer *myScrollTimer;
00514   QPoint mousePos;
00515   QTimer scrollBarTimer;
00516 };
00517 
00518 class KDTimeHeaderToolTip :public QToolTip
00519 {
00520 
00521 public:
00522   KDTimeHeaderToolTip( QWidget *wid, KDTimeHeaderWidget* header ) : QToolTip( wid ), _wid(wid),_header (header) {
00523 
00524 };
00525 
00526 protected:
00527   virtual void maybeTip( const QPoint& p)
00528     {
00529       static bool ishidden = true;
00530       if (QToolTip::isGloballyEnabled () ) {
00531     if (ishidden) {
00532       tip( QRect( p.x(),p.y(),5,5), _header->getToolTipText(p));
00533     }
00534     else
00535       hide();
00536     ishidden = !ishidden;
00537       }
00538   }
00539 private:
00540   QWidget* _wid;
00541   KDTimeHeaderWidget * _header;
00542 };
00543 
00544 class KDCanvasToolTip :public QToolTip
00545 {
00546 
00547 public:
00548   KDCanvasToolTip( QWidget *wid, KDGanttCanvasView* canview ) : QToolTip( wid ), _wid(wid),_canview (canview) {
00549 
00550 };
00551 
00552 protected:
00553   virtual void maybeTip( const QPoint& p)
00554     {
00555       static bool ishidden = true;
00556       if (QToolTip::isGloballyEnabled () ) {
00557     if (ishidden) {
00558       tip( QRect( p.x()-2,p.y()-2,5,5), _canview->getToolTipText(p));
00559     }
00560     else
00561       hide();
00562     ishidden = !ishidden;
00563       }
00564   }
00565 private:
00566   QWidget* _wid;
00567   KDGanttCanvasView * _canview;
00568 };
00569 
00570 class KDCanvasWhatsThis :public QWhatsThis
00571 {
00572 public:
00573   KDCanvasWhatsThis( QWidget *wid, KDGanttCanvasView* canview ) : QWhatsThis( wid ), _wid(wid),_canview (canview) { };
00574 
00575 protected:
00576   virtual QString text( const QPoint& p)
00577   {
00578     return _canview->getWhatsThisText(p) ;
00579   }
00580 private:
00581   QWidget* _wid;
00582   KDGanttCanvasView * _canview;
00583 };
00584 
00585 class KDListViewWhatsThis :public QWhatsThis
00586 {
00587 public:
00588   KDListViewWhatsThis( QWidget *wid, KDListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
00589 
00590 protected:
00591   virtual QString text( const QPoint& p)
00592   {
00593     return _view->getWhatsThisText(p) ;
00594   }
00595 private:
00596   QWidget* _wid;
00597   KDListView * _view;
00598 };
00599 
00600 
00601 
00602 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys