00001
#ifndef _XQGANTTBARVIEWPORT_H_
00002
#define _XQGANTTBARVIEWPORT_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00052
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;
00071
int _screenHS;
00072
int _textPosX, _textPosY;
00073
00074
int _screenHandleX, _screenHandleY, _screenHandleW, _screenHandleH;
00075
00076
int _depth;
00077
00078 };
00079
00080
00081
00083
00087
00088 class 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 }
00143
00144
00145
00146 KPopupMenu* menu() {
00147
return _menu;
00148 }
00149
00150
00151
00153
00156 KToolBar* toolbar(QMainWindow* mw = 0);
00157
00158
00159
00160
void zoom(
double sfactor,
int wx,
int wy);
00161
00162
00163
void zoom(
double sfactor);
00164
00165
00166
void getSelectedItems(QPtrList<KGanttItem>& list) {
00167 getSelectedItems(_toplevelitem, list);
00168 }
00169
00170
00171 signals:
00172
00173
void modeChanged(
int);
00174
void scroll(
int x,
int y);
00175
void resized();
00176
void recalculated();
00177
void message(
const QString& msg);
00178
00179
00180
protected slots:
00181
00182
void setMode(
int mode);
00183
00184
void setSelect();
00185
void setZoom();
00186
void setMove();
00187
00188
void zoomIn();
00189
void zoomOut();
00190
void zoomAll();
00191
00192
void popup(
int index);
00193
00194
void selectAll();
00195
void unselectAll();
00196
00197
void deleteSelectedItems();
00198
void insertIntoSelectedItem();
00199
00200
00201
00202
private slots:
00203
00204
void toplevelitemChanged(
KGanttItem* item, KGanttItem::Change c);
00205
void textEdited();
00206
void itemDestroyed(
KGanttItem*);
00207
00208
00209
00210
private:
00211
00212
enum Position { Outside = 0, Handle = 1,
00213 North = 2, South = 4,
00214 West = 8, East = 16,
00215 Center = 32 };
00216
00218
00221
inline int screenX(
int wx);
00222
00223
00225
00228
inline int screenY(
int wy);
00229
00230
00232
00235
inline int worldX(
int sx);
00236
00237
00239
00242
inline int worldY(
int sy);
00243
00244
00245
00246
xQGanttBarView* _parent;
00247
00248
int _grid, _snapgrid;
00249
bool _drawGrid, _drawHeader;
00250
00251 Mode _mode;
00252
00253
int _marginX, _marginY;
00254
double _scaleX, _scaleY;
00255
00256
int _margin;
00257
00258
00259 QCursor* _cursor_lupe;
00260
00261 QLabel* _itemInfo;
00262 QLineEdit* _itemTextEdit;
00263
00264
00265
00266
KGanttItem* _toplevelitem;
00267
00268
static KGanttItem* _currentItem;
00269
00270 KPopupMenu* _menu;
00271 KPopupMenu* _selectMenu;
00272
00273 KIconLoader* _iconloader;
00274
00275 KToolBar* _toolbar;
00276
00277 QPoint* _startPoint, *_endPoint;
00278
00279 QPtrList<QDate> _holidays;
00280
00281 QPtrList<KGanttItem> *_observedList;
00282
00283
00285
00286
void initMenu();
00287
00288
void drawGrid(QPainter*,
int x1,
int y1,
int x2,
int y2);
00289
void drawHeader(QPainter*,
int x1,
int y1,
int x2,
int y2);
00290
void drawItem(
KGanttItem* item, QPainter* p,
const QRect& rect );
00291
00292
void drawRelation(QPainter*,
KGanttRelation*);
00293
00294
void recalc(
KGanttItem* item,
int xPos,
int yPos,
int depth,
int nr );
00295
void recalc();
00296
00297
void selectItem(
KGanttItem*,
bool);
00298
00299
void getSelectedItems(
KGanttItem*, QPtrList<KGanttItem>&);
00300
00301
void adjustSize();
00302
00303
void observeList(QPtrList<KGanttItem>*);
00304
00305 Position check(
KGanttItem** founditem,
int x,
int y);
00306
00307
void mousePressEvent(QMouseEvent*);
00308
void mouseReleaseEvent(QMouseEvent*);
00309
00310
void wheelEvent ( QWheelEvent * e) {
00311 printf(
"wheelEvent\n");
00312 }
00313
00314
void mouseMoveEvent(QMouseEvent*);
00315
void keyPressEvent(QKeyEvent* e);
00316
void paintEvent(QPaintEvent * e);
00317
00318
00319 QPixmap closedIcon, openedIcon;
00320
00321 };
00322
00323
00324
00325
00326
00327
00328
00329
int xQGanttBarViewPort::screenX(
int wx)
00331 {
00332
return (
int) (0.5 + (wx + _marginX) * _scaleX);
00333 }
00334
int xQGanttBarViewPort::screenY(
int wy)
00336 {
00337
return (
int) (0.5 + (wy + _marginY) * _scaleY);
00338 }
00339
int xQGanttBarViewPort::worldX(
int sx)
00341 {
00342
return (
int) (0.5 + (sx/_scaleX - _marginX));
00343 }
00344
int xQGanttBarViewPort::worldY(
int sy)
00346 {
00347
return (
int) (0.5 + (sy/_scaleY - _marginY));
00348 }
00349
00350
00351
#endif