summaryrefslogtreecommitdiffstats
path: root/kgantt/kgantt/xQGanttBarViewPort.h
blob: ec6beeffaec81fc7d9c1d5422d0a27f88c27293e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#ifndef _XTQGANTTBARVIEWPORT_H_
#define _XTQGANTTBARVIEWPORT_H_

/*

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.

    author  : jh, jochen@ifb.bv.tu-berlin.de

    file    : xQGanttBarViewPort.h
    date    : 26 oct 2000


    changelog :

*/



#include "KGanttItem.h"

#include <tqcursor.h>
#include <tqtimer.h>
#include <tqlabel.h>

#include <kpopupmenu.h> 
#include <ktoolbar.h> 

#include <tqptrdict.h>
#include <tqaction.h> 
#include <tqlineedit.h>

class xQGanttBarView;

#define sgn(n) (n < 0 ? -1 : 1)


// This is an internal class.
// helper for drawing items

class xTQTaskPosition 
////////////////////
{

public :

  xTQTaskPosition(int nr, int x, int y, int w, int h, int hiSub, 
		 int tPx, int tPy, int d) 
    :  _nr(nr), _screenX(x), _screenY(y), _screenW(w), _screenH(h), 
       _screenHS(hiSub), _textPosX(tPx), _textPosY(tPy), _depth(d)
    {
      _screenHandleX = _screenHandleY = _screenHandleW = _screenHandleH = 0;
    }

  int _nr;
  int _screenX, _screenY, _screenW;
  int _screenH; // height without subitems
  int _screenHS; // height including subitems
  int _textPosX, _textPosY;

  int _screenHandleX, _screenHandleY, _screenHandleW, _screenHandleH;

  int _depth;
 
};



///  GanttBarViewPort Widget.
/*!
 *
 */

/////////////////////////////////////////
class KDE_EXPORT xQGanttBarViewPort : public TQFrame
////////////////////////////////////////
{

  Q_OBJECT
  

  friend class xQGanttBarView;
  friend class KGantt;

public:

  enum Mode {Init, Select, Zoom, Move};


  ///  Constructor.
  /*!
   *
   */
  xQGanttBarViewPort(KGanttItem* toplevelitem, xQGanttBarView* parent = 0,
		     const char * name=0, WFlags f=0 );


  ///  Destructor.
  /*!
   *
   */
  ~xQGanttBarViewPort();



  ///  Update widget.
  /*!
   *
   */
  void update(int x1, int y1, int x2, int y2); 
  

 
  TQPtrDict<xTQTaskPosition> _gItemList;


  ///  Add holiday.
  /*!
   *   
   */
  void addHoliday(int y, int m, int d);



  ///  Remove holiday.
  /*!
   *
   */
  void removeHoliday(int y, int m, int d) {
    Q_UNUSED(y); Q_UNUSED(m); Q_UNUSED(d);
  }



  TDEPopupMenu* menu() {
    return _menu;
  }



  ///
  /*!
   *
   */
  TDEToolBar* toolbar(TQMainWindow* mw = 0);


  //  zoom by factor sfactor and move wx,wy to the center
  void zoom(double sfactor, int wx, int wy);

  //  zoom by factor, and leave the center unmoved
  void zoom(double sfactor);


  void getSelectedItems(TQPtrList<KGanttItem>& list) {
    getSelectedItems(_toplevelitem, list);
  }


signals:

  void modeChanged(int);
  void scroll(int x, int y);
  void resized();
  void recalculated();
  void message(const TQString& msg);


protected slots:

  void setMode(int mode);

  void setSelect();
  void setZoom();
  void setMove();

  void zoomIn();
  void zoomOut();
  void zoomAll(); 

  void popup(int index);

  void selectAll();
  void unselectAll();

  void deleteSelectedItems();
  void insertIntoSelectedItem();



private slots:  

  void toplevelitemChanged(KGanttItem* item, KGanttItem::Change c);
  void textEdited();
  void itemDestroyed(KGanttItem*);



private:

  enum Position { Outside = 0, Handle  = 1,
		  North   = 2, South   = 4,
		  West    = 8, East    = 16,
		  Center  = 32 };

  ///  Transform world coordinate to screen coordinate.
  /*!
   *
   */
  inline int screenX(int wx);


  ///  Transform world coordinate to screen coordinate.
  /*!
   *
   */
  inline int screenY(int wy);

  
  ///  Transform screen coordinate to world coordinate.
  /*!
   *
   */
  inline int worldX(int sx);


  ///  Transform screen coordinate to world coordinate.
  /*!
   *
   */
  inline int worldY(int sy);


  //  this will be set by setParentScrollView()
  xQGanttBarView* _parent;

  int _grid, _snapgrid;
  bool _drawGrid, _drawHeader;

  Mode _mode;

  int _marginX, _marginY; // margin in minutes
  double _scaleX, _scaleY;

  int _margin;


  TQCursor* _cursor_lupe;

  TQLabel* _itemInfo;
  TQLineEdit* _itemTextEdit;


  // all item are stored here
  KGanttItem* _toplevelitem;

  static KGanttItem* _currentItem;

  TDEPopupMenu* _menu;
  TDEPopupMenu* _selectMenu;
  
  KIconLoader* _iconloader;

  TDEToolBar* _toolbar;

  TQPoint* _startPoint, *_endPoint;

  TQPtrList<TQDate> _holidays;

  TQPtrList<KGanttItem> *_observedList;


  /// 

  void initMenu(); 

  void drawGrid(TQPainter*, int x1, int y1, int x2, int y2);
  void drawHeader(TQPainter*, int x1, int y1, int x2, int y2);
  void drawItem(KGanttItem* item, TQPainter* p, const TQRect& rect );

  void drawRelation(TQPainter*, KGanttRelation*);

  void recalc(KGanttItem* item, int xPos, int yPos, int depth, int nr );
  void recalc();

  void selectItem(KGanttItem*,bool);

  void getSelectedItems(KGanttItem*, TQPtrList<KGanttItem>&);

  void adjustSize();

  void observeList(TQPtrList<KGanttItem>*);

  Position check(KGanttItem** founditem, int x, int y);

  void mousePressEvent(TQMouseEvent*);
  void mouseReleaseEvent(TQMouseEvent*);

  void wheelEvent ( TQWheelEvent * /*e*/) {
    printf("wheelEvent\n");
  }

  void mouseMoveEvent(TQMouseEvent*);  
  void keyPressEvent(TQKeyEvent* e);
  void paintEvent(TQPaintEvent * e);
  
  
  TQPixmap closedIcon, openedIcon;

};




//   inline


int xQGanttBarViewPort::screenX(int wx)
///////////////////////////////////////
{   
  return (int) (0.5 + (wx + _marginX)  * _scaleX);
}  
int xQGanttBarViewPort::screenY(int wy)
/////////////////////////////////////
{   
  return (int) (0.5 + (wy + _marginY) * _scaleY);
}  
int xQGanttBarViewPort::worldX(int sx)
/////////////////////////////////////
{   
  return (int) (0.5 + (sx/_scaleX - _marginX));
}  
int xQGanttBarViewPort::worldY(int sy)
//////////////////////////////////////
{   
  return (int) (0.5 + (sy/_scaleY - _marginY));
}  


#endif