File indexing completed on 2024-03-24 16:03:39

0001 /********************************************************************************
0002  * Copyright (C) 2011-2015 by Stephen Allewell                                  *
0003  * steve.allewell@gmail.com                                                     *
0004  *                                                                              *
0005  * This program is free software; you can redistribute it and/or modify         *
0006  * it under the terms of the GNU General Public License as published by         *
0007  * the Free Software Foundation; either version 2 of the License, or            *
0008  * (at your option) any later version.                                          *
0009  ********************************************************************************/
0010 
0011 
0012 /**
0013  * @file
0014  * Header file for the Symbol class.
0015  */
0016 
0017 
0018 #ifndef Symbol_H
0019 #define Symbol_H
0020 
0021 #include <QBrush>
0022 #include <QPainterPath>
0023 #include <QPen>
0024 
0025 
0026 /**
0027  * @brief Defines the Symbol class encapsulating the QPainterPath with how it is drawn.
0028  *
0029  * The Symbol incorporates the QPainterPath object with additional information as to how
0030  * it should be drawn. Originally the path was drawn filled, the implementation of this
0031  * Symbol class allows a fill attribute and a pen width attribute for outline paths. In
0032  * addition the line end style and line join style can be changed.
0033  */
0034 class Symbol
0035 {
0036 public:
0037     Symbol();
0038     ~Symbol();
0039 
0040     QPainterPath path() const;
0041     bool filled() const;
0042     qreal lineWidth() const;
0043     Qt::PenCapStyle capStyle() const;
0044     Qt::PenJoinStyle joinStyle() const;
0045 
0046     void setPath(const QPainterPath &path);
0047     void setFilled(bool filled);
0048     void setLineWidth(qreal width);
0049     void setCapStyle(Qt::PenCapStyle penCapStyle);
0050     void setJoinStyle(Qt::PenJoinStyle penJoinStyle);
0051 
0052     QPen pen() const;
0053     QBrush brush() const;
0054 
0055     friend QDataStream &operator<<(QDataStream &stream, const Symbol &symbol);
0056     friend QDataStream &operator>>(QDataStream &stream, Symbol &symbol);
0057 
0058 private:
0059     static const qint32 version = 100;              /**< version of the stream object */
0060 
0061     QPainterPath        m_path;                     /**< the symbols path, incorporates fill method if m_filled is true */
0062     bool                m_filled;                   /**< true if the path is filled, false if an outline path */
0063     qreal               m_lineWidth;                /**< width of the pen, this is scaled with the painter */
0064     Qt::PenCapStyle     m_capStyle;                 /**< pen cap style, see the QPen documentation for details */
0065     Qt::PenJoinStyle    m_joinStyle;                /**< pen join style, see the QPen documentation for details */
0066 };
0067 
0068 
0069 QDataStream &operator<<(QDataStream &stream, const Symbol &symbol);
0070 QDataStream &operator>>(QDataStream &stream, Symbol &symbol);
0071 
0072 
0073 #endif
0074