SciFigs/GraphContentOptions.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of SciFigs.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2008-02-18
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (LGIT, Grenoble, France)
00025 **
00026 ***************************************************************************/
00027 
00028 #ifndef GRAPHCONTENTOPTIONS_H
00029 #define GRAPHCONTENTOPTIONS_H
00030 
00031 #include <QtGui>
00032 #include "Scale.h"
00033 #include "SciFigsDLLExport.h"
00034 
00035 namespace SciFigs {
00036 
00037 class SCIFIGS_EXPORT GraphContentOptions : public QSharedData
00038 {
00039   TRANSLATIONS("GraphContentOptions")
00040 public:
00041   GraphContentOptions();
00042   GraphContentOptions(const GraphContentOptions& o);
00043   ~GraphContentOptions();
00044 
00045   // X and Y scales
00046   Scale& scaleX() {return _scaleX;}
00047   Scale& scaleY() {return _scaleY;}
00048   const Scale& scaleX() const {return _scaleX;}
00049   const Scale& scaleY() const {return _scaleY;}
00050   // coordinates conversion for screen
00051   int xr2s(double x) const {return _scaleX.r2s(x);}
00052   int yr2s(double y) const {return _scaleY.r2s(y);}
00053   QPoint r2s(double x, double y) const {return QPoint(xr2s(x), yr2s(y));}
00054   QPoint r2s(const Point& p) const {return QPoint(xr2s(p.x()), yr2s(p.y()));}
00055   QPoint r2s(const Point2D& p) const {return QPoint(xr2s(p.x()), yr2s(p.y()));}
00056   // coordinates conversion for screen in floating point values
00057   double xr2sF(double x) const {return _scaleX.r2sF(x);}
00058   double yr2sF(double y) const {return _scaleY.r2sF(y);}
00059   QPointF r2sF(double x, double y) const {return QPointF(xr2sF(x), yr2sF(y));}
00060   QPointF r2sF(const Point& p) const {return QPointF(xr2sF(p.x()), yr2sF(p.y()));}
00061   QPointF r2sF(const Point2D& p) const {return QPointF(xr2sF(p.x()), yr2sF(p.y()));}
00062   /*
00063      Returns true if the segment must be drawn
00064      This tranformation function is used to avoid overflow in super zoomed graphics
00065   */
00066   bool r2s(const Point2D& p1, const Point2D& p2, QPoint& ps1, QPoint& ps2) const;
00067   bool yr2s(const Point2D& p1, const Point2D& p2, QPoint& ps1, QPoint& ps2) const;
00068   inline bool r2s(const Point& p1, const Point& p2, QPoint& ps1, QPoint& ps2) const;
00069   /* I noticed that on some linux systems it is forbiden to draw a line
00070      outside the widget frame especially for negative X and Y greater than
00071      height(), this is why I'm forced to check this at the end of the
00072      routine before drawing
00073   */
00074   inline void checkOrigin(QPoint& ps1, QPoint& ps2, int h) const;
00075   double xs2r(int x) const {return _scaleX.s2r(x);}
00076   double ys2r(int y) const {return _scaleY.s2r(y);}
00077   Point s2r(const QPoint& p) const {return Point(xs2r( p.x()), ys2r(p.y()) );}
00078   Point2D s2r2D(const QPoint& p) const {return Point2D(xs2r( p.x()), ys2r(p.y()) );}
00079   double xVisMin() const {return _scaleX.minimum();}
00080   double yVisMin() const {return _scaleY.minimum();}
00081   double xVisMax() const {return _scaleX.maximum();}
00082   double yVisMax() const {return _scaleY.maximum();}
00083   double ax() const {return _scaleX.a();}
00084   double ay() const {return _scaleY.a();}
00085   double bx() const {return _scaleX.b();}
00086   double by() const {return _scaleY.b();}
00087 
00088   bool gridLines() const {return _gridLines;}
00089   void setGridLines(bool g) {_gridLines=g;}
00090 
00091   const QColor& gridLineColor() const {return _gridLineColor;}
00092   void setGridLineColor(const QColor& c) {_gridLineColor=c;}
00093 
00094   bool transparentMask() const {return _transparentMask;}
00095   void setTransparentMask(bool tm) {_transparentMask=tm;}
00096 
00097   double gridLineWeight() const {return _gridLineWeight;}
00098   void setGridLineWeight(double lw) {_gridLineWeight=lw;}
00099 
00100   double contourWeight() const {return _contourWeight;}
00101   void setContourWeight(double lw) {_contourWeight=lw;}
00102 
00103   bool printBitmap() const {return _printBitmap;}
00104   void setPrintBitmap(bool p) {_printBitmap=p;}
00105 
00106   void paintGridLines (QPainter& p, double dotpercm, int w, int h) const;
00107   void paintContour (QPainter& p, double dotpercm, int w, int h) const;
00108 
00109   void swapAxes();
00110 private:
00111   inline bool oneInside(const Point2D& p1, const Point2D& p2, QPoint& ps1, QPoint& ps2) const;
00112   inline bool bothOutside(const Point2D& p1, const Point2D& p2, QPoint& ps1, QPoint& ps2) const;
00113 
00114   bool _gridLines;
00115   bool _transparentMask;
00116   QColor _gridLineColor;
00117   double _gridLineWeight;
00118   double _contourWeight;
00119   bool _printBitmap;
00120 
00121   Scale _scaleX;
00122   Scale _scaleY;
00123 };
00124 
00125 inline bool GraphContentOptions::r2s(const Point& p1, const Point& p2, QPoint& ps1, QPoint& ps2) const
00126 {
00127   TRACE;
00128   Point2D p2D1=p1;
00129   Point2D p2D2=p2;
00130   return r2s(p2D1, p2D2, ps1, ps2);
00131 }
00132 
00133 inline void GraphContentOptions::checkOrigin(QPoint& ps1, QPoint& ps2, int h) const
00134 {
00135   TRACE;
00136   if(ps1.x() < 0) ps1.setX(0);
00137   if(ps1.y() >= h) ps1.setY(h - 1);
00138   if(ps2.x() < 0) ps2.setX(0);
00139   if(ps2.y() >= h) ps2.setY(h - 1);
00140 }
00141 
00142 } // namespace SciFigs
00143 
00144 #endif // GRAPHCONTENTOPTIONS_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines