kgantt

xQGanttBarViewPort.h
00001 #ifndef _XTQGANTTBARVIEWPORT_H_
00002 #define _XTQGANTTBARVIEWPORT_H_
00003 
00004 /*
00005 
00006     This library is free software; you can redistribute it and/or
00007     modify it under the terms of the GNU Library General Public
00008     License as published by the Free Software Foundation; either
00009     version 2 of the License, or (at your option) any later version.
00010 
00011     This library is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014     Library General Public License for more details.
00015 
00016     You should have received a copy of the GNU Library General Public License
00017     along with this library; see the file COPYING.LIB.  If not, write to
00018     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00019     Boston, MA 02110-1301, USA.
00020 
00021     author  : jh, jochen@ifb.bv.tu-berlin.de
00022 
00023     file    : xQGanttBarViewPort.h
00024     date    : 26 oct 2000
00025 
00026 
00027     changelog :
00028 
00029 */
00030 
00031 
00032 
00033 #include "KGanttItem.h"
00034 
00035 #include <tqcursor.h>
00036 #include <tqtimer.h>
00037 #include <tqlabel.h>
00038 
00039 #include <kpopupmenu.h> 
00040 #include <ktoolbar.h> 
00041 
00042 #include <tqptrdict.h>
00043 #include <tqaction.h> 
00044 #include <tqlineedit.h>
00045 
00046 class xQGanttBarView;
00047 
00048 #define sgn(n) (n < 0 ? -1 : 1)
00049 
00050 
00051 // This is an internal class.
00052 // helper for drawing items
00053 
00054 class xTQTaskPosition 
00056 {
00057 
00058 public :
00059 
00060   xTQTaskPosition(int nr, int x, int y, int w, int h, int hiSub, 
00061          int tPx, int tPy, int d) 
00062     :  _nr(nr), _screenX(x), _screenY(y), _screenW(w), _screenH(h), 
00063        _screenHS(hiSub), _textPosX(tPx), _textPosY(tPy), _depth(d)
00064     {
00065       _screenHandleX = _screenHandleY = _screenHandleW = _screenHandleH = 0;
00066     }
00067 
00068   int _nr;
00069   int _screenX, _screenY, _screenW;
00070   int _screenH; // height without subitems
00071   int _screenHS; // height including subitems
00072   int _textPosX, _textPosY;
00073 
00074   int _screenHandleX, _screenHandleY, _screenHandleW, _screenHandleH;
00075 
00076   int _depth;
00077  
00078 };
00079 
00080 
00081 
00083 
00087 
00088 class KDE_EXPORT xQGanttBarViewPort : public TQFrame
00090 {
00091 
00092   Q_OBJECT
00093   TQ_OBJECT
00094 
00095   friend class xQGanttBarView;
00096   friend class KGantt;
00097 
00098 public:
00099 
00100   enum Mode {Init, Select, Zoom, Move};
00101 
00102 
00104 
00107   xQGanttBarViewPort(KGanttItem* toplevelitem, xQGanttBarView* parent = 0,
00108              const char * name=0, WFlags f=0 );
00109 
00110 
00112 
00115   ~xQGanttBarViewPort();
00116 
00117 
00118 
00120 
00123   void update(int x1, int y1, int x2, int y2); 
00124   
00125 
00126  
00127   TQPtrDict<xTQTaskPosition> _gItemList;
00128 
00129 
00131 
00134   void addHoliday(int y, int m, int d);
00135 
00136 
00137 
00139 
00142   void removeHoliday(int y, int m, int d) {
00143     Q_UNUSED(y); Q_UNUSED(m); Q_UNUSED(d);
00144   }
00145 
00146 
00147 
00148   KPopupMenu* menu() {
00149     return _menu;
00150   }
00151 
00152 
00153 
00155 
00158   KToolBar* toolbar(TQMainWindow* mw = 0);
00159 
00160 
00161   //  zoom by factor sfactor and move wx,wy to the center
00162   void zoom(double sfactor, int wx, int wy);
00163 
00164   //  zoom by factor, and leave the center unmoved
00165   void zoom(double sfactor);
00166 
00167 
00168   void getSelectedItems(TQPtrList<KGanttItem>& list) {
00169     getSelectedItems(_toplevelitem, list);
00170   }
00171 
00172 
00173 signals:
00174 
00175   void modeChanged(int);
00176   void scroll(int x, int y);
00177   void resized();
00178   void recalculated();
00179   void message(const TQString& msg);
00180 
00181 
00182 protected slots:
00183 
00184   void setMode(int mode);
00185 
00186   void setSelect();
00187   void setZoom();
00188   void setMove();
00189 
00190   void zoomIn();
00191   void zoomOut();
00192   void zoomAll(); 
00193 
00194   void popup(int index);
00195 
00196   void selectAll();
00197   void unselectAll();
00198 
00199   void deleteSelectedItems();
00200   void insertIntoSelectedItem();
00201 
00202 
00203 
00204 private slots:  
00205 
00206   void toplevelitemChanged(KGanttItem* item, KGanttItem::Change c);
00207   void textEdited();
00208   void itemDestroyed(KGanttItem*);
00209 
00210 
00211 
00212 private:
00213 
00214   enum Position { Outside = 0, Handle  = 1,
00215           North   = 2, South   = 4,
00216           West    = 8, East    = 16,
00217           Center  = 32 };
00218 
00220 
00223   inline int screenX(int wx);
00224 
00225 
00227 
00230   inline int screenY(int wy);
00231 
00232   
00234 
00237   inline int worldX(int sx);
00238 
00239 
00241 
00244   inline int worldY(int sy);
00245 
00246 
00247   //  this will be set by setParentScrollView()
00248   xQGanttBarView* _parent;
00249 
00250   int _grid, _snapgrid;
00251   bool _drawGrid, _drawHeader;
00252 
00253   Mode _mode;
00254 
00255   int _marginX, _marginY; // margin in minutes
00256   double _scaleX, _scaleY;
00257 
00258   int _margin;
00259 
00260 
00261   TQCursor* _cursor_lupe;
00262 
00263   TQLabel* _itemInfo;
00264   TQLineEdit* _itemTextEdit;
00265 
00266 
00267   // all item are stored here
00268   KGanttItem* _toplevelitem;
00269 
00270   static KGanttItem* _currentItem;
00271 
00272   KPopupMenu* _menu;
00273   KPopupMenu* _selectMenu;
00274   
00275   KIconLoader* _iconloader;
00276 
00277   KToolBar* _toolbar;
00278 
00279   TQPoint* _startPoint, *_endPoint;
00280 
00281   TQPtrList<TQDate> _holidays;
00282 
00283   TQPtrList<KGanttItem> *_observedList;
00284 
00285 
00287 
00288   void initMenu(); 
00289 
00290   void drawGrid(TQPainter*, int x1, int y1, int x2, int y2);
00291   void drawHeader(TQPainter*, int x1, int y1, int x2, int y2);
00292   void drawItem(KGanttItem* item, TQPainter* p, const TQRect& rect );
00293 
00294   void drawRelation(TQPainter*, KGanttRelation*);
00295 
00296   void recalc(KGanttItem* item, int xPos, int yPos, int depth, int nr );
00297   void recalc();
00298 
00299   void selectItem(KGanttItem*,bool);
00300 
00301   void getSelectedItems(KGanttItem*, TQPtrList<KGanttItem>&);
00302 
00303   void adjustSize();
00304 
00305   void observeList(TQPtrList<KGanttItem>*);
00306 
00307   Position check(KGanttItem** founditem, int x, int y);
00308 
00309   void mousePressEvent(TQMouseEvent*);
00310   void mouseReleaseEvent(TQMouseEvent*);
00311 
00312   void wheelEvent ( TQWheelEvent * /*e*/) {
00313     printf("wheelEvent\n");
00314   }
00315 
00316   void mouseMoveEvent(TQMouseEvent*);  
00317   void keyPressEvent(TQKeyEvent* e);
00318   void paintEvent(TQPaintEvent * e);
00319   
00320   
00321   TQPixmap closedIcon, openedIcon;
00322 
00323 };
00324 
00325 
00326 
00327 
00328 //   inline
00329 
00330 
00331 int xQGanttBarViewPort::screenX(int wx)
00333 {   
00334   return (int) (0.5 + (wx + _marginX)  * _scaleX);
00335 }  
00336 int xQGanttBarViewPort::screenY(int wy)
00338 {   
00339   return (int) (0.5 + (wy + _marginY) * _scaleY);
00340 }  
00341 int xQGanttBarViewPort::worldX(int sx)
00343 {   
00344   return (int) (0.5 + (sx/_scaleX - _marginX));
00345 }  
00346 int xQGanttBarViewPort::worldY(int sy)
00348 {   
00349   return (int) (0.5 + (sy/_scaleY - _marginY));
00350 }  
00351 
00352 
00353 #endif