00001
00002
00003 #ifndef MAINWIN_H
00004 #define MAINWIN_H
00005
00006 #include <qstring.h>
00007 #include <qfont.h>
00008 #include <qlistbox.h>
00009 #include <qworkspace.h>
00010 #include <qtoolbutton.h>
00011 #include <qsignalmapper.h>
00012 #include <qdragobject.h>
00013 #include <qtimer.h>
00014 #include <kapp.h>
00015 #include <kmainwindow.h>
00016 #include <kparts/mainwindow.h>
00017 #include <kaction.h>
00018 #include <kkeydialog.h>
00019 #include <kstatusbar.h>
00020 #include <kstandarddirs.h>
00021 #include <kmenubar.h>
00022 #include "GraphList.h"
00023 #include "Spreadsheet.h"
00024 #include "Worksheet.h"
00025 #include "Project.h"
00026
00027 #ifdef HAVE_QSA
00028 #include <qsproject.h>
00029 #include <qsinterpreter.h>
00030 #ifdef HAVE_QSA_IDE
00031 #include <qsworkbench.h>
00032 #endif
00033 #endif
00034
00035 #define PROJECT_VERSION 21
00036
00037 extern "C" double parse(char[]);
00038 extern "C" int parse_errors();
00039
00040 class Worksheet;
00041 class Spreadsheet;
00042 class Plot;
00043 class Plot2DSimple;
00044
00045 class MainWin
00046 : public KParts::MainWindow
00047 {
00048 Q_OBJECT
00049 private:
00050 void readConfig();
00051 void enableAutosave(bool as);
00052 void newDialog(bool d, PType type);
00053 Plot *newPlot(PType type=P2D);
00054 QWorkspace* ws;
00055 QString filename;
00056 KParts::ReadOnlyPart* gvpart;
00057 QPopupMenu *spreadsheetpopup;
00058 QSignalMapper *sm, *smg;
00059 KConfig *config;
00060 KRecentFilesAction* recent;
00061 KAction *configureAction, *project_action, *explorer_action;
00062 KAction *import_action, *importopj_action, *export_image, *export_svg, *export_pic, *export_ps, *export_eps, *export_pdf;
00063 KAction *export_pstoedit, *export_ImageMagick, *print_action, *save_action, *save_as;
00064 KAction *graph_list, *plot_list, *clear_action, *close_action, *worksheet_action, *plot_action, *arrange, *overlay;
00065 KAction *deleteplot, *qwt3d_plot, *qwt3d_func, *qwt3d_data;
00066 KAction *evaluate, *operations, *imagepro;
00067 KAction *smooth, *prune, *average, *compress, *periodic, *seasonal, *hist, *peak;
00068 KAction *interpolation, *differences, *integration, *regression, *fft, *convolution, *wavelet, *hankel, *fit;
00069 KAction *axes, *title_action, *legend, *objects;
00070 KAction *asx, *asy, *asz, *asall, *maglens, *panzoom, *sl, *sr, *su, *sd, *sxu, *sxd, *syu, *syd, *szu, *szd;
00071 KAction *zoomin, *zoomout, *maskplot;
00072 KAction *baseline, *region, *label, *line, *rect, *ellipse, *image;
00073 KAction *ideAction, *scriptAction;
00074 KToggleAction *menubar, *toolbar, *sidetoolbar, *analysistoolbar, *drawingtoolbar, *statusbar;
00075 KToggleAction *printpreview, *togglespeedmode, *toggledatamode;
00076 bool printpreviewchecked;
00077 Project *project;
00078 QTimer *autosaveTimer;
00079 bool autosave;
00080 long autosaveinterval;
00081 bool modified;
00082 bool speedmode, datamode;
00083 int speedmodevalue;
00084 QFont defaultfont;
00085 int nr_w, nr_s;
00086 #ifdef HAVE_QSA
00087 QSProject *qsproject;
00088 #ifdef HAVE_QSA_IDE
00089 QSWorkbench *ide;
00090 #endif
00091 #endif
00092 bool is_fullscreen;
00093 private slots:
00094 void closeWin();
00095 void setWinFocus(int i) { (ws->windowList()).at(i)->setFocus(); }
00096 void SpreadsheetMenu();
00097
00098 void configure();
00099 void configureKeys() { KKeyDialog::configure(actionCollection(), this, true); }
00100 void configureToolbars();
00101 void saveSettings();
00102 void setAutosaveInterval(long interval) { autosaveinterval=interval;}
00103
00104 void openIDE();
00105 void reportBug();
00106 void exampleAxesLabel() { openfile(locate("data", QString("LabPlot/axeslabel.lpl.gz"))); }
00107 void exampleAnalysis() { openfile(locate("data", QString("LabPlot/analysis.lpl.gz"))); }
00108 void exampleSurface() { openfile(locate("data", QString("LabPlot/surface.lpl.gz"))); }
00109 void example3d() { openfile(locate("data", QString("LabPlot/3d.lpl.gz"))); }
00110 void exampleRydberg() { openfile(locate("data", QString("LabPlot/rydberg.lpl.gz"))); }
00111 void exampleLog() { openfile(locate("data", QString("LabPlot/log.lpl.gz"))); }
00112 void exampleFFT() { openfile(locate("data", QString("LabPlot/fft.lpl.gz"))); }
00113 void exampleObjects() { openfile(locate("data", QString("LabPlot/objects.lpl.gz"))); }
00114 void exampleHist() { openfile(locate("data", QString("LabPlot/hist.lpl.gz"))); }
00115 void exampleFit() { openfile(locate("data", QString("LabPlot/fit.lpl.gz"))); }
00116 void exampleImage() { openfile(locate("data", QString("LabPlot/image.lpl.gz"))); }
00117 void examplePie() { openfile(locate("data", QString("LabPlot/pie.lpl.gz"))); }
00118 void exampleExponentialFit() { openfile(locate("data", QString("LabPlot/exponential_fit.lpl.gz"))); }
00119 void exampleMultiplot() { openfile(locate("data", QString("LabPlot/multiplot.lpl.gz"))); }
00120 void exampleSurface2() { openfile(locate("data", QString("LabPlot/surface2.lpl.gz"))); }
00121 void examplePolar() { openfile(locate("data", QString("LabPlot/polar.lpl.gz"))); }
00122 void exampleTernary() { openfile(locate("data", QString("LabPlot/ternary.lpl.gz"))); }
00123 void exampleAudio() { openfile(locate("data", QString("LabPlot/audio.lpl.gz"))); }
00124 void exampleQWT() { openfile(locate("data", QString("LabPlot/qwt.lpl.gz"))); }
00125 void exampleBar() { openfile(locate("data", QString("LabPlot/bar.lpl.gz"))); }
00126 void exampleLogfit() { openfile(locate("data", QString("LabPlot/logfit.lpl.gz"))); }
00127 void exampleMarker() { openfile(locate("data", QString("LabPlot/marker.lpl.gz"))); }
00128 void exampleSurfaceStyle() { openfile(locate("data", QString("LabPlot/surfacestyle.lpl.gz"))); }
00129 void exampleTeXLabel() { openfile(locate("data", QString("LabPlot/texlabel.lpl.gz"))); }
00130 public slots:
00131 void open(QString fn=0);
00132 void New();
00133 void save(QString fn=0);
00134 void saveAs(QString fn=0);
00135 void projectInfo();
00136 void projectExplorer();
00137 void importData(QString fn,int filter=0);
00138 void importDialog();
00139 void importOPJ(QString fn=0);
00140 void exportPlot(QString fn=0, QString f=0);
00141 void exportPS(QString fn=0);
00142 void exportEPS(QString fn=0);
00143 void exportPDF(QString fn=0);
00144 void exportSVG(QString fn=0);
00145 void exportPIC(QString fn=0);
00146 void exportPstoEdit(QString fn=i18n("out.pdf"),int f=4, int s=5, double sc=1.0, double r=0.0);
00149 void exportPstoEditDialog();
00150 void exportImageMagick(QString fn=i18n("out.8bim"), int f=0, int sx=800, int sy=600, double r=0.0);
00153 void exportImageMagickDialog();
00154 void print();
00155 void printPreview();
00156 void graphDialog();
00157 void plotDialog();
00158
00159 void clear();
00160 void deletePlot();
00161 void loadScript(QString fn=0);
00162 void Environment();
00163 void aboutKDE();
00164 void exit() {modified=false; close(); }
00165 void toggleFullScreen();
00166 void toggleMenuBar();
00167 void toggleToolBar();
00168 void toggleSideToolBar();
00169 void toggleAnalysisToolBar();
00170 void toggleDrawingToolBar();
00171 void toggleStatusBar();
00172 bool speedMode() { return speedmode; }
00173 void setSpeedMode(bool s) { speedmode = s; }
00174 void toggleSpeedMode();
00175 int speedModeValue() { return speedmodevalue; }
00176 void setSpeedModeValue(int s) { speedmodevalue=s; }
00177 bool dataMode() { return datamode; }
00178 void setDataMode(bool d) { datamode = d; }
00179 QFont defaultFont() { return defaultfont; }
00180 void setDefaultFont(QFont f) { defaultfont=f; }
00181
00182 void newPlot(int type) { newPlot((PType) type); }
00183 Plot2DSimple* new2DPlot() { return (Plot2DSimple *) newPlot(P2D); }
00184 void newSurfacePlot() { newPlot(PSURFACE); }
00185 void new3DPlot() { newPlot(P3D); }
00186 void newPiePlot() { newPlot(PPIE); }
00187 void newPolarPlot() { newPlot(PPOLAR); }
00188 void newTernaryPlot() { newPlot(PTERNARY); }
00189 void newQWT3DPlot() { newPlot(PQWT3D); }
00190
00191 void new2DData() { newDialog(0,P2D); }
00192 void newSData() { newDialog(0,PSURFACE); }
00193 void new3DData() { newDialog(0,P3D); }
00194 void newPieData() { newDialog(0,PPIE); }
00195 void newPolarData() { newDialog(0,PPOLAR); }
00196 void newTernaryData() { newDialog(0,PTERNARY); }
00197 void newQWT3DData() { newDialog(0,PQWT3D); }
00198 void new2DFunction() { newDialog(1,P2D); }
00199 void new3DFunction() {newDialog(1,P3D); }
00200 void newQWT3DFunction() {newDialog(1,PQWT3D); }
00201 void newSFunction() { newDialog(1,PSURFACE); }
00202 void newPolarFunction() {newDialog(1,PPOLAR); }
00203
00204 Style* newStyle() { return new Style(); }
00205 Symbol* newSymbol() { return new Symbol(); }
00206 void lDebug(QString s) { kdDebug()<<s<<endl; }
00207
00208 void evaluateDialog();
00209 void operationsDialog();
00210 void smoothDialog();
00211 void averageDialog();
00212 void compressDialog();
00213 void pruneDialog();
00214 void periodicDialog();
00215 void seasonalDialog();
00216 void histDialog();
00217 void peakDialog();
00218 void interpolationDialog();
00219 void differencesDialog();
00220 void integrationDialog();
00221 void regressionDialog();
00222 void fftDialog();
00223 void convolutionDialog();
00224 void waveletDialog();
00225 void hankelDialog();
00226 void fitDialog();
00227 void imageDialog();
00228
00229 void arrangeDialog();
00230 void overlayDialog();
00231 void worksheetDialog();
00232 void plotSettingsDialog();
00233 void axesDialog();
00234 void titleDialog();
00235 void legendDialog();
00236 void objectDialog();
00237
00238 void autoScaleX();
00239 void autoScaleY();
00240 void autoScaleZ();
00241 void autoScaleAll();
00242 void shiftLeft();
00243 void shiftRight();
00244 void shiftUp();
00245 void shiftDown();
00246 void scaleXUp();
00247 void scaleXDown();
00248 void scaleYUp();
00249 void scaleYDown();
00250 void scaleZUp();
00251 void scaleZDown();
00252 void zoomIn();
00253 void zoomOut();
00254 void toggleDataMode();
00255
00256
00257 void open(const KURL& url);
00258
00259 void magLens();
00260 void panZoom();
00261 void maskPlot();
00262
00263 void defineRegion();
00264 void defineBaseline();
00265 void defineLine();
00266 void defineLabel();
00267 void defineRect();
00268 void defineEllipse();
00269 void defineImage();
00270
00271 void setActiveSheet(int i);
00272 void changeGraph(int i);
00273 Spreadsheet* newSpreadsheet();
00274 Worksheet* newWorksheet();
00275 Worksheet* activeWorksheet();
00276 Spreadsheet* activeSpreadsheet();
00277 void updateGraphList();
00278 void updateSheetList();
00279 public:
00280 MainWin(const char *name,const char *filen,bool is_part=false);
00281 void replot();
00282 void openfile(QString file);
00283 void message(QString msg) {statusBar()->message(msg); }
00284 KConfig* Config() { return config; }
00285 int defining_region, defining_line, defining_rect, defining_ellipse;
00286 int defining_maglens,defining_panzoom, defining_mask;
00287 bool defining_baseline,defining_label,defining_image;
00288 QString last_2dfunction, last_3dfunction, last_filename;
00289 int last_readas, last_nrpointsx, last_nrpointsy;
00290 double last_xmin, last_xmax, last_ymin, last_ymax;
00291
00292 Project *getProject() { return project; }
00293 void setProject(Project *p) { project=p; }
00294 #ifdef HAVE_QSA
00295 QSProject *getQSProject() { return qsproject; }
00296 #endif
00297 void readScript(QString name);
00298 QWorkspace *getWorkspace() { return ws; }
00299 void deleteActiveSheet();
00300 void setModified() {modified = true;}
00301 int NrSpreadsheets() { return nr_s; }
00302 int NrWorksheets() { return nr_w; }
00303 Worksheet *addWorksheet(PType type, int sheet);
00304 int addGraph2D(Graph2D *g, int item, PType type=P2D);
00305 int addGraph3D(Graph3D *g, int item, PType type=P3D);
00306 int addGraph4D(Graph4D *g, int item);
00307 int addGraphM(GraphM *g, int item, PType type=PSURFACE);
00308 int addGraphIMAGE(GraphIMAGE *g, int item);
00309 void calculateRanges2D(Point *a, int n, double *xmin, double *xmax,
00310 double *ymin, double *ymax);
00311 void calculateRanges3D(Point3D *a, int n, double *xmin, double *xmax,
00312 double *ymin, double *ymax, double *zmin, double *zmax);
00313 void calculateRanges4D(Point4D *a, int n, double *xmin, double *xmax,
00314 double *ymin, double *ymax, double *zmin, double *zmax, double *tmin, double *tmax);
00315 QString parseExpression(QString tmp, double value, int j);
00316 double formatLabel(QString value,int item);
00317 protected:
00318 void resizeEvent(QResizeEvent *e) { this->resize(e->size()); }
00319 void dragEnterEvent(QDragEnterEvent *e) { e->accept(QTextDrag::canDecode(e)); }
00320 void dropEvent(QDropEvent *e);
00321 void closeEvent(QCloseEvent *e);
00322 void mouseDoubleClickEvent(QMouseEvent *e) { e->pos(); if(!menuBar()->isVisible()) menuBar()->show(); }
00323
00324 };
00325
00326 #endif // MAINWIN_H