File indexing completed on 2024-05-05 12:57:33
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 * @file 0013 * Header file for the Symbol class. 0014 */ 0015 0016 #ifndef Symbol_H 0017 #define Symbol_H 0018 0019 #include <QMap> 0020 #include <QPainterPath> 0021 0022 #include "Stitch.h" 0023 0024 /** 0025 * @brief Defines the Symbol class encapsulating the QPainterPath with how it is drawn. 0026 * 0027 * The Symbol incorporates the QPainterPath object with additional information as to how 0028 * it should be drawn. Originally the path was drawn filled, the implementation of this 0029 * Symbol class allows a fill attribute and a pen width attribute for outline paths. In 0030 * addition the line end style and line join style can be changed. 0031 */ 0032 class Symbol 0033 { 0034 public: 0035 Symbol(); 0036 0037 QPainterPath path(Stitch::Type type); 0038 QPainterPath path() const; 0039 bool filled() const; 0040 qreal lineWidth() const; 0041 Qt::PenCapStyle capStyle() const; 0042 Qt::PenJoinStyle joinStyle() const; 0043 0044 void setPath(const QPainterPath &path); 0045 void setFilled(bool filled); 0046 void setLineWidth(qreal width); 0047 void setCapStyle(Qt::PenCapStyle penCapStyle); 0048 void setJoinStyle(Qt::PenJoinStyle penJoinStyle); 0049 0050 QPen pen() const; 0051 QBrush brush() const; 0052 0053 friend QDataStream &operator<<(QDataStream &stream, const Symbol &symbol); 0054 friend QDataStream &operator>>(QDataStream &stream, Symbol &symbol); 0055 0056 private: 0057 static const qint32 version = 100; /**< version of the stream object */ 0058 0059 QMap<Stitch::Type, QPainterPath> m_paths; /**< the symbols paths, cached by type, incorporates fill method if m_filled is true */ 0060 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 QDataStream &operator<<(QDataStream &stream, const Symbol &symbol); 0068 QDataStream &operator>>(QDataStream &stream, Symbol &symbol); 0069 0070 #endif