style.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef STYLE_H
00018 #define STYLE_H
00019
00020 #include <cassert>
00021 #include <QString>
00022 #include "scfonts.h"
00023 #include "scribusapi.h"
00024 #include "sccolor.h"
00025 #include "styles/stylecontext.h"
00026 #include "desaxe/saxio.h"
00027
00028
00038 class SCRIBUS_API Style : public SaxIO {
00039 protected:
00040 QString m_name;
00041 const StyleContext* m_context;
00042 int m_contextversion;
00043 QString m_parent;
00044 QString m_shortcut;
00045 public:
00046
00047
00048 Style(): m_name(""), m_context(NULL), m_contextversion(-1), m_parent(""), m_shortcut() {}
00049
00050 Style(StyleContext* b, QString n): m_name(n), m_context(b), m_contextversion(-1), m_parent(""), m_shortcut() {}
00051
00052 Style& operator=(const Style& o)
00053 {
00054 m_name = o.m_name;
00055
00056 m_contextversion = -1;
00057 m_parent = o.m_parent;
00058 m_shortcut = o.m_shortcut;
00059 return *this;
00060 }
00061
00062 Style(const Style& o) : SaxIO(), m_name(o.m_name),
00063 m_context(o.m_context), m_contextversion(o.m_contextversion), m_parent(o.m_parent), m_shortcut(o.m_shortcut) {}
00064
00065 virtual ~Style() {}
00066
00067
00068
00069
00070 template<class SUBSTYLE>
00071 static void desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag);
00072
00073 void saxxAttributes(Xml_attr& attr) const;
00074
00075
00076
00077
00078 QString name() const { return m_name; }
00079 void setName(const QString& n) { m_name = n.isEmpty() ? "" : n; }
00080 bool hasName() const { return ! m_name.isEmpty(); }
00081
00082 virtual QString displayName() const {
00083 if ( hasName() || !hasParent() || !m_context)
00084 return name();
00085
00086
00087 else
00088 return parentStyle()->displayName();
00089 }
00090
00091 QString parent() const { return m_parent; }
00092 void setParent(const QString& p) { if (m_parent != p) m_contextversion = -1; m_parent = p.isEmpty()? "" : p; }
00093 bool hasParent() const { return ! m_parent.isEmpty(); }
00094 const Style* parentStyle() const;
00095
00096 static const QString INHERIT_PARENT;
00097
00098 virtual void setContext(const StyleContext* context);
00099 const StyleContext* context() const { return m_context; }
00100
00105 virtual void update(const StyleContext* b = NULL);
00106
00110 void validate() const;
00111
00112 QString shortcut() const { return m_shortcut; }
00113 void setShortcut(const QString &shortcut) { m_shortcut = shortcut; }
00114
00120 virtual bool equiv(const Style& other) const = 0;
00126 virtual bool operator==(const Style& other) const { return name() == other.name() && equiv(other); }
00127 virtual bool operator!=(const Style& other) const { return ! ( (*this) == other ); }
00128
00133 virtual void erase() = 0;
00137 void applyStyle(const Style& other) {
00138 if (other.hasParent())
00139 setParent( other.parent() == INHERIT_PARENT? "" :other.parent());
00140 m_contextversion = -1;
00141 }
00145 void eraseStyle(const Style& other) {
00146 if (other.parent() == parent())
00147 setParent("");
00148 m_contextversion = -1;
00149 }
00150 };
00151
00152
00153 #endif