Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

style.h

Go to the documentation of this file.
00001 /*
00002  For general Scribus (>=1.3.2) copyright and licensing information please refer
00003  to the COPYING file provided with the program. Following this notice may exist
00004  a copyright and/or license notice that predates the release of Scribus 1.3.2
00005  for which a new license (GPL+exception) is in place.
00006  */
00007 /***************************************************************************
00008 *                                                                         *
00009 *   This program is free software; you can redistribute it and/or modify  *
00010 *   it under the terms of the GNU General Public License as published by  *
00011 *   the Free Software Foundation; either version 2 of the License, or     *
00012 *   (at your option) any later version.                                   *
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 //  static const short NOVALUE = -16000;
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     { //assert(typeinfo() == o.typeinfo()); 
00054         m_name = o.m_name; 
00055 //      m_context = o.m_context; 
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     // this is an abstract class, so:
00069     // static const Xml_string saxxDefaultElem; 
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     //virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
00075     //virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
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         //  else if ( inheritsAll() )
00086         //      return parent()->displayName();
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
Created with personalized Doxygen. This is documentation for GPL software Scribus - Open Source Desktop Publishing.