Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
5684 avox 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
 
6733 avox 20
#include <cassert>
10028 cbradney 21
#include <QString>
12314 pierre 22
#include <QMap>
6125 cbradney 23
#include "scfonts.h"
5693 jghali 24
#include "scribusapi.h"
7478 jghali 25
#include "sccolor.h"
8134 avox 26
#include "styles/stylecontext.h"
8193 avox 27
#include "desaxe/saxio.h"
5684 avox 28
 
29
/**
8134 avox 30
 *  This is the base class for all style-like objects: CharStyles,
31
 *  ParagraphStyles, LineStyles, FrameStyles, CellStyles,
6733 avox 32
 *  FlowStyles,...
8134 avox 33
 *  It provides a name and an inheritance mechanism which uses a Stylecontext.
6733 avox 34
 *  Before any attribute is queried, you have to call validate(), which checks
8134 avox 35
 *  the stored m_contextversion against the StyleContext's version and updates all
6733 avox 36
 *  attributes if they are different.
37
 */
8193 avox 38
class SCRIBUS_API Style : public SaxIO {
6733 avox 39
protected:
12283 cbradney 40
        bool m_isDefaultStyle;
12343 pierre 41
        const QString m_uuid;
12340 pierre 42
        QString m_name;
6733 avox 43
        QString m_parent;
6949 tsoots 44
        QString m_shortcut;
6733 avox 45
public:
46
//      static const short NOVALUE = -16000;
5684 avox 47
 
12314 pierre 48
        // default constructor
12340 pierre 49
        // create an UUID for itself and null UUID for its parent member
50
        // name the style the same as m_uuid so hasName() return false until a proper name has been set
12314 pierre 51
        Style();
5684 avox 52
 
12314 pierre 53
        // if lang is null, which likely will be the rule, we get it from gui language
12337 pierre 54
        Style( QString n, QString lang = QString() );
5684 avox 55
 
12343 pierre 56
//      Style& operator=(const Style& o);
5684 avox 57
 
12314 pierre 58
        Style(const Style& o);
5684 avox 59
 
12337 pierre 60
        virtual ~Style();
6733 avox 61
 
8337 avox 62
 
63
        // this is an abstract class, so:
64
        // static const Xml_string saxxDefaultElem; 
8382 avox 65
        template<class SUBSTYLE>
8834 cbradney 66
                static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag);
8337 avox 67
 
68
        void saxxAttributes(Xml_attr& attr) const;
8800 jghali 69
        //virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
8337 avox 70
        //virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
71
 
12283 cbradney 72
        void setDefaultStyle(bool ids)       { m_isDefaultStyle = ids; }
73
        bool isDefaultStyle() const      { return m_isDefaultStyle; }
8337 avox 74
 
12343 pierre 75
        const QString uuid() const ; // returns the UUID, at some point has to be changed into uuid() - cannot be reset
12340 pierre 76
 
12337 pierre 77
        QString name() const ; // returns the human-readable name
12314 pierre 78
        void setName(const QString& n = QString()/*, const QString& lang = QString()*/);
79
        bool hasName(/*const QString& lang = QString()*/) const ;
80
 
5684 avox 81
 
12314 pierre 82
        QString parent() const ;
83
        void setParent(const QString& p);
84
        bool hasParent() const ;
5684 avox 85
 
12337 pierre 86
 
9607 avox 87
        static const QString INHERIT_PARENT;
5684 avox 88
 
6949 tsoots 89
        QString shortcut() const { return m_shortcut; }
90
        void setShortcut(const QString &shortcut) { m_shortcut = shortcut; }
12340 pierre 91
 
92
        /// We keep it under the hood
93
        void validate() const;
6949 tsoots 94
 
6733 avox 95
        /**
96
                returns true if both Styles are of the same type, inherit the same attributes,
97
            have the same parent, and agree on all attributes which are not inherited.
8134 avox 98
            The StyleContext, the name and any inherited attrinutes may be different.
6733 avox 99
         */
12337 pierre 100
        virtual bool equiv(const QString& other) const = 0;
6733 avox 101
        /**
102
                returns true if both Styles are equivalent and have the same name.
8134 avox 103
            Since the context is not tested, this does *not* ensure they will return
6733 avox 104
            the same values for all attributes.
105
         */
12337 pierre 106
        virtual bool operator==(const Style& other) const { return uuid() == other.uuid() && equiv(other.uuid()); }
6733 avox 107
        virtual bool operator!=(const Style& other) const { return ! ( (*this) == other ); }
6091 tsoots 108
 
6733 avox 109
        /**
110
                resets all attributes to their defaults and makes them inherited.
111
            name and parent are not affected.
112
         */
113
        virtual void erase() = 0;
114
        /**
115
                if other has a parent, replace this parent with the other ones
116
         */
12337 pierre 117
        void applyStyle(const QString& other);
6733 avox 118
        /**
119
                if other has the same parent, remove this parent
120
         */
12337 pierre 121
        void eraseStyle(const QString& other) ;
12340 pierre 122
 
123
        const Style* parentStyle() const;
124
 
125
        // make us life easier 
12343 pierre 126
        operator const QString&() const{return m_uuid;}
5684 avox 127
};
128
 
129
 
12340 pierre 130
 
5695 avox 131
#endif