Subversion Repositories Scribus

Rev

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.                                   *
*                                                                         *
***************************************************************************/



#include "style.h"

#include "prefsmanager.h"
#include "desaxe/digester.h"
#include "desaxe/simple_actions.h"
#include "desaxe/saxiohelper.h"
#include "styleslibrary.h"

#include <QDebug>
#include <QUuid>

const QString Style::INHERIT_PARENT = QUuid().toString() ;

Style::Style()
        : m_isDefaultStyle(false), m_uuid(QUuid::createUuid().toString()),  m_parent(QUuid().toString()), m_shortcut()
{
        m_name = m_uuid;
        StylesLibrary::Add(m_uuid,this);
}


Style::Style( QString n, QString lang  )
        : m_isDefaultStyle(false), m_uuid( QUuid::createUuid().toString() ), m_name(n), m_parent(QUuid().toString()), m_shortcut()
{
        StylesLibrary::Add(m_uuid,this);
}

Style::Style(const Style& o)
        : SaxIO(),
        m_isDefaultStyle(o.m_isDefaultStyle),
        m_uuid( QUuid::createUuid().toString() ),
        m_name(o.m_name),
        m_parent(o.m_parent),
        m_shortcut(o.m_shortcut)
{
        StylesLibrary::Add(m_uuid,this);
}

// Style& Style::operator=(const Style& o)
// { //assert(typeinfo() == o.typeinfo());
//      m_isDefaultStyle = o.m_isDefaultStyle;
//      m_name = o.m_name;
//      m_uuid = o.m_uuid;
//      m_parent = o.m_parent;
//      m_shortcut = o.m_shortcut;
//      return *this;
// }


Style::~ Style()
{
        StylesLibrary::Remove(m_name);
}


QString Style::name() const
{
        return m_name; 
}

const QString Style::uuid() const
{
        return m_uuid;
}

void Style::setName(const QString& n)
{
        m_name = n;
}

bool Style::hasName() const
{
        return m_name != m_uuid;
}

QString Style::parent() const
{
        return m_parent;
}

void Style::setParent(const QString& p)
{
        m_parent = QUuid(p).toString();
}              

bool Style::hasParent() const
{
        return !QUuid(m_parent).isNull() ;
}


void Style::validate() const
{

}


const Style* Style::parentStyle() const
{
        const Style * par = QUuid(m_parent).isNull() ? NULL : StylesLibrary::BaseStyle(m_parent) ;
        if (par == this)
        {
                return NULL;
        }
        return par;
}

void Style::saxxAttributes(Xml_attr& attr) const
{
        if (!uuid().isEmpty())
                attr["uuid"] = uuid();
        if(!parent().isEmpty())
                attr["parent"] = parent();
        if (!shortcut().isEmpty())
                attr["shortcut"] = shortcut();
}

void Style::applyStyle(const QString& other)
{
        Style *pOther = StylesLibrary::BaseStyle( other );
        if (pOther && pOther->hasParent())
                setParent( pOther->parent() == INHERIT_PARENT ? QUuid().toString() : pOther->parent());
}

void Style::eraseStyle(const QString& other)
{
        Style *pOther = StylesLibrary::BaseStyle( other );
        if ( pOther && pOther->parent() == parent())
                setParent(QUuid().toString());
}