Subversion Repositories Scribus

Rev

Rev 7942 | Rev 8058 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6733 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
***************************************************************************/
6443 avox 15
 
16
 
6733 avox 17
 
18
 
19
#include "style.h"
20
 
7942 avox 21
ParagraphStyle::ParagraphStyle() : Style(), cstyleBase(NULL), cstyle()
6443 avox 22
{
7059 avox 23
        setBase(NULL);
7006 avox 24
        cstyle.setBase(NULL);
6805 avox 25
        setParent("");
6765 avox 26
        cstyleBase.setDefaultStyle( &cstyle );
6740 avox 27
//      qDebug(QString("ParagraphStyle() %1 pbase %2 cbase %3").arg(reinterpret_cast<uint>(this)).arg(reinterpret_cast<uint>(base())).arg(reinterpret_cast<uint>(defaultStyle()->base())));
6443 avox 28
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
29
        m_##attr_NAME = attr_DEFAULT; \
30
        inh_##attr_NAME = true;
31
#include "paragraphstyle.attrdefs.cxx"
32
#undef ATTRDEF
33
}
34
 
35
 
7942 avox 36
ParagraphStyle::ParagraphStyle(const ParagraphStyle& other) : Style(other), cstyleBase(NULL), cstyle(other.charStyle())
6443 avox 37
{
7059 avox 38
        setBase(NULL);
39
        cstyle.setBase(NULL);
6765 avox 40
        cstyleBase.setDefaultStyle( &cstyle );
6735 avox 41
//      qDebug(QString("ParagraphStyle(%2) %1").arg(reinterpret_cast<uint>(&other)).arg(reinterpret_cast<uint>(this)));
7003 avox 42
        other.validate();
6733 avox 43
 
6443 avox 44
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
45
        m_##attr_NAME = other.m_##attr_NAME; \
46
        inh_##attr_NAME = other.inh_##attr_NAME;
47
#include "paragraphstyle.attrdefs.cxx"
48
#undef ATTRDEF
49
}
50
 
6765 avox 51
ParagraphStyle::~ParagraphStyle()
52
{
53
//      qDebug(QString("~ParagraphStyle %1").arg(reinterpret_cast<uint>(this)));
54
}
55
 
6443 avox 56
QString ParagraphStyle::displayName() const
57
{
58
        if ( hasName() || !hasParent() || !m_base)
59
                return name();
60
        //      else if ( inheritsAll() )
61
        //              return parent()->displayName();
62
        else
63
                return (parentStyle())->displayName() + "+";
64
}
65
 
66
 
67
bool ParagraphStyle::equiv(const Style& other) const
68
{
6805 avox 69
        other.validate();
6443 avox 70
        const ParagraphStyle* oth = dynamic_cast<const ParagraphStyle*> ( & other );
71
        return  oth &&
6733 avox 72
                parent() == oth->parent()
6443 avox 73
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 74
                && (inh_##attr_NAME == oth->inh_##attr_NAME) \
75
                && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
6443 avox 76
#include "paragraphstyle.attrdefs.cxx"
77
#undef ATTRDEF
78
                ;
79
}      
80
 
81
 
82
 
83
ParagraphStyle& ParagraphStyle::operator=(const ParagraphStyle& other)
84
{
6805 avox 85
        other.validate();
6765 avox 86
        static_cast<Style&>(*this) = static_cast<const Style&>(other);
7059 avox 87
 
6443 avox 88
        cstyle = other.charStyle();
6765 avox 89
        cstyleBase = other.cstyleBase;
7059 avox 90
 
91
        setBase(NULL);
6765 avox 92
        // we dont want cstyleBase to point to other's charstyle...
7059 avox 93
        cstyle.setBase(NULL);
6765 avox 94
        cstyleBase.setDefaultStyle( &cstyle );
95
        cstyleBase.invalidate();
7059 avox 96
 
6443 avox 97
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6733 avox 98
        m_##attr_NAME = other.m_##attr_NAME; \
99
        inh_##attr_NAME = other.inh_##attr_NAME;
6443 avox 100
#include "paragraphstyle.attrdefs.cxx"
101
#undef ATTRDEF
102
        return *this;
103
}
104
 
105
 
106
 
6805 avox 107
void ParagraphStyle::update(const StyleBase* base)
6443 avox 108
{
109
        Style::update(base);
7001 avox 110
        assert ( &cstyleBase != cstyle.base());
6443 avox 111
        const ParagraphStyle * oth = dynamic_cast<const ParagraphStyle*> ( parentStyle() );
6805 avox 112
//      qDebug(QString("ParagraphStyle::update(%1) parent=%2").arg((unsigned long int)base).arg((unsigned long int)oth));
6443 avox 113
        if (oth) {
7001 avox 114
                cstyle.setBase(oth->charStyleBase());
115
                assert ( &cstyleBase != cstyle.base());
116
                cstyle.validate();
6443 avox 117
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
118
                if (inh_##attr_NAME) \
6733 avox 119
                        m_##attr_NAME = oth->attr_GETTER();
6443 avox 120
#include "paragraphstyle.attrdefs.cxx"
121
#undef ATTRDEF
122
        }
7001 avox 123
        cstyleBase.invalidate();
6443 avox 124
}
125
 
126
 
127
 
128
void ParagraphStyle::applyStyle(const ParagraphStyle& other)
129
{
130
        Style::applyStyle(other);
131
        cstyle.applyCharStyle(other.charStyle());
6805 avox 132
        cstyleBase.invalidate();
6443 avox 133
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
134
        if (! other.inh_##attr_NAME) \
135
                set##attr_NAME(other.m_##attr_NAME);
136
#include "paragraphstyle.attrdefs.cxx"
137
#undef ATTRDEF
138
}
139
 
140
 
141
void ParagraphStyle::eraseStyle(const ParagraphStyle& other)
142
{
6805 avox 143
        other.validate();
6443 avox 144
        Style::eraseStyle(other);
145
        cstyle.eraseCharStyle(other.charStyle());
6805 avox 146
        cstyleBase.invalidate();
6443 avox 147
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
6936 avox 148
        if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
6443 avox 149
                reset##attr_NAME();
150
#include "paragraphstyle.attrdefs.cxx"
151
#undef ATTRDEF
152
}
153
 
7242 avox 154
void ParagraphStyle::setStyle(const ParagraphStyle & other)
155
{
156
        other.validate();
7993 avox 157
        setParent(other.parent());
7242 avox 158
        cstyle.setStyle(other.charStyle());
159
        cstyleBase.invalidate();
160
#define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
7993 avox 161
        inh_##attr_NAME = other.inh_##attr_NAME; \
7242 avox 162
        m_##attr_NAME = other.m_##attr_NAME;
163
#include "paragraphstyle.attrdefs.cxx"
164
#undef ATTRDEF
165
}
166