Scribus
Open source desktop publishing at your fingertips
style.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 STYLE_H
18 #define STYLE_H
19 
20 #include <cassert>
21 #include <QString>
22 #include "scfonts.h"
23 #include "scribusapi.h"
24 #include "styles/stylecontext.h"
25 #include "desaxe/saxio.h"
26 
27 
37 class SCRIBUS_API Style : public SaxIO {
38 protected:
39  bool m_isDefaultStyle;
40  QString m_name;
41  const StyleContext* m_context;
42  int m_contextversion;
43  QString m_parent;
44  QString m_shortcut;
45 public:
46 // static const short NOVALUE = -16000;
47 
48  Style(): m_isDefaultStyle(false), m_name(""), m_context(NULL), m_contextversion(-1), m_parent(""), m_shortcut() {}
49 
50  Style(StyleContext* b, QString n): m_isDefaultStyle(false), m_name(n), m_context(b), m_contextversion(-1), m_parent(""), m_shortcut() {}
51 
52  Style& operator=(const Style& o)
53  { //assert(typeinfo() == o.typeinfo());
54  m_isDefaultStyle = o.m_isDefaultStyle;
55  m_name = o.m_name;
56 // m_context = o.m_context;
57  m_contextversion = -1;
58  m_parent = o.m_parent;
59  m_shortcut = o.m_shortcut;
60  return *this;
61  }
62 
63  Style(const Style& o) : SaxIO(), m_isDefaultStyle(o.m_isDefaultStyle),m_name(o.m_name),
64  m_context(o.m_context), m_contextversion(o.m_contextversion), m_parent(o.m_parent), m_shortcut(o.m_shortcut) {}
65 
66  virtual ~Style() {}
67 
68 
69  // this is an abstract class, so:
70  // static const Xml_string saxxDefaultElem;
71  template<class SUBSTYLE>
72  static void desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag);
73 
74  void saxxAttributes(Xml_attr& attr) const;
75  //virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
76  //virtual void saxx(SaxHandler& handler) const { saxx(handler, saxxDefaultElem); }
77 
78  void setDefaultStyle(bool ids);
79  bool isDefaultStyle() const { return m_isDefaultStyle; }
80 
81  QString name() const { return m_name; }
82  void setName(const QString& n) { m_name = n.isEmpty() ? "" : n; }
83  bool hasName() const { return ! m_name.isEmpty(); }
84 
85  virtual QString displayName() const = 0;/*{
86  if ( hasName() || !hasParent() || !m_context)
87  return name();
88  // else if ( inheritsAll() )
89  // return parent()->displayName();
90  else
91  return parentStyle()->displayName();
92  }*/
93 
94  QString parent() const { return m_parent; }
95  void setParent(const QString& p);
96  bool hasParent() const { return ! m_parent.isEmpty(); }
97  const Style* parentStyle() const;
98 
99  static const QString INHERIT_PARENT;
100 
101  virtual void setContext(const StyleContext* context);
102  const StyleContext* context() const { return m_context; }
103 
108  virtual void update(const StyleContext* b = NULL);
109 
113  inline void validate() const {
114  if (m_context && m_contextversion != m_context->version()) {
115  const_cast<Style*>(this)->update(m_context);
116  assert( m_context->checkConsistency() );
117  }
118  }
119 
120  QString shortcut() const { return m_shortcut; }
121  void setShortcut(const QString &shortcut) { m_shortcut = shortcut; }
122 
128  virtual bool equiv(const Style& other) const = 0;
134  virtual bool operator==(const Style& other) const { return name() == other.name() && equiv(other); }
135  virtual bool operator!=(const Style& other) const { return ! ( (*this) == other ); }
136 
141  virtual void erase() = 0;
145  void applyStyle(const Style& other) {
146  if (other.hasParent())
147  setParent( other.parent() == INHERIT_PARENT? "" :other.parent());
148  m_contextversion = -1;
149  }
153  void eraseStyle(const Style& other) {
154  if (other.parent() == parent())
155  setParent("");
156  m_contextversion = -1;
157  }
158 };
159 
160 #endif
Definition: stylecontext.h:35
void applyStyle(const Style &other)
Definition: style.h:145
Definition: style.h:37
void eraseStyle(const Style &other)
Definition: style.h:153
virtual bool operator==(const Style &other) const
Definition: style.h:134
Definition: saxio.h:26
static void desaxeRules(const Xml_string &, desaxe::Digester &, const Xml_string=saxxDefaultElem)
Definition: saxio.h:49
Definition: digester.h:100
void validate() const
Definition: style.h:113