Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Examples  

splinegraph.h

00001 /* splinegraph.h   Qt widget for entering a spline curve graphically
00002  * 
00003  * Copyright 2001 Ken McMillan
00004  *
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 
00021 #include <vector>
00022 #include <qwidget.h>
00023 #include <qpainter.h>
00024 
00025 class SplineInterpolator {
00026  public:
00027   vector<float> xpts,ypts;
00028   virtual float operator()(float) = 0;
00029   virtual void recalculate() = 0;
00030 };
00031 
00032 class SplineGraph : public QWidget {
00033   Q_OBJECT
00034 public:
00035   SplineGraph(SplineInterpolator *, float _xmin, float _xmax, float _ymin, float _ymax);
00036   void setXRange(float,float);
00037   void setYRange(float,float);
00038   void setPoints(vector<float> &_xpts, vector<float> &_ypts);
00039 
00040 protected:
00041   virtual void paintEvent( QPaintEvent*);
00042   void mousePressEvent(QMouseEvent *);
00043   void mouseReleaseEvent ( QMouseEvent *);
00044   void mouseMoveEvent ( QMouseEvent * );
00045 
00046 private:
00047   SplineInterpolator *interp;
00048   float xmin,xmax,ymin,ymax,xright,xleft; 
00049   QSize graphSize;
00050   int borderwidth;
00051   int gtop,gbottom,gright,gleft;
00052   QPixmap* _buffer;
00053   bool draggingPoint;
00054   int draggedPoint;
00055   float XScaleUnit,YScaleUnit;
00056 
00057   int xPoint(float x);
00058   int yPoint(float y);
00059   float xPointInv(int x);
00060   float yPointInv(int y);
00061   void drawGraph();
00062   void drawScale(QPainter &p, 
00063                  Orientation scaleDir, 
00064                  int pos, int tickDir);
00065   
00066 };
00067 

Generated at Sun Jan 18 20:51:22 2004 for Jezabel by doxygen1.2.8.1 written by Dimitri van Heesch, © 1997-2001