File indexing completed on 2024-04-21 04:34:01

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 
0039     QPainterPath path() const;
0040     bool filled() const;
0041     qreal lineWidth() const;
0042     Qt::PenCapStyle capStyle() const;
0043     Qt::PenJoinStyle joinStyle() const;
0044 
0045     void setPath(const QPainterPath &path);
0046     void setFilled(bool filled);
0047     void setLineWidth(qreal width);
0048     void setCapStyle(Qt::PenCapStyle penCapStyle);
0049     void setJoinStyle(Qt::PenJoinStyle penJoinStyle);
0050 
0051     QPen pen() const;
0052     QBrush brush() const;
0053 
0054     friend QDataStream &operator<<(QDataStream &stream, const Symbol &symbol);
0055     friend QDataStream &operator>>(QDataStream &stream, Symbol &symbol);
0056 
0057 private:
0058     static const qint32 version = 100;              /**< version of the stream object */
0059 
0060     QPainterPath        m_path;                     /**< the symbols path, incorporates fill method if m_filled is true */
0061     bool                m_filled;                   /**< true if the path is filled, false if an outline path */
0062     qreal               m_lineWidth;                /**< width of the pen, this is scaled with the painter */
0063     Qt::PenCapStyle     m_capStyle;                 /**< pen cap style, see the QPen documentation for details */
0064     Qt::PenJoinStyle    m_joinStyle;                /**< pen join style, see the QPen documentation for details */
0065 };
0066 
0067 
0068 QDataStream &operator<<(QDataStream &stream, const Symbol &symbol);
0069 QDataStream &operator>>(QDataStream &stream, Symbol &symbol);
0070 
0071 
0072 #endif
0073