File indexing completed on 2024-05-05 12:57:23
0001 /* 0002 * Copyright (C) 2010-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 #ifndef Element_H 0012 #define Element_H 0013 0014 #include <QMargins> 0015 #include <QRect> 0016 0017 #include "Renderer.h" 0018 #include "configuration.h" 0019 0020 class QPainter; 0021 0022 class Document; 0023 class Page; 0024 class Renderer; 0025 0026 class Element 0027 { 0028 public: 0029 enum Type { Text, Pattern, Plan, Key, Image }; 0030 0031 Element(Page *, const QRect &, Element::Type); 0032 Element(const Element &); 0033 virtual ~Element() = default; 0034 0035 virtual Element *clone() const = 0; 0036 virtual void render(Document *, QPainter *) const = 0; 0037 0038 Page *parent() const; 0039 Element::Type type() const; 0040 const QRect &rectangle() const; 0041 0042 void setParent(Page *); 0043 void setRectangle(const QRect &); 0044 void move(const QPoint &); 0045 0046 friend QDataStream &operator<<(QDataStream &, const Element &); 0047 friend QDataStream &operator>>(QDataStream &, Element &); 0048 0049 protected: 0050 virtual QDataStream &streamOut(QDataStream &) const = 0; 0051 virtual QDataStream &streamIn(QDataStream &) = 0; 0052 0053 static const int version = 101; // removed m_visible 0054 0055 Page *m_parent; 0056 QRect m_rectangle; // area to be used on the page, in mm, top, left, width, height 0057 Element::Type m_type; 0058 }; 0059 0060 class KeyElement : public Element 0061 { 0062 public: 0063 KeyElement(Page *, const QRect &, Element::Type type = Element::Key); 0064 KeyElement(const KeyElement &); 0065 virtual ~KeyElement() = default; 0066 0067 bool showBorder() const; 0068 QColor borderColor() const; 0069 int borderThickness() const; 0070 bool fillBackground() const; 0071 QColor backgroundColor() const; 0072 int backgroundTransparency() const; 0073 QMargins margins() const; 0074 QColor textColor() const; 0075 QFont textFont() const; 0076 int indexStart() const; 0077 int indexCount() const; 0078 bool symbolColumn() const; 0079 bool symbolColumnColor() const; 0080 bool flossNameColumn() const; 0081 bool strandsColumn() const; 0082 bool flossDescriptionColumn() const; 0083 bool stitchesColumn() const; 0084 bool lengthColumn() const; 0085 bool skeinsColumn() const; 0086 0087 void setShowBorder(bool); 0088 void setBorderColor(const QColor &); 0089 void setBorderThickness(int); 0090 void setFillBackground(bool); 0091 void setBackgroundColor(const QColor &); 0092 void setBackgroundTransparency(int); 0093 void setMargins(const QMargins &); 0094 void setTextColor(const QColor &); 0095 void setTextFont(const QFont &); 0096 void setIndexStart(int); 0097 void setIndexCount(int); 0098 void setSymbolColumn(bool); 0099 void setSymbolColumnColor(bool); 0100 void setFlossNameColumn(bool); 0101 void setStrandsColumn(bool); 0102 void setFlossDescriptionColumn(bool); 0103 void setStitchesColumn(bool); 0104 void setLengthColumn(bool); 0105 void setSkeinsColumn(bool); 0106 0107 virtual KeyElement *clone() const Q_DECL_OVERRIDE; 0108 virtual void render(Document *, QPainter *painter) const Q_DECL_OVERRIDE; 0109 0110 friend class KeyElementDlg; 0111 0112 protected: 0113 virtual QDataStream &streamOut(QDataStream &) const Q_DECL_OVERRIDE; 0114 virtual QDataStream &streamIn(QDataStream &) Q_DECL_OVERRIDE; 0115 0116 private: 0117 static const int version = 103; // added m_symbolColumnColor 0118 0119 bool m_showBorder; 0120 QColor m_borderColor; 0121 int m_borderThickness; 0122 bool m_fillBackground; 0123 QColor m_backgroundColor; 0124 int m_backgroundTransparency; 0125 QMargins m_margins; 0126 QColor m_textColor; 0127 QFont m_textFont; 0128 int m_indexStart; 0129 int m_indexCount; 0130 bool m_symbolColumn; 0131 bool m_symbolColumnColor; 0132 bool m_flossNameColumn; 0133 bool m_strandsColumn; 0134 bool m_flossDescriptionColumn; 0135 bool m_stitchesColumn; 0136 bool m_lengthColumn; 0137 bool m_skeinsColumn; 0138 }; 0139 0140 class PlanElement : public Element 0141 { 0142 public: 0143 PlanElement(Page *, const QRect &, Element::Type type = Element::Plan); 0144 PlanElement(const PlanElement &); 0145 virtual ~PlanElement() = default; 0146 0147 QRect patternRect() const; 0148 void setPatternRect(const QRect &); 0149 0150 virtual PlanElement *clone() const Q_DECL_OVERRIDE; 0151 virtual void render(Document *, QPainter *painter) const Q_DECL_OVERRIDE; 0152 0153 protected: 0154 virtual QDataStream &streamOut(QDataStream &) const Q_DECL_OVERRIDE; 0155 virtual QDataStream &streamIn(QDataStream &) Q_DECL_OVERRIDE; 0156 0157 private: 0158 static const int version = 100; 0159 0160 QRect m_patternRect; 0161 }; 0162 0163 class PatternElement : public Element 0164 { 0165 public: 0166 PatternElement(Page *, const QRect &, Element::Type type = Element::Pattern); 0167 PatternElement(const PatternElement &); 0168 virtual ~PatternElement() = default; 0169 0170 virtual PatternElement *clone() const Q_DECL_OVERRIDE; 0171 virtual void render(Document *, QPainter *painter) const Q_DECL_OVERRIDE; 0172 0173 bool showBorder() const; 0174 QColor borderColor() const; 0175 int borderThickness() const; 0176 QRect patternRect() const; 0177 bool showScales() const; 0178 bool showPlan() const; 0179 Element *planElement() const; 0180 Configuration::EnumEditor_FormatScalesAs::type formatScalesAs() const; 0181 Configuration::EnumRenderer_RenderStitchesAs::type renderStitchesAs() const; 0182 Configuration::EnumRenderer_RenderBackstitchesAs::type renderBackstitchesAs() const; 0183 Configuration::EnumRenderer_RenderKnotsAs::type renderKnotsAs() const; 0184 bool showGrid() const; 0185 bool showStitches() const; 0186 bool showBackstitches() const; 0187 bool showKnots() const; 0188 0189 void setShowBorder(bool); 0190 void setBorderColor(const QColor &); 0191 void setBorderThickness(int); 0192 void setPatternRect(const QRect &); 0193 void setShowScales(bool); 0194 void setShowPlan(bool); 0195 void setFormatScalesAs(Configuration::EnumEditor_FormatScalesAs::type); 0196 void setRenderStitchesAs(Configuration::EnumRenderer_RenderStitchesAs::type); 0197 void setRenderBackstitchesAs(Configuration::EnumRenderer_RenderBackstitchesAs::type); 0198 void setRenderKnotsAs(Configuration::EnumRenderer_RenderKnotsAs::type); 0199 void setShowGrid(bool); 0200 void setShowStitches(bool); 0201 void setShowBackstitches(bool); 0202 void setShowKnots(bool); 0203 0204 friend class PatternElementDlg; 0205 0206 protected: 0207 virtual QDataStream &streamOut(QDataStream &) const Q_DECL_OVERRIDE; 0208 virtual QDataStream &streamIn(QDataStream &) Q_DECL_OVERRIDE; 0209 0210 private: 0211 static const int version = 102; // added m_showBorder, m_borderColor, m_borderThickness 0212 0213 bool m_showBorder; 0214 QColor m_borderColor; 0215 int m_borderThickness; 0216 0217 QRect m_patternRect; 0218 bool m_showScales; 0219 bool m_showPlan; 0220 0221 Configuration::EnumEditor_FormatScalesAs::type m_formatScalesAs; 0222 0223 Configuration::EnumRenderer_RenderStitchesAs::type m_renderStitchesAs; 0224 Configuration::EnumRenderer_RenderBackstitchesAs::type m_renderBackstitchesAs; 0225 Configuration::EnumRenderer_RenderKnotsAs::type m_renderKnotsAs; 0226 0227 bool m_showGrid; 0228 bool m_showStitches; 0229 bool m_showBackstitches; 0230 bool m_showKnots; 0231 0232 // Renderer m_renderer; 0233 PlanElement *m_planElement; 0234 }; 0235 0236 class ImageElement : public PatternElement 0237 { 0238 public: 0239 ImageElement(Page *, const QRect &, Element::Type type = Element::Image); 0240 ImageElement(const ImageElement &); 0241 virtual ~ImageElement() = default; 0242 0243 virtual ImageElement *clone() const Q_DECL_OVERRIDE; 0244 virtual void render(Document *, QPainter *painter) const Q_DECL_OVERRIDE; 0245 0246 friend class ImageElementDlg; 0247 0248 protected: 0249 virtual QDataStream &streamOut(QDataStream &) const Q_DECL_OVERRIDE; 0250 virtual QDataStream &streamIn(QDataStream &) Q_DECL_OVERRIDE; 0251 0252 private: 0253 static const int version = 100; 0254 }; 0255 0256 class TextElement : public Element 0257 { 0258 public: 0259 TextElement(Page *, const QRect &, Element::Type type = Element::Text); 0260 TextElement(const TextElement &); 0261 virtual ~TextElement() = default; 0262 0263 bool showBorder() const; 0264 QColor borderColor() const; 0265 int borderThickness() const; 0266 bool fillBackground() const; 0267 QColor backgroundColor() const; 0268 int backgroundTransparency() const; 0269 QMargins margins() const; 0270 QFont textFont() const; 0271 QColor textColor() const; 0272 Qt::Alignment alignment() const; 0273 QString text() const; 0274 0275 void setShowBorder(bool); 0276 void setBorderColor(const QColor &); 0277 void setBorderThickness(int); 0278 void setFillBackground(bool); 0279 void setBackgroundColor(const QColor &); 0280 void setBackgroundTransparency(int); 0281 void setMargins(const QMargins &); 0282 void setTextFont(const QFont &); 0283 void setTextColor(const QColor &); 0284 void setAlignment(Qt::Alignment); 0285 void setText(const QString &); 0286 0287 virtual TextElement *clone() const Q_DECL_OVERRIDE; 0288 virtual void render(Document *, QPainter *painter) const Q_DECL_OVERRIDE; 0289 0290 friend class TextElementDlg; 0291 0292 protected: 0293 virtual QDataStream &streamOut(QDataStream &) const Q_DECL_OVERRIDE; 0294 virtual QDataStream &streamIn(QDataStream &) Q_DECL_OVERRIDE; 0295 0296 private: 0297 QString convertedText(Document *) const; 0298 QString encodeToHtml(const QString &) const; 0299 0300 static const int version = 100; 0301 0302 bool m_showBorder; 0303 QColor m_borderColor; 0304 int m_borderThickness; 0305 bool m_fillBackground; 0306 QColor m_backgroundColor; 0307 int m_backgroundTransparency; 0308 QMargins m_margins; 0309 QFont m_textFont; 0310 QColor m_textColor; 0311 Qt::Alignment m_alignment; 0312 QString m_text; 0313 }; 0314 0315 #endif // Element_H