00001 #ifndef WORKSHEET_H
00002 #define WORKSHEET_H
00003
00004 #include <qwidget.h>
00005 #include <qpainter.h>
00006 #include <qstring.h>
00007 #include <qfont.h>
00008 #include <qcolor.h>
00009 #include <qtextstream.h>
00010 #include <qdatetime.h>
00011 #include <kprinter.h>
00012 #include "MainWin.h"
00013 #include "Plot.h"
00014 #include "Label.h"
00015 #include "Line.h"
00016 #include "Rect.h"
00017 #include "Ellipse.h"
00018 #include "LImage.h"
00019 #include "widgettype.h"
00020 #include "scale.h"
00021
00022 #ifdef HAVE_UNDO
00023 extern "C" {
00024 #include "undo.h"
00025 }
00026 #endif
00027
00028 #define NR_PLOTS 16
00029 #define NR_OBJECTS 100
00030
00031 class MainWin;
00032 class Plot;
00033 class Plot2DSimple;
00034 class Plot2DSurface;
00035 class Plot3D;
00036 class PlotQWT3D;
00037 class PlotPie;
00038 class PlotPolar;
00039 class PlotTernary;
00040
00041 class Worksheet: public QWidget
00042 {
00043 Q_OBJECT
00044
00045
00046 Q_PROPERTY(bool title_enabled READ TitleEnabled WRITE setTitleEnabled)
00047 Q_PROPERTY(bool timestamp_enabled READ TimeStampEnabled WRITE setTimeStampEnabled)
00048 Q_PROPERTY(QDateTime timestamp READ TimeStamp WRITE setTimeStamp)
00049 Q_PROPERTY(QColor background READ Background WRITE setBackground)
00050 private:
00051 MainWin *mw;
00052 WidgetType widgettype;
00053 Plot *plot[NR_PLOTS];
00054 KPrinter *printer;
00055 QPixmap *pixmap;
00056 QString title;
00057 bool title_enabled;
00058 QDateTime timestamp;
00059 bool timestamp_enabled;
00060 QColor background;
00061
00062 Label *label[NR_OBJECTS];
00063 Line *line[NR_OBJECTS];
00064 Rect *rect[NR_OBJECTS];
00065 Ellipse *ellipse[NR_OBJECTS];
00066 LImage *image[NR_OBJECTS];
00067
00068 int X, Y;
00069 int lx, ly;
00070 int ax, ay, anumber;
00071 int tx, ty;
00072 int bx, by;
00073 int tlx, tly;
00074 int tmagx, tmagy,tmagx2,tmagy2;
00075 int tmaskx, tmasky,tmaskx2,tmasky2;
00076 double tpanx, tpany;
00077 int tdatamodex;
00078 int linesx,linesy,lineex,lineey,labelx,labely,rectx,recty;
00079 int ellipsex,ellipsey,imagex,imagey;
00080 bool moving_cornerF1, moving_cornerF2;
00081 bool moving_cornerB1, moving_cornerB2;
00082 bool moving_borderx1, moving_borderx2;
00083 bool moving_bordery1, moving_bordery2;
00084 bool moving_center;
00085 int object_index;
00086 int tmp_object_index;
00087 unsigned int api, nr_plots;
00088 public:
00089 Worksheet(QWidget *parent, MainWin *mw, const char *name);
00090 static void* operator new(size_t size);
00091 static void operator delete(void *p);
00092 void closeNow();
00093 WidgetType getWidgetType() { return widgettype; }
00094 QStringList Info();
00095 MainWin *getMainWin() { return mw; }
00096 Plot *getPlot(int i) { return plot[i]; }
00097 void setPlot(int i,Plot *p) { plot[i] = p; }
00098 #ifdef HAVE_UNDO
00099 UNDO *getUndo();
00100 void setUndo(UNDO *u);
00101 #endif
00102 void updatePixmap();
00103 void New();
00104 void save(QTextStream *t);
00105 void open(QTextStream *t,int version, PType oldtype);
00106 QDomElement saveXML(QDomDocument doc);
00107 void openXML(QDomNode node);
00108
00109
00110 void addGraph2D(Graph2D *g,PType type=P2D);
00111 void addGraph3D(Graph3D *g,PType type=P3D);
00112 void addGraphM(GraphM *g,PType type=PSURFACE);
00113 void addGraph4D(Graph4D *g);
00114 void addGraphIMAGE(GraphIMAGE *g);
00115 void addGraphL(GraphL *g,PType type=PPIE);
00116
00117 void resetRanges();
00118 void checkRanges(TScale scale, double *min, double *max);
00119 double partRanges(TScale scale, double min, double max);
00120 public slots:
00121 void Export(QString filename, QString format);
00122 void ExportPS(QString filename);
00123 void ExportEPS(QString filename);
00124 void ExportPDF(QString filename);
00125 void ExportSVG(QString filename);
00126 void ExportPIC(QString filename);
00127 void Print(QString filename);
00128
00129
00130 Plot2DSimple* get2DPlot(int i);
00131 Plot2DSimple* get2DSimplePlot(int i) { return get2DPlot(i);}
00132 Plot2DSurface* get2DSurfacePlot(int i);
00133 Plot3D* get3DPlot(int i);
00134 PlotQWT3D* getQWT3DPlot(int i);
00135 PlotPie* getPiePlot(int i);
00136 PlotPolar* getPolarPlot(int i);
00137 PlotTernary* getTernaryPlot(int i);
00138
00139 Plot* newPlot(PType type=P2D, bool insert=true);
00140 Plot* clonePlot(int item, bool insert=true);
00141 void deletePlot(int i);
00142 void deleteActivePlot();
00143
00144 int getX() { return X; }
00145 int getY() { return Y; }
00146 void redraw() {updatePixmap();}
00147 int API() { return api; }
00148 unsigned int NrPlots() { return nr_plots; }
00149 void setNrPlots(unsigned int i) { nr_plots=i; }
00150
00151 int NrObjects() { return NR_OBJECTS; }
00152 Line* getLine(int i) { return line[i]; }
00153 void setLine(int i, Line *l) { line[i]=l; }
00154 Label* getLabel(int i) { return label[i]; }
00155 void setLabel(int i, Label *l) { label[i]=l; }
00156 Rect* getRect(int i) { return rect[i]; }
00157 void setRect(int i, Rect *r) { rect[i]=r; }
00158 Ellipse* getEllipse(int i) { return ellipse[i]; }
00159 void setEllipse(int i, Ellipse* e) { ellipse[i]=e; }
00160 LImage* getImage(int i) { return image[i]; }
00161 void setImage(int i, LImage* im) { image[i]=im; }
00162
00163 QString Title() const { return title; }
00164 void setTitle(QString t) { title = t.remove(QChar('&')); setCaption(title); updatePixmap(); }
00165 bool TitleEnabled() const { return title_enabled; }
00166 void enableTitle(bool e=true) { title_enabled = e; updatePixmap(); }
00167 void setTitleEnabled(bool e=true) { enableTitle(e); }
00168 QDateTime TimeStamp() const { return timestamp; }
00169 void setTimeStamp(QDateTime ts) { timestamp = ts; updatePixmap(); }
00170 bool TimeStampEnabled() const { return timestamp_enabled; }
00171 void enableTimeStamp(bool e=true) { timestamp_enabled = e;updatePixmap(); }
00172 void setTimeStampEnabled(bool e=true) { enableTimeStamp(e); }
00173 QColor Background() const { return background; }
00174 void setBackground(QColor c) { background = c; updatePixmap(); }
00175 void setBackground(QString c) { setBackground(QColor(c)); }
00176 protected:
00177 void resizeEvent( QResizeEvent * );
00178 void paintEvent( QPaintEvent * );
00179 void mousePressEvent( QMouseEvent *);
00180 void mouseReleaseEvent( QMouseEvent *);
00181 void mouseDoubleClickEvent( QMouseEvent * );
00182 void mouseMoveEvent( QMouseEvent * );
00183 void keyPressEvent(QKeyEvent *);
00184 void closeEvent(QCloseEvent *);
00185 void Draw(QPainter *,int w, int h);
00186 void setupPrinter(KPrinter *pr, QString fn);
00187 double XCoordinate(double x, double xmin, double xmax);
00188 double YCoordinate(double y, double ymin, double ymax);
00189 };
00190
00191 #endif //WORKSHEET