fastmap/DrawScene.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of fastmap.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
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 General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created : 2008-09-13
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef DRAWSCENE_H
00028 #define DRAWSCENE_H
00029 
00030 #include <QtGui>
00031 
00032 class DimensionItem;
00033 class EllipseItem;
00034 class TextItem;
00035 class LineItemDelegate;
00036 class RectItemDelegate;
00037 class EllipseItemDelegate;
00038 class TextItemDelegate;
00039 class DimensionItemDelegate;
00040 class MapProject;
00041 
00042 class DrawScene : public QGraphicsScene
00043 {
00044 public:
00045   DrawScene();
00046   ~DrawScene();
00047 
00048   enum Unit {Millimeter, Centimeter, Meter, Kilometer};
00049 
00050   void setUnit(Unit u) {_unit=u;}
00051   Unit unit() const {return _unit;}
00052 
00053   double unitToDots(int dpi);
00054 
00055   void setScale(double s) {_scale=s;}
00056   double scale() const {return _scale;}
00057 
00058   void setMargin(double m) {_margin=m;}
00059   double margin() const {return _margin;}
00060 
00061   void setScaling(bool s) {_scaling=s;}
00062   bool scaling() const {return _scaling;}
00063 
00064   double scale(double val);
00065   QPointF scale(const QPointF& p);
00066 
00067   enum CoordinateType {CartesianAbsolute, CartesianRelative, PolarAbsolute, PolarRelative};
00068 
00069   void setCoordinateType(CoordinateType ct) {_coordinateType=ct;}
00070 
00071   void setPen(const QPen& p) {_currentPen=p;}
00072   const QPen& pen() const {return _currentPen;}
00073 
00074   void setBrush(const QBrush& b) {_currentBrush=b;}
00075   const QBrush& brush() const {return _currentBrush;}
00076 
00077   void setFont(const QFont& f) {_currentFont=f;}
00078   const QFont& font() const {return _currentFont;}
00079 
00080   QPointF currentPoint() const {return _currentPoint;}
00081   void setCurrentPoint(double x, double y);
00082   void moveTo(const QPointF& p);
00083 
00084   QGraphicsLineItem * addLine(const QLineF & line, const QPen & pen=QPen());
00085   QGraphicsRectItem * addRect(const QRectF & rect, const QPen & pen=QPen(), const QBrush & brush=QBrush());
00086   EllipseItem * addEllipse(const QRectF& rect, double start, double span, const QPen& pen=QPen(), const QBrush& brush=QBrush());
00087   TextItem * addText(const QString& t, const QFont & f=QFont(), const QPen& pen=QPen(), const QBrush& brush=QBrush());
00088   DimensionItem * addDimension(const QLineF & line, const QFont& f=QFont(), const QPen & pen=QPen(), const QBrush& brush=QBrush());
00089 
00090   void clear();
00091   bool parse(const QString cmd);
00092 
00093   QList<QPointF> nodes(const QRectF& rect);
00094 private:
00095   inline double scaleHelper(double val);
00096 
00097   Unit _unit;
00098   double _scale;
00099   double _margin;
00100   bool _scaling;
00101 
00102   QPointF _currentPoint;
00103   float _currentAzimuth;
00104   CoordinateType _coordinateType;
00105   QPen _currentPen;
00106   QBrush _currentBrush;
00107   QFont _currentFont;
00108   // Item editors
00109   LineItemDelegate * _lineDelegate;
00110   RectItemDelegate * _rectDelegate;
00111   TextItemDelegate * _textDelegate;
00112   EllipseItemDelegate * _ellipseDelegate;
00113   DimensionItemDelegate * _dimensionDelegate;
00114 };
00115 
00116 #endif // DRAWSCENE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines