Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
8343 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
#include "style.h"
12314 pierre 18
 
19
#include "prefsmanager.h"
8343 avox 20
#include "desaxe/digester.h"
21
#include "desaxe/simple_actions.h"
22
#include "desaxe/saxiohelper.h"
12340 pierre 23
#include "styleslibrary.h"
8343 avox 24
 
12314 pierre 25
#include <QDebug>
26
#include <QUuid>
27
 
12340 pierre 28
const QString Style::INHERIT_PARENT = QUuid().toString() ;
9607 avox 29
 
12314 pierre 30
Style::Style()
12343 pierre 31
        : m_isDefaultStyle(false), m_uuid(QUuid::createUuid().toString()),  m_parent(QUuid().toString()), m_shortcut()
12314 pierre 32
{
12337 pierre 33
        m_name = m_uuid;
12340 pierre 34
        StylesLibrary::Add(m_uuid,this);
12314 pierre 35
}
36
 
37
 
12337 pierre 38
Style::Style( QString n, QString lang  )
39
        : m_isDefaultStyle(false), m_uuid( QUuid::createUuid().toString() ), m_name(n), m_parent(QUuid().toString()), m_shortcut()
12314 pierre 40
{
12340 pierre 41
        StylesLibrary::Add(m_uuid,this);
12314 pierre 42
}
43
 
44
Style::Style(const Style& o)
45
        : SaxIO(),
46
        m_isDefaultStyle(o.m_isDefaultStyle),
12337 pierre 47
        m_uuid( QUuid::createUuid().toString() ),
12314 pierre 48
        m_name(o.m_name),
49
        m_parent(o.m_parent),
50
        m_shortcut(o.m_shortcut)
51
{
12340 pierre 52
        StylesLibrary::Add(m_uuid,this);
12314 pierre 53
}
54
 
12343 pierre 55
// Style& Style::operator=(const Style& o)
56
// { //assert(typeinfo() == o.typeinfo()); 
57
//      m_isDefaultStyle = o.m_isDefaultStyle;
58
//      m_name = o.m_name;
59
//      m_uuid = o.m_uuid;
60
//      m_parent = o.m_parent;
61
//      m_shortcut = o.m_shortcut;
62
//      return *this;
63
// }
12314 pierre 64
 
12337 pierre 65
 
66
Style::~ Style()
67
{
12340 pierre 68
        StylesLibrary::Remove(m_name);
12337 pierre 69
}
70
 
71
 
12340 pierre 72
QString Style::name() const
12314 pierre 73
{
12340 pierre 74
        return m_name; 
12314 pierre 75
}
76
 
12343 pierre 77
const QString Style::uuid() const
12314 pierre 78
{
12340 pierre 79
        return m_uuid;
12314 pierre 80
}
81
 
12340 pierre 82
void Style::setName(const QString& n)
12314 pierre 83
{
12340 pierre 84
        m_name = n;
12314 pierre 85
}
86
 
12340 pierre 87
bool Style::hasName() const
12314 pierre 88
{
12340 pierre 89
        return m_name != m_uuid;
12314 pierre 90
}
91
 
92
QString Style::parent() const
93
{
94
        return m_parent;
95
}
96
 
97
void Style::setParent(const QString& p)
98
{
12322 pierre 99
        m_parent = QUuid(p).toString();
12314 pierre 100
}              
101
 
102
bool Style::hasParent() const
103
{
104
        return !QUuid(m_parent).isNull() ;
105
}
106
 
107
 
12340 pierre 108
void Style::validate() const
8343 avox 109
{
110
 
111
}
112
 
113
 
114
const Style* Style::parentStyle() const
115
{
12340 pierre 116
        const Style * par = QUuid(m_parent).isNull() ? NULL : StylesLibrary::BaseStyle(m_parent) ;
12322 pierre 117
        if (par == this)
118
        {
119
                return NULL;
120
        }
12340 pierre 121
        return par;
8343 avox 122
}
123
 
124
void Style::saxxAttributes(Xml_attr& attr) const
125
{
12314 pierre 126
        if (!uuid().isEmpty())
127
                attr["uuid"] = uuid();
8343 avox 128
        if(!parent().isEmpty())
129
                attr["parent"] = parent();
130
        if (!shortcut().isEmpty())
131
                attr["shortcut"] = shortcut();
132
}
12314 pierre 133
 
12340 pierre 134
void Style::applyStyle(const QString& other)
12314 pierre 135
{
12340 pierre 136
        Style *pOther = StylesLibrary::BaseStyle( other );
137
        if (pOther && pOther->hasParent())
138
                setParent( pOther->parent() == INHERIT_PARENT ? QUuid().toString() : pOther->parent());
12314 pierre 139
}
140
 
12340 pierre 141
void Style::eraseStyle(const QString& other)
12314 pierre 142
{
12340 pierre 143
        Style *pOther = StylesLibrary::BaseStyle( other );
144
        if ( pOther && pOther->parent() == parent())
12314 pierre 145
                setParent(QUuid().toString());
146
}
12337 pierre 147
 
148