Scribus
Open source desktop publishing at your fingertips
linestyle.h
1 /*
2  For general Scribus (>=1.3.2) copyright and licensing information please refer
3  to the COPYING file provided with the program. Following this notice may exist
4  a copyright and/or license notice that predates the release of Scribus 1.3.2
5  for which a new license (GPL+exception) is in place.
6  */
7 /***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15 
16 
17 #ifndef LINESTYLE_H
18 #define LINESTYLE_H
19 
20 #include <QString>
21 #include "style.h"
22 #include "styles/stylecontextproxy.h"
23 
24 class SCRIBUS_API LineStyle : public Style {
25 public:
26 
27 
28  LineStyle() : Style(), lineStyleProxy(this) {
29 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
30  m_##attr_NAME = attr_DEFAULT; \
31  inh_##attr_NAME = true;
32 #include "linestyle.attrdefs.cxx"
33 #undef ATTRDEF
34  };
35 
36  LineStyle(qreal width, const QString& color, qreal shade=100) : Style(), lineStyleProxy(this) {
37 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
38  m_##attr_NAME = attr_DEFAULT; \
39  inh_##attr_NAME = true;
40 #include "linestyle.attrdefs.cxx"
41 #undef ATTRDEF
42  setWidth(width);
43  setColor(color);
44  setShade(shade);
45  };
46 
47  LineStyle(const LineStyle & other);
48 
49  LineStyle & operator=(const LineStyle & other);
50 
51  static const Xml_string saxxDefaultElem;
52  static void desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag = saxxDefaultElem);
53 
54  virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
55  virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
56 
57  void getNamedResources(ResourceCollection& lists) const;
58  void replaceNamedResources(ResourceCollection& newNames);
59 
60  QString displayName() const;
61 
62  void update(const StyleContext * b);
63 
64  bool equiv(const Style& other) const;
65 
66  void applyLineStyle(const LineStyle & other);
67  void eraseLineStyle(const LineStyle & other);
68  void setStyle(const LineStyle & other);
69  void erase() { eraseLineStyle(*this); }
70 
71  QString asString() const;
72 
75 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
76  const attr_TYPE &attr_GETTER() const { validate(); return m_##attr_NAME; }
77 #include "linestyle.attrdefs.cxx"
78 #undef ATTRDEF
79 
82 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
83  void set##attr_NAME(attr_TYPE v) { m_##attr_NAME = v; inh_##attr_NAME = false; }
84 #include "linestyle.attrdefs.cxx"
85 #undef ATTRDEF
86  void appendSubline(const LineStyle& subline) { validate(); m_Sublines.append(subline); inh_Sublines = false; }
87 
90 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
91  void reset##attr_NAME() { m_##attr_NAME = attr_DEFAULT; inh_##attr_NAME = true; }
92 #include "linestyle.attrdefs.cxx"
93 #undef ATTRDEF
94 
96 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
97  bool isInh##attr_NAME() const { return inh_##attr_NAME; }
98 #include "linestyle.attrdefs.cxx"
99 #undef ATTRDEF
100 
101 
103 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
104  bool isDef##attr_NAME() const { \
105  if ( !inh_##attr_NAME ) return true; \
106  const LineStyle * par = dynamic_cast<const LineStyle*>(parentStyle()); \
107  return par && par->isDef##attr_NAME(); \
108  }
109 #include "linestyle.attrdefs.cxx"
110 #undef ATTRDEF
111 
112 
113 private:
114 
115  StyleContextProxy lineStyleProxy;
116  // FIXME: see pstyle how this works for nested styles
117 
118 
119  // member declarations:
120 
121 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
122  attr_TYPE m_##attr_NAME; \
123  bool inh_##attr_NAME;
124 #include "linestyle.attrdefs.cxx"
125 #undef ATTRDEF
126 };
127 
128 
129 inline LineStyle & LineStyle::operator=(const LineStyle & other)
130 {
131  static_cast<Style&>(*this) = static_cast<const Style&>(other);
132 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
133  m_##attr_NAME = other.m_##attr_NAME; \
134  inh_##attr_NAME = other.inh_##attr_NAME;
135 #include "linestyle.attrdefs.cxx"
136 #undef ATTRDEF
137  m_contextversion = -1;
138  return *this;
139 }
140 
141 inline LineStyle::LineStyle(const LineStyle & other) : Style(other), lineStyleProxy(this)
142 {
143 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
144  m_##attr_NAME = other.m_##attr_NAME; \
145  inh_##attr_NAME = other.inh_##attr_NAME;
146 #include "linestyle.attrdefs.cxx"
147 #undef ATTRDEF
148  m_contextversion = -1;
149 }
150 
151 #endif
void erase()
Definition: linestyle.h:69
virtual bool equiv(const Style &other) const =0
Definition: stylecontext.h:35
Definition: saxhandler.h:21
Definition: stylecontextproxy.h:33
Definition: linestyle.h:24
virtual void update(const StyleContext *b=NULL)
Definition: style.cpp:54
Definition: style.h:37
static const Xml_string saxxDefaultElem
Definition: saxio.h:40
virtual void saxx(SaxHandler &handler) const
Definition: linestyle.h:55
Definition: digester.h:100
virtual void saxx(SaxHandler &, const Xml_string &) const =0
void validate() const
Definition: style.h:113
Definition: resourcecollection.h:41