Back to index

scribus-ng  1.3.4.dfsg+svn20071115
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 <qsignal.h>
00022 #include <qstring.h>
00023 #include <qvaluelist.h>
00024 #include "scfonts.h"
00025 #include "scribusapi.h"
00026 #include "sccolor.h"
00027 #include "styles/stylecontext.h"
00028 #include "desaxe/saxio.h"
00029 
00030 
00040 class SCRIBUS_API Style : public SaxIO {
00041 protected:
00042        QString m_name;
00043        const StyleContext* m_context;
00044        int m_contextversion;
00045        QString m_parent;
00046        QString m_shortcut;
00047 public:
00048 //     static const short NOVALUE = -16000;
00049 
00050        Style(): m_name(""), m_context(NULL), m_contextversion(-1), m_parent(""), m_shortcut() {}
00051 
00052     Style(StyleContext* b, QString n): m_name(n), m_context(b), m_contextversion(-1), m_parent(""), m_shortcut() {}
00053        
00054        Style& operator=(const Style& o) 
00055        { //assert(typeinfo() == o.typeinfo()); 
00056               m_name = o.m_name; 
00057 //            m_context = o.m_context; 
00058               m_contextversion = -1; 
00059               m_parent = o.m_parent;
00060               m_shortcut = o.m_shortcut;
00061               return *this;
00062        }
00063        
00064        Style(const Style& o) : SaxIO(), m_name(o.m_name), 
00065               m_context(o.m_context), m_contextversion(o.m_contextversion), m_parent(o.m_parent), m_shortcut(o.m_shortcut) {} 
00066        
00067        virtual ~Style()                 {}
00068 
00069        
00070        // this is an abstract class, so:
00071        // static const Xml_string saxxDefaultElem; 
00072        template<class SUBSTYLE>
00073               static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag);
00074        
00075        void saxxAttributes(Xml_attr& attr) const;
00076        //virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
00077        //virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
00078        
00079        
00080        QString name() const             { return m_name; }
00081        void setName(const QString& n)   { m_name = n.isEmpty() ? "" : n; }
00082        bool hasName() const             { return ! m_name.isEmpty(); }
00083 
00084        virtual QString displayName() const {     
00085               if ( hasName() || !hasParent() || !m_context)
00086                      return name();
00087               //     else if ( inheritsAll() )
00088               //            return parent()->displayName();
00089               else 
00090                      return parentStyle()->displayName();
00091        }
00092        
00093        QString parent() const           { return m_parent; }
00094        void setParent(const QString& p) { if (m_parent != p) m_contextversion = -1; m_parent = p.isEmpty()? "" : p; }
00095        bool hasParent() const           { return ! m_parent.isEmpty(); }
00096        const Style* parentStyle() const;
00097        
00098        static const QString INHERIT_PARENT;
00099        
00100        virtual void setContext(const StyleContext* context);
00101        const StyleContext* context() const        { return m_context; }
00102        
00107        virtual void update(const StyleContext* b = NULL);
00108        
00112        void validate() const;
00113 
00114        QString shortcut() const { return m_shortcut; }
00115        void setShortcut(const QString &shortcut) { m_shortcut = shortcut; }
00116 
00122        virtual bool equiv(const Style& other) const = 0;
00128        virtual bool operator==(const Style& other) const { return name() == other.name() && equiv(other); }
00129        virtual bool operator!=(const Style& other) const { return ! ( (*this) == other ); }
00130 
00135        virtual void erase() = 0;
00139        void applyStyle(const Style& other) { 
00140               if (other.hasParent())
00141                      setParent( other.parent() == INHERIT_PARENT? "" :other.parent());
00142               m_contextversion = -1;
00143        }
00147        void eraseStyle(const Style& other) {
00148               if (other.parent() == parent())
00149                      setParent("");
00150               m_contextversion = -1;
00151        }
00152 };
00153 
00154 
00155 #endif