kdgantt

KDGanttViewSubwidgets.h

00001 /* -*- Mode: C++ -*-
00002    $Id: KDGanttViewSubwidgets.h 380679 2005-01-21 06:27:11Z 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 );
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 private slots:
00369   void dragItem( QListViewItem * );
00370  private:
00371    void resizeEvent ( QResizeEvent * ) ;
00372   void contentsMouseDoubleClickEvent ( QMouseEvent * e );
00373   bool _calendarMode;
00374 
00375 
00376 
00377 };
00378 
00379 
00380 class KDCanvasText : public QCanvasText
00381 {
00382 public:
00383     KDCanvasText( KDTimeTableWidget* canvas, void* parentItem, int type );
00384     int myParentType;
00385     void* myParentItem;
00386 };
00387 
00388 
00389 class KDCanvasLine : public QCanvasLine
00390 {
00391 public:
00392     KDCanvasLine( KDTimeTableWidget* canvas, void* parentItem, int type );
00393     int myParentType;
00394     void* myParentItem;
00395 };
00396 
00397 
00398 class KDCanvasPolygonItem: public QCanvasPolygonalItem
00399 {
00400 public:
00401     KDCanvasPolygonItem( KDTimeTableWidget* canvas, void* parentItem,
00402                          int type );
00403     int myParentType;
00404     void* myParentItem;
00405 };
00406 
00407 
00408 class KDCanvasPolygon: public QCanvasPolygon
00409 {
00410 public:
00411     KDCanvasPolygon( KDTimeTableWidget* canvas, void* parentItem, int type );
00412     int myParentType;
00413     void* myParentItem;
00414 };
00415 
00416 
00417 class KDCanvasEllipse: public QCanvasEllipse
00418 {
00419 public:
00420     KDCanvasEllipse( KDTimeTableWidget* canvas, void* parentItem, int type );
00421     int myParentType;
00422     void* myParentItem;
00423 };
00424 
00425 
00426 class KDCanvasRectangle: public QCanvasRectangle
00427 {
00428 public:
00429     KDCanvasRectangle( KDTimeTableWidget* canvas, void* parentItem, int type );
00430     int myParentType;
00431     void* myParentItem;
00432 };
00433 
00434 
00435 class KDCanvasToolTip;
00436 
00437 class KDGanttCanvasView : public QCanvasView
00438 {
00439     Q_OBJECT
00440 
00441 public:
00442     KDGanttCanvasView(KDGanttView* sender, QCanvas* canvas = 0, QWidget* parent = 0, const char* name = 0 );
00443     ~KDGanttCanvasView();
00444     QString getToolTipText(QPoint p);
00445     QString getWhatsThisText(QPoint p);
00446     void drawToPainter ( QPainter * p );
00447     void resetCutPaste( KDGanttViewItem* );
00448     void setShowPopupMenu( bool show );
00449     bool showPopupMenu();
00450     void cutItem (  KDGanttViewItem* );
00451     void insertItemAsRoot( KDGanttViewItem* );
00452     void insertItemAsChild( KDGanttViewItem* , KDGanttViewItem* );
00453     void insertItemAfter( KDGanttViewItem* , KDGanttViewItem* );
00454 protected:
00455     friend class KDGanttView;
00456     friend class KDListView;
00457     virtual void contentsMousePressEvent ( QMouseEvent * ) ;
00458     virtual void contentsMouseReleaseEvent ( QMouseEvent * );
00459     virtual void contentsMouseDoubleClickEvent ( QMouseEvent * );
00460     virtual void contentsMouseMoveEvent ( QMouseEvent * ) ;
00461     virtual void viewportPaintEvent ( QPaintEvent * pe );
00462     void resizeEvent ( QResizeEvent * ) ;
00463     void set_MouseTracking(bool on);
00464     KDGanttView* mySignalSender;
00465     KDGanttViewItem* currentItem, *lastClickedItem, *cuttedItem;
00466     KDGanttViewTaskLink* currentLink;
00467     int getType(QCanvasItem*);
00468     KDGanttViewItem* getItem(QCanvasItem*);
00469     KDGanttViewTaskLink* getLink(QCanvasItem*);
00470     KDCanvasWhatsThis* myWhatsThis;
00471     QPopupMenu* onItem;
00472     bool _showItemAddPopupMenu;
00473     int myMyContentsHeight;
00474     KDGanttViewItem *fromItem;
00475     bool linkItemsEnabled;
00476     QCanvasLine *linkLine;
00477     int fromArea;
00478     bool autoScrollEnabled;
00479     int getItemArea(KDGanttViewItem *item, int x);
00480     int getLinkType(int from, int to);
00481 
00482 signals:
00483   void heightResized( int );
00484   void widthResized( int );
00485 public slots:
00486   void set_Mouse_Tracking(bool on);
00487   void moveMyContent( int, int );
00488   void setMyContentsHeight( int );
00489 private slots:
00490   void cutItem();
00491   void pasteItem( int );
00492   void newRootItem( int );
00493   void newChildItem( int );
00494   void slotScrollTimer();
00495 
00496 private:
00497   KDCanvasToolTip* myToolTip;
00498   QTimer *myScrollTimer;
00499   QPoint mousePos;
00500 };
00501 
00502 class KDTimeHeaderToolTip :public QToolTip
00503 {
00504 
00505 public:
00506   KDTimeHeaderToolTip( QWidget *wid, KDTimeHeaderWidget* header ) : QToolTip( wid ), _wid(wid),_header (header) {
00507 
00508 };
00509 
00510 protected:
00511   virtual void maybeTip( const QPoint& p)
00512     {
00513       static bool ishidden = true;
00514       if (QToolTip::isGloballyEnabled () ) {
00515     if (ishidden) {
00516       tip( QRect( p.x(),p.y(),5,5), _header->getToolTipText(p));
00517     }
00518     else
00519       hide();
00520     ishidden = !ishidden;
00521       }
00522   }
00523 private:
00524   QWidget* _wid;
00525   KDTimeHeaderWidget * _header;
00526 };
00527 
00528 class KDCanvasToolTip :public QToolTip
00529 {
00530 
00531 public:
00532   KDCanvasToolTip( QWidget *wid, KDGanttCanvasView* canview ) : QToolTip( wid ), _wid(wid),_canview (canview) {
00533 
00534 };
00535 
00536 protected:
00537   virtual void maybeTip( const QPoint& p)
00538     {
00539       static bool ishidden = true;
00540       if (QToolTip::isGloballyEnabled () ) {
00541     if (ishidden) {
00542       tip( QRect( p.x()-2,p.y()-2,5,5), _canview->getToolTipText(p));
00543     }
00544     else
00545       hide();
00546     ishidden = !ishidden;
00547       }
00548   }
00549 private:
00550   QWidget* _wid;
00551   KDGanttCanvasView * _canview;
00552 };
00553 
00554 class KDCanvasWhatsThis :public QWhatsThis
00555 {
00556 public:
00557   KDCanvasWhatsThis( QWidget *wid, KDGanttCanvasView* canview ) : QWhatsThis( wid ), _wid(wid),_canview (canview) { };
00558 
00559 protected:
00560   virtual QString text( const QPoint& p)
00561   {
00562     return _canview->getWhatsThisText(p) ;
00563   }
00564 private:
00565   QWidget* _wid;
00566   KDGanttCanvasView * _canview;
00567 };
00568 
00569 class KDListViewWhatsThis :public QWhatsThis
00570 {
00571 public:
00572   KDListViewWhatsThis( QWidget *wid, KDListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
00573 
00574 protected:
00575   virtual QString text( const QPoint& p)
00576   {
00577     return _view->getWhatsThisText(p) ;
00578   }
00579 private:
00580   QWidget* _wid;
00581   KDListView * _view;
00582 };
00583 
00584 
00585 
00586 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys