kgantt

xQGanttBarViewPort.h

00001 #ifndef _XQGANTTBARVIEWPORT_H_
00002 #define _XQGANTTBARVIEWPORT_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 <qcursor.h>
00036 #include <qtimer.h>
00037 #include <qlabel.h>
00038 
00039 #include <kpopupmenu.h> 
00040 #include <ktoolbar.h> 
00041 
00042 #include <qptrdict.h>
00043 #include <qaction.h> 
00044 #include <qlineedit.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 xQTaskPosition 
00056 {
00057 
00058 public :
00059 
00060   xQTaskPosition(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 QFrame
00090 {
00091 
00092   Q_OBJECT
00093 
00094   friend class xQGanttBarView;
00095   friend class KGantt;
00096 
00097 public:
00098 
00099   enum Mode {Init, Select, Zoom, Move};
00100 
00101 
00103 
00106   xQGanttBarViewPort(KGanttItem* toplevelitem, xQGanttBarView* parent = 0,
00107              const char * name=0, WFlags f=0 );
00108 
00109 
00111 
00114   ~xQGanttBarViewPort();
00115 
00116 
00117 
00119 
00122   void update(int x1, int y1, int x2, int y2); 
00123   
00124 
00125  
00126   QPtrDict<xQTaskPosition> _gItemList;
00127 
00128 
00130 
00133   void addHoliday(int y, int m, int d);
00134 
00135 
00136 
00138 
00141   void removeHoliday(int y, int m, int d) {
00142     Q_UNUSED(y); Q_UNUSED(m); Q_UNUSED(d);
00143   }
00144 
00145 
00146 
00147   KPopupMenu* menu() {
00148     return _menu;
00149   }
00150 
00151 
00152 
00154 
00157   KToolBar* toolbar(QMainWindow* mw = 0);
00158 
00159 
00160   //  zoom by factor sfactor and move wx,wy to the center
00161   void zoom(double sfactor, int wx, int wy);
00162 
00163   //  zoom by factor, and leave the center unmoved
00164   void zoom(double sfactor);
00165 
00166 
00167   void getSelectedItems(QPtrList<KGanttItem>& list) {
00168     getSelectedItems(_toplevelitem, list);
00169   }
00170 
00171 
00172 signals:
00173 
00174   void modeChanged(int);
00175   void scroll(int x, int y);
00176   void resized();
00177   void recalculated();
00178   void message(const QString& msg);
00179 
00180 
00181 protected slots:
00182 
00183   void setMode(int mode);
00184 
00185   void setSelect();
00186   void setZoom();
00187   void setMove();
00188 
00189   void zoomIn();
00190   void zoomOut();
00191   void zoomAll(); 
00192 
00193   void popup(int index);
00194 
00195   void selectAll();
00196   void unselectAll();
00197 
00198   void deleteSelectedItems();
00199   void insertIntoSelectedItem();
00200 
00201 
00202 
00203 private slots:  
00204 
00205   void toplevelitemChanged(KGanttItem* item, KGanttItem::Change c);
00206   void textEdited();
00207   void itemDestroyed(KGanttItem*);
00208 
00209 
00210 
00211 private:
00212 
00213   enum Position { Outside = 0, Handle  = 1,
00214           North   = 2, South   = 4,
00215           West    = 8, East    = 16,
00216           Center  = 32 };
00217 
00219 
00222   inline int screenX(int wx);
00223 
00224 
00226 
00229   inline int screenY(int wy);
00230 
00231   
00233 
00236   inline int worldX(int sx);
00237 
00238 
00240 
00243   inline int worldY(int sy);
00244 
00245 
00246   //  this will be set by setParentScrollView()
00247   xQGanttBarView* _parent;
00248 
00249   int _grid, _snapgrid;
00250   bool _drawGrid, _drawHeader;
00251 
00252   Mode _mode;
00253 
00254   int _marginX, _marginY; // margin in minutes
00255   double _scaleX, _scaleY;
00256 
00257   int _margin;
00258 
00259 
00260   QCursor* _cursor_lupe;
00261 
00262   QLabel* _itemInfo;
00263   QLineEdit* _itemTextEdit;
00264 
00265 
00266   // all item are stored here
00267   KGanttItem* _toplevelitem;
00268 
00269   static KGanttItem* _currentItem;
00270 
00271   KPopupMenu* _menu;
00272   KPopupMenu* _selectMenu;
00273   
00274   KIconLoader* _iconloader;
00275 
00276   KToolBar* _toolbar;
00277 
00278   QPoint* _startPoint, *_endPoint;
00279 
00280   QPtrList<QDate> _holidays;
00281 
00282   QPtrList<KGanttItem> *_observedList;
00283 
00284 
00286 
00287   void initMenu(); 
00288 
00289   void drawGrid(QPainter*, int x1, int y1, int x2, int y2);
00290   void drawHeader(QPainter*, int x1, int y1, int x2, int y2);
00291   void drawItem(KGanttItem* item, QPainter* p, const QRect& rect );
00292 
00293   void drawRelation(QPainter*, KGanttRelation*);
00294 
00295   void recalc(KGanttItem* item, int xPos, int yPos, int depth, int nr );
00296   void recalc();
00297 
00298   void selectItem(KGanttItem*,bool);
00299 
00300   void getSelectedItems(KGanttItem*, QPtrList<KGanttItem>&);
00301 
00302   void adjustSize();
00303 
00304   void observeList(QPtrList<KGanttItem>*);
00305 
00306   Position check(KGanttItem** founditem, int x, int y);
00307 
00308   void mousePressEvent(QMouseEvent*);
00309   void mouseReleaseEvent(QMouseEvent*);
00310 
00311   void wheelEvent ( QWheelEvent * /*e*/) {
00312     printf("wheelEvent\n");
00313   }
00314 
00315   void mouseMoveEvent(QMouseEvent*);  
00316   void keyPressEvent(QKeyEvent* e);
00317   void paintEvent(QPaintEvent * e);
00318   
00319   
00320   QPixmap closedIcon, openedIcon;
00321 
00322 };
00323 
00324 
00325 
00326 
00327 //   inline
00328 
00329 
00330 int xQGanttBarViewPort::screenX(int wx)
00332 {   
00333   return (int) (0.5 + (wx + _marginX)  * _scaleX);
00334 }  
00335 int xQGanttBarViewPort::screenY(int wy)
00337 {   
00338   return (int) (0.5 + (wy + _marginY) * _scaleY);
00339 }  
00340 int xQGanttBarViewPort::worldX(int sx)
00342 {   
00343   return (int) (0.5 + (sx/_scaleX - _marginX));
00344 }  
00345 int xQGanttBarViewPort::worldY(int sy)
00347 {   
00348   return (int) (0.5 + (sy/_scaleY - _marginY));
00349 }  
00350 
00351 
00352 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys