kgantt

xQGanttBarViewPort.h
1#ifndef _XTQGANTTBARVIEWPORT_H_
2#define _XTQGANTTBARVIEWPORT_H_
3
4/*
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 author : jh, jochen@ifb.bv.tu-berlin.de
22
23 file : xQGanttBarViewPort.h
24 date : 26 oct 2000
25
26
27 changelog :
28
29*/
30
31
32
33#include "KGanttItem.h"
34
35#include <tqcursor.h>
36#include <tqtimer.h>
37#include <tqlabel.h>
38
39#include <tdepopupmenu.h>
40#include <tdetoolbar.h>
41
42#include <tqptrdict.h>
43#include <tqaction.h>
44#include <tqlineedit.h>
45
46class xQGanttBarView;
47
48#define sgn(n) (n < 0 ? -1 : 1)
49
50
51// This is an internal class.
52// helper for drawing items
53
54class xTQTaskPosition
56{
57
58public :
59
60 xTQTaskPosition(int nr, int x, int y, int w, int h, int hiSub,
61 int tPx, int tPy, int d)
62 : _nr(nr), _screenX(x), _screenY(y), _screenW(w), _screenH(h),
63 _screenHS(hiSub), _textPosX(tPx), _textPosY(tPy), _depth(d)
64 {
65 _screenHandleX = _screenHandleY = _screenHandleW = _screenHandleH = 0;
66 }
67
68 int _nr;
69 int _screenX, _screenY, _screenW;
70 int _screenH; // height without subitems
71 int _screenHS; // height including subitems
72 int _textPosX, _textPosY;
73
74 int _screenHandleX, _screenHandleY, _screenHandleW, _screenHandleH;
75
76 int _depth;
77
78};
79
80
81
83
88class TDE_EXPORT xQGanttBarViewPort : public TQFrame
90{
91
92 TQ_OBJECT
93
94
95 friend class xQGanttBarView;
96 friend class KGantt;
97
98public:
99
100 enum Mode {Init, Select, Zoom, Move};
101
102
104
107 xQGanttBarViewPort(KGanttItem* toplevelitem, xQGanttBarView* parent = 0,
108 const char * name=0, WFlags f=0 );
109
110
112
116
117
118
120
123 void update(int x1, int y1, int x2, int y2);
124
125
126
127 TQPtrDict<xTQTaskPosition> _gItemList;
128
129
131
134 void addHoliday(int y, int m, int d);
135
136
137
139
142 void removeHoliday(int y, int m, int d) {
143 Q_UNUSED(y); Q_UNUSED(m); Q_UNUSED(d);
144 }
145
146
147
148 TDEPopupMenu* menu() {
149 return _menu;
150 }
151
152
153
155
158 TDEToolBar* toolbar(TQMainWindow* mw = 0);
159
160
161 // zoom by factor sfactor and move wx,wy to the center
162 void zoom(double sfactor, int wx, int wy);
163
164 // zoom by factor, and leave the center unmoved
165 void zoom(double sfactor);
166
167
168 void getSelectedItems(TQPtrList<KGanttItem>& list) {
169 getSelectedItems(_toplevelitem, list);
170 }
171
172
173signals:
174
175 void modeChanged(int);
176 void scroll(int x, int y);
177 void resized();
178 void recalculated();
179 void message(const TQString& msg);
180
181
182protected slots:
183
184 void setMode(int mode);
185
186 void setSelect();
187 void setZoom();
188 void setMove();
189
190 void zoomIn();
191 void zoomOut();
192 void zoomAll();
193
194 void popup(int index);
195
196 void selectAll();
197 void unselectAll();
198
199 void deleteSelectedItems();
200 void insertIntoSelectedItem();
201
202
203
204private slots:
205
206 void toplevelitemChanged(KGanttItem* item, KGanttItem::Change c);
207 void textEdited();
208 void itemDestroyed(KGanttItem*);
209
210
211
212private:
213
214 enum Position { Outside = 0, Handle = 1,
215 North = 2, South = 4,
216 West = 8, East = 16,
217 Center = 32 };
218
220
223 inline int screenX(int wx);
224
225
227
230 inline int screenY(int wy);
231
232
234
237 inline int worldX(int sx);
238
239
241
244 inline int worldY(int sy);
245
246
247 // this will be set by setParentScrollView()
248 xQGanttBarView* _parent;
249
250 int _grid, _snapgrid;
251 bool _drawGrid, _drawHeader;
252
253 Mode _mode;
254
255 int _marginX, _marginY; // margin in minutes
256 double _scaleX, _scaleY;
257
258 int _margin;
259
260
261 TQCursor* _cursor_lupe;
262
263 TQLabel* _itemInfo;
264 TQLineEdit* _itemTextEdit;
265
266
267 // all item are stored here
268 KGanttItem* _toplevelitem;
269
270 static KGanttItem* _currentItem;
271
272 TDEPopupMenu* _menu;
273 TDEPopupMenu* _selectMenu;
274
275 TDEIconLoader* _iconloader;
276
277 TDEToolBar* _toolbar;
278
279 TQPoint* _startPoint, *_endPoint;
280
281 TQPtrList<TQDate> _holidays;
282
283 TQPtrList<KGanttItem> *_observedList;
284
285
287
288 void initMenu();
289
290 void drawGrid(TQPainter*, int x1, int y1, int x2, int y2);
291 void drawHeader(TQPainter*, int x1, int y1, int x2, int y2);
292 void drawItem(KGanttItem* item, TQPainter* p, const TQRect& rect );
293
294 void drawRelation(TQPainter*, KGanttRelation*);
295
296 void recalc(KGanttItem* item, int xPos, int yPos, int depth, int nr );
297 void recalc();
298
299 void selectItem(KGanttItem*,bool);
300
301 void getSelectedItems(KGanttItem*, TQPtrList<KGanttItem>&);
302
303 void adjustSize();
304
305 void observeList(TQPtrList<KGanttItem>*);
306
307 Position check(KGanttItem** founditem, int x, int y);
308
309 void mousePressEvent(TQMouseEvent*);
310 void mouseReleaseEvent(TQMouseEvent*);
311
312 void wheelEvent ( TQWheelEvent * /*e*/) {
313 printf("wheelEvent\n");
314 }
315
316 void mouseMoveEvent(TQMouseEvent*);
317 void keyPressEvent(TQKeyEvent* e);
318 void paintEvent(TQPaintEvent * e);
319
320
321 TQPixmap closedIcon, openedIcon;
322
323};
324
325
326
327
328// inline
329
330
331int xQGanttBarViewPort::screenX(int wx)
333{
334 return (int) (0.5 + (wx + _marginX) * _scaleX);
335}
336int xQGanttBarViewPort::screenY(int wy)
338{
339 return (int) (0.5 + (wy + _marginY) * _scaleY);
340}
341int xQGanttBarViewPort::worldX(int sx)
343{
344 return (int) (0.5 + (sx/_scaleX - _marginX));
345}
346int xQGanttBarViewPort::worldY(int sy)
348{
349 return (int) (0.5 + (sy/_scaleY - _marginY));
350}
351
352
353#endif
KGanttItem.
Definition: KGanttItem.h:56
KGanttRelation.
Gantt Widget.
Definition: KGantt.h:92
void getSelectedItems(TQPtrList< KGanttItem > &list)
Get all selected items.
Definition: KGantt.h:216
TDEPopupMenu * menu()
Get popup menu.
Definition: KGantt.h:182
TDEToolBar * toolbar(TQMainWindow *mw=0)
Add gantt toolbar to main window.
Definition: KGantt.h:198
GanttBarViewPort Widget.
void removeHoliday(int y, int m, int d)
Remove holiday.
Gantt view.