Subversion Repositories Scribus


Rev 12340 | Blame | Compare with Previous | Last modification | View Log | RSS feed

 For general Scribus (>=1.3.2) copyright and licensing information please refer
 to the COPYING file provided with the program. Following this notice may exist
 a copyright and/or license notice that predates the release of Scribus 1.3.2
 for which a new license (GPL+exception) is in place.

*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *

#ifndef STYLE_H
#define STYLE_H

#include <cassert>
#include <QString>
#include <QMap>
#include "scfonts.h"
#include "scribusapi.h"
#include "sccolor.h"
#include "styles/stylecontext.h"
#include "desaxe/saxio.h"

 *  This is the base class for all style-like objects: CharStyles,
 *  ParagraphStyles, LineStyles, FrameStyles, CellStyles,
 *  FlowStyles,...
 *  It provides a name and an inheritance mechanism which uses a Stylecontext.
 *  Before any attribute is queried, you have to call validate(), which checks
 *  the stored m_contextversion against the StyleContext's version and updates all
 *  attributes if they are different.

class SCRIBUS_API Style : public SaxIO {
        bool m_isDefaultStyle;
        const QString m_uuid;
        QString m_name;
        QString m_parent;
        QString m_shortcut;
//      static const short NOVALUE = -16000;

        // default constructor
        // create an UUID for itself and null UUID for its parent member
        // name the style the same as m_uuid so hasName() return false until a proper name has been set

        // if lang is null, which likely will be the rule, we get it from gui language
        Style( QString n, QString lang = QString() );
//      Style& operator=(const Style& o);
        Style(const Style& o);
        virtual ~Style();

        // this is an abstract class, so:
        // static const Xml_string saxxDefaultElem;
        template<class SUBSTYLE>
                static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag);
        void saxxAttributes(Xml_attr& attr) const;
        //virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
        //virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
        void setDefaultStyle(bool ids)       { m_isDefaultStyle = ids; }
        bool isDefaultStyle() const      { return m_isDefaultStyle; }
        const QString uuid() const ; // returns the UUID, at some point has to be changed into uuid() - cannot be reset
        QString name() const ; // returns the human-readable name
        void setName(const QString& n = QString()/*, const QString& lang = QString()*/);
        bool hasName(/*const QString& lang = QString()*/) const ;
        QString parent() const ;
        void setParent(const QString& p);
        bool hasParent() const ;
        static const QString INHERIT_PARENT;
        QString shortcut() const { return m_shortcut; }
        void setShortcut(const QString &shortcut) { m_shortcut = shortcut; }
        /// We keep it under the hood
        void validate() const;

                returns true if both Styles are of the same type, inherit the same attributes,
            have the same parent, and agree on all attributes which are not inherited.
            The StyleContext, the name and any inherited attrinutes may be different.

        virtual bool equiv(const QString& other) const = 0;
                returns true if both Styles are equivalent and have the same name.
            Since the context is not tested, this does *not* ensure they will return
            the same values for all attributes.

        virtual bool operator==(const Style& other) const { return uuid() == other.uuid() && equiv(other.uuid()); }
        virtual bool operator!=(const Style& other) const { return ! ( (*this) == other ); }

                resets all attributes to their defaults and makes them inherited.
            name and parent are not affected.

        virtual void erase() = 0;
                if other has a parent, replace this parent with the other ones

        void applyStyle(const QString& other);
                if other has the same parent, remove this parent

        void eraseStyle(const QString& other) ;
        const Style* parentStyle() const;
        // make us life easier
        operator const QString&() const{return m_uuid;}