SciFigs/Pen.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 : 2004-12-01
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef PEN_H
00030 #define PEN_H
00031 
00032 #include <QtGui>
00033 #include <QGpCoreTools.h>
00034 #include "SciFigsDLLExport.h"
00035 
00036 namespace SciFigs {
00037 
00038 class SCIFIGS_EXPORT Pen : public XMLClass
00039 {
00040 public:
00041   inline Pen();
00042   inline Pen(Qt::PenStyle style);
00043   inline Pen(const QColor& col, double width=0, Qt::PenStyle style=Qt::SolidLine);
00044   inline Pen(const QColor& col, double width, Qt::PenStyle s, Qt::PenCapStyle c,
00045                  Qt::PenJoinStyle j);
00046   inline Pen(const Pen& o);
00047   virtual ~Pen() {}
00048 
00049   virtual const QString& xml_tagName() const {return xmlPenTag;}
00050   static const QString xmlPenTag;
00051 
00052   inline QPen qpen(double dotpercm) const;
00053   inline Pen& operator=(const Pen& o);
00054   inline bool operator==(const Pen& o) const;
00055 
00056   Qt::PenStyle style() const {return _style;}
00057   void setStyle(Qt::PenStyle s) {_style=s;}
00058   double width() const {return _width;}
00059   int screenWidth(double dotpercm) const
00060   {
00061     return (int) floor(0.1 * _width * dotpercm + 0.5);
00062   }
00063   void setWidth (double w) {_width=w;}
00064   const QColor& color() const {return _color;}
00065   void setColor(const QColor & c) {_color=c;}
00066   Qt::PenCapStyle capStyle() const {return _capStyle;}
00067   void setCapStyle(Qt::PenCapStyle c) {_capStyle=c;}
00068   Qt::PenJoinStyle joinStyle() const {return _joinStyle;}
00069   void setJoinStyle(Qt::PenJoinStyle j) {_joinStyle=j;}
00070 
00071   static Qt::PenStyle styleValue(QString s);
00072   static QString styleName(Qt::PenStyle s);
00073   static Qt::PenCapStyle capStyleValue(QString s);
00074   static QString capStyleName(Qt::PenCapStyle s);
00075   static Qt::PenJoinStyle joinStyleValue(QString s);
00076   static QString joinStyleName(Qt::PenJoinStyle s);
00077   static const Pen null;
00078 protected:
00079   virtual void xml_writeProperties(XML_WRITEPROPERTIES_ARGS) const;
00080   virtual bool xml_setProperty(XML_SETPROPERTY_ARGS);
00081   virtual XMLMember xml_member(XML_MEMBER_ARGS);
00082 private:
00083   QColor _color;
00084   Qt::PenStyle _style;
00085   Qt::PenCapStyle _capStyle;
00086   Qt::PenJoinStyle _joinStyle;
00087   // in mm
00088   double _width;
00089 };
00090 
00091 // SCIFIGS_EXPORT QTextStream& operator>>(QTextStream& s,Pen& p);
00092 
00093 inline Pen::Pen()
00094 {
00095   _color=Qt::black;
00096   _style=Qt::SolidLine;
00097   _capStyle=Qt::FlatCap;
00098   _joinStyle=Qt::MiterJoin;
00099   _width=0.3;
00100 }
00101 
00102 inline Pen::Pen(Qt::PenStyle style)
00103 {
00104   _color=Qt::black;
00105   _style=style;
00106   _capStyle=Qt::FlatCap;
00107   _joinStyle=Qt::MiterJoin;
00108   _width=0.3;
00109 }
00110 
00111 inline Pen::Pen(const QColor& col, double width, Qt::PenStyle style)
00112 {
00113   _color=col;
00114   _style=style;
00115   _capStyle=Qt::FlatCap;
00116   _joinStyle=Qt::MiterJoin;
00117   _width=width;
00118 }
00119 
00120 inline Pen::Pen(const QColor& col, double width, Qt::PenStyle s, Qt::PenCapStyle c,
00121                 Qt::PenJoinStyle j)
00122 {
00123   _color=col;
00124   _style=s;
00125   _capStyle=c;
00126   _joinStyle=j;
00127   _width=width;
00128 }
00129 
00130 inline Pen::Pen(const Pen& o) : XMLClass()
00131 
00132 {
00133   _color=o._color;
00134   _style=o._style;
00135   _capStyle=o._capStyle;
00136   _joinStyle=o._joinStyle;
00137   _width=o._width;
00138 }
00139 
00140 inline Pen& Pen::operator=(const Pen& o)
00141 {
00142   _color=o._color;
00143   _style=o._style;
00144   _capStyle=o._capStyle;
00145   _joinStyle=o._joinStyle;
00146   _width=o._width;
00147   return *this;
00148 }
00149 
00150 inline bool Pen::operator==(const Pen& o) const
00151 {
00152   TRACE;
00153   return _color==o._color
00154       && _style==o._style
00155       && _capStyle==o._capStyle
00156       && _joinStyle==o._joinStyle
00157       && _width==o._width;
00158 }
00159 
00160 inline QPen Pen::qpen(double dotpercm) const
00161 {
00162   TRACE;
00163   return QPen(QBrush( _color), round(0.1 * _width * dotpercm), _style, _capStyle,
00164                _joinStyle);
00165 }
00166 
00167 } // namespace SciFigs
00168 
00169 #endif // PEN_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines