QtiPlot 0.9.8.2
ArrowMarker.h
Go to the documentation of this file.
00001 /***************************************************************************
00002     File                 : ArrowMarker.h
00003     Project              : QtiPlot
00004     --------------------------------------------------------------------
00005     Copyright            : (C) 2006 - 2011 by Ion Vasilief
00006     Email (use @ for *)  : ion_vasilief*yahoo.fr
00007     Description          : Arrow marker (extension to QwtPlotMarker)
00008 
00009  ***************************************************************************/
00010 
00011 /***************************************************************************
00012  *                                                                         *
00013  *  This program is free software; you can redistribute it and/or modify   *
00014  *  it under the terms of the GNU General Public License as published by   *
00015  *  the Free Software Foundation; either version 2 of the License, or      *
00016  *  (at your option) any later version.                                    *
00017  *                                                                         *
00018  *  This program is distributed in the hope that it will be useful,        *
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00021  *  GNU General Public License for more details.                           *
00022  *                                                                         *
00023  *   You should have received a copy of the GNU General Public License     *
00024  *   along with this program; if not, write to the Free Software           *
00025  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
00026  *   Boston, MA  02110-1301  USA                                           *
00027  *                                                                         *
00028  ***************************************************************************/
00029 #ifndef ARROWMARKER_H
00030 #define ARROWMARKER_H
00031 
00032 #include <qwt_plot_marker.h>
00033 
00043 class ArrowMarker: public QObject, public QwtPlotMarker
00044 {
00045 public:
00046     enum Operation { None, MoveStart, MoveEnd, MoveBoth };
00047     enum AttachPolicy {Page, Scales};
00048     ArrowMarker();
00049 
00051     QPoint startPoint() const;
00053     void setStartPoint(const QPoint& p);
00054 
00056     QPoint endPoint() const;
00058     void setEndPoint(const QPoint& p);
00059 
00061     QwtDoublePoint startPointCoord();
00063     void setStartPoint(double x, double y);
00064 
00066     QwtDoublePoint endPointCoord();
00068     void setEndPoint(double x, double y);
00069 
00070     void setColor(const QColor& c);
00071     QColor color(){return linePen().color();};
00072 
00074     void setWidth(double w);
00076     double width(){return linePen().widthF();};
00077 
00079     double arrowWidth();
00080 
00082     void setStyle(Qt::PenStyle s);
00084     Qt::PenStyle style(){return linePen().style ();};
00085 
00087     void drawStartArrow(bool on = true){d_start_arrow = on;};
00088     bool hasStartArrow(){return d_start_arrow;};
00089 
00091     void drawEndArrow(bool on = true){d_end_arrow = on;};
00092     bool hasEndArrow(){return d_end_arrow;};
00093 
00095     int headLength(){return d_head_length;};
00097     void setHeadLength(int l);
00098 
00100     int headAngle(){return d_head_angle;};
00102     void setHeadAngle(int a);
00103 
00104     bool filledArrowHead(){return d_fill_head;};
00106     void fillArrowHead(bool fill = true);
00107 
00109     double dist(int x, int y);
00110 
00112     double length();
00113 
00115     QRect rect() const {return QRect(startPoint(), endPoint()).normalize();};
00116 
00118     QwtDoubleRect boundingRect() const;
00119     void setBoundingRect(double xs, double ys, double xe, double ye);
00120 
00122     void updateBoundingRect();
00123 
00125     bool editable() const { return d_editable; }
00127     void setEditable(bool yes);
00128 
00130     bool eventFilter(QObject *o, QEvent *e);
00131 
00132     void setAttachPolicy(AttachPolicy attachTo);
00133     AttachPolicy attachPolicy(){return d_attach_policy;};
00134 
00135 private:
00136     void displayInfo(bool clear = false);
00137     void draw(QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &r) const;
00138     double theta(int xs, int ys, int xe, int ye) const;
00139 
00141     bool d_start_arrow;
00142 
00144     bool d_end_arrow;
00145 
00147     bool d_fill_head;
00148 
00150     int d_head_angle;
00151 
00153     int d_head_length;
00154 
00156     QPoint d_start;
00157 
00159     QPoint d_end;
00160 
00162     QwtDoubleRect d_rect;
00164     bool d_editable;
00165 
00167     Operation d_op;
00168 
00174     QPoint d_op_startat;
00175 
00176     AttachPolicy d_attach_policy;
00177 };
00178 #endif