Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
basicgraph.h00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef BASICGRAPH_H
00019 #define BASICGRAPH_H
00020
00021 #include <qwidget.h>
00022
00023 #include <vector>
00024
00025 #include "commongraph.h"
00026 #include "mathfunctionimplementor.h"
00027
00028 #ifdef KDE_APP
00029 class KPrinter;
00030 #else
00031 class QPrinter;
00032 #endif
00033
00034 class QPainter;
00035 class QPixmap;
00036
00037 class Mathfunction;
00038 class GraphEvent;
00039
00046 class BasicGraph : public QWidget, public CommonGraph, public MathFunctionImplementor
00047 {
00048 Q_OBJECT
00049
00050 public:
00051 BasicGraph ( QWidget *parent=0, const char *name=0 );
00052 virtual ~BasicGraph();
00053
00054 virtual void load_key( const char *key, const char *value );
00055
00057 QColor axisColor() const;
00058
00060 QColor gridColor() const;
00061
00063 QColor backgroundColor() const;
00064
00066 QColor scaleColor() const;
00067
00068 #ifdef KDE_APP
00069 virtual void print(KPrinter *);
00070 #else
00071 virtual void print(QPrinter *);
00072 #endif //KDE_APP
00073
00075 int setXMin(double xMin);
00076
00078 int setXMax(double xMax);
00079
00081 int setXScale(double xScale);
00082
00084 int setYMin(double yMin);
00085
00087 int setYMax(double yMax);
00088
00090 int setYScale(double yScale);
00091
00093 inline double getXMin() const{return xMin;}
00094
00096 inline double getXMax() const{return xMax;}
00097
00099 inline double getYMin() const{return yMin;}
00100
00102 inline double getYMax() const{return yMax;}
00103
00105 inline double getXScale() const{return xScale2;}
00106
00108 inline double getYScale() const{return yScale2;}
00109
00111 inline double getRScale() const{return getXScale();}
00112
00114 inline double getAScale() const{return getYScale();}
00115
00117 inline bool getAxisState() const{return showAxis;}
00118
00120 inline bool getGridState() const{return showGrid;}
00121
00123 inline bool getScaleState() const{return showScale;}
00124
00126 int getXZoomFactor() const;
00127
00129 int getYZoomFactor() const;
00130
00134 inline double getMouseX() const{return mouseX;}
00135
00139 inline double getMouseY() const{return mouseY;}
00140
00141 inline QPoint getMousePoint() const{return QPoint(toPixelXCoord(mouseX),toPixelYCoord(mouseY));}
00142
00146 int setRange(double xMin,double xMax,double yMin,double yMax);
00147
00148 inline virtual void setSnapToGrid(bool b){snapToGrid = b;}
00149 inline virtual bool isSnapToGrid() const{return snapToGrid;}
00150
00151 virtual void installMathFunctions();
00152 virtual int execMathFunction( const char * id );
00153
00159 void offscreenResize(int width, int height);
00160
00161 public slots:
00162 int setAScale(double d){return setYScale(d);}
00163 int setRScale(double d){return setXScale(d);}
00164 void setGrid(bool);
00165 void setAxis(bool);
00166 void setGridNum(bool);
00167 void setScale(bool);
00168 void setXZoomFactor(int);
00169 void setYZoomFactor(int);
00170 void setAxisColor(const QColor &);
00171 void setGridColor(const QColor &);
00172 void setBackgroundColor(const QColor &);
00173 void setScaleColor(const QColor &);
00174 void zoomIn();
00175 void zoomOut();
00176 void setAxisWidth(int);
00177 void zoomStd();
00178 void zoomBox();
00179
00180 signals:
00181 void dimensionsChanged( const GraphEvent & );
00182 void activeCoordinateChanged( const QString &, const QString & = QString(), const QString & = QString() );
00183 void infoMessageReady( const QString & );
00184
00185 protected:
00186 friend class MathFunction;
00187
00192 void setMouseX(double x_coordiniate,bool snapToGrid=true);
00193
00198 void setMouseY(double y_coordiniate,bool snapToGrid=true);
00199
00200 virtual void drawAfterAxis(QPainter *){}
00201
00202 inline virtual double snapIntervalX() const{return xScale2;}
00203 inline virtual double snapIntervalY() const{return yScale2;}
00204 inline virtual double startSnap() const{return 0;}
00205
00206 virtual void updateCoords();
00207
00208 void paint(QPainter*);
00209 void setCoordinateStyle(int i){mode = i;}
00210 double toGraphXCoord(double) const;
00211 double toGraphYCoord(double) const;
00212 int toPixelXCoord(double) const;
00213 int toPixelYCoord(double) const;
00214 void updateGraph();
00215 void emitDimensionsChanged();
00216
00217 double xMin,xMax,xScale2,yMin,yMax,yScale2,xScale,yScale,mouseX,mouseY;
00218 int xZoom,yZoom,axisWidth;
00219 QFont graphFont,scaleFont;
00220 QPainter *p;
00221 QPixmap *buffer;
00222
00223
00224 void paintEvent (QPaintEvent *);
00225 void resizeEvent (QResizeEvent *);
00226 void mouseDoubleClickEvent (QMouseEvent *);
00227 void mouseMoveEvent(QMouseEvent *);
00228 void mousePressEvent(QMouseEvent *);
00229 void mouseReleaseEvent ( QMouseEvent *);
00230
00231 private:
00232 bool mouseDown, doingZoomBox, snapToGrid;
00233 bool showAxis,showGrid,showGridNum,showScale;
00234 int mode;
00235 QPoint origin, lastClick;
00236 double lastClickGraphCoordX,lastClickGraphCoordY;
00237 QColor _axisColor,_gridColor,_backgroundColor,_scaleColor;
00238 void drawGrid (QPainter *);
00239 void drawScale(QPainter *);
00240 void drawAxis (QPainter *);
00241 };
00242
00243 #endif
|