00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef SYMBOL_H
00030 #define SYMBOL_H
00031
00032 #include "SciFigsDLLExport.h"
00033 #include "Pen.h"
00034 #include "Brush.h"
00035
00036 namespace SciFigs {
00037
00038 class SCIFIGS_EXPORT Symbol : public XMLClass
00039 {
00040 public:
00041 enum Type{NoSymbol, Cross, Square, Circle, TriangleUp, TriangleDown, Losange, Star};
00042 Symbol(Type type=NoSymbol, double size=1.2, Pen pen=Pen(Qt::black),
00043 Brush brush=Brush(Qt::NoBrush));
00044 Symbol(const Symbol& s);
00045 virtual ~Symbol() {}
00046
00047 Symbol& operator=(const Symbol& o);
00048 bool operator==(const Symbol& o) const;
00049
00050 virtual const QString& xml_tagName() const {return xmlSymbolTag;}
00051 static const QString xmlSymbolTag;
00052
00053 static Type symbolValue(QString s);
00054 static QString symbolName(Type s);
00055
00056 void fromStream(QTextStream& s);
00057
00058 void setType(Type t) {_type=t;}
00059 Type type() const {return _type;}
00060
00061 void setSize(double s) {_size=s;}
00062 double size() const {return _size;}
00063
00064 void setPen(const Pen& p) {_pen=p;}
00065 const Pen& pen() const {return _pen;}
00066
00067 void setBrush(const Brush& b) {_brush=b;}
00068 const Brush& brush() const {return _brush;}
00069
00070 void paint(QPainter& p, const QPointF ¢er, double dotpercm=28.346457) const;
00071 static inline void paint(Type type, QPainter& p, QPointF center,
00072 double size, double halfSize);
00073
00074 static const Symbol null;
00075 protected:
00076 virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00077 virtual void xml_writeChildren(XML_WRITECHILDREN_ARGS) const;
00078 virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00079 virtual XMLMember xml_member(XML_MEMBER_ARGS);
00080 protected:
00081 Type _type;
00082
00083 double _size;
00084 Pen _pen;
00085 Brush _brush;
00086 };
00087
00088
00089
00090 inline void Symbol::paint(Type type, QPainter& p, QPointF center,
00091 double size, double halfSize)
00092 {
00093 TRACE;
00094 switch(type) {
00095 case Cross: {
00096 QPointF h1(halfSize, halfSize);
00097 QPointF h2(halfSize, -halfSize);
00098 p.drawLine(center-h1, center+h1);
00099 p.drawLine(center-h2, center+h2);
00100 }
00101 break;
00102 case Square: {
00103 p.drawRect(QRectF(center-QPointF(halfSize, halfSize),QSizeF(size,size)));
00104 }
00105 break;
00106 case Circle: {
00107 p.drawEllipse(center, halfSize, halfSize);
00108 }
00109 break;
00110 case TriangleUp: {
00111 QPolygonF points(4);
00112 double halfSize=0.5*0.866025403784439*size;
00113 center+=QPointF(-halfSize, 0.25*size);
00114 points[0]=center;
00115 points[1]=center+QPointF(0.866025403784439*size, 0);
00116 points[2]=center+QPointF(halfSize, -0.75*size);
00117 points[3]=points[0];
00118 p.drawPolygon(points);
00119 }
00120 break;
00121 case TriangleDown: {
00122 QPolygonF points(4);
00123 double halfSize=0.5*0.866025403784439*size;
00124 center+=QPointF(-halfSize, -0.25*size);
00125 points[0]=center;
00126 points[1]=center+QPointF(0.866025403784439*size, 0);
00127 points[2]=center+QPointF(halfSize, 0.75*size);
00128 points[3]=points[0];
00129 p.drawPolygon(points);
00130 }
00131 break;
00132 case Losange: {
00133 QPolygonF points(5);
00134 double quarterSize=size*0.25;
00135 points[0]=center-QPointF(0.0, halfSize);
00136 points[1]=center+QPointF(quarterSize, 0.0);
00137 points[2]=center+QPointF(0.0, halfSize);
00138 points[3]=center-QPointF(quarterSize, 0.0);
00139 points[4]=points[0];
00140 p.drawPolygon (points);
00141 }
00142 break;
00143 case Star: {
00144 QPointF h1(halfSize, halfSize);
00145 QPointF h2(halfSize, -halfSize);
00146 QPointF h3(halfSize, 0.0);
00147 QPointF h4(0.0, halfSize);
00148 p.drawLine(center-h1, center+h1);
00149 p.drawLine(center-h2, center+h2);
00150 p.drawLine(center-h3, center+h3);
00151 p.drawLine(center-h4, center+h4);
00152 }
00153 break;
00154 default:
00155 break;
00156 }
00157 }
00158
00159 }
00160
00161 #endif // SYMBOL_H