Back to index

scribus-ng  1.3.4.dfsg+svn20071115
linestyle.cpp
Go to the documentation of this file.
00001 /*
00002  For general Scribus (>=1.3.2) copyright and licensing information please refer
00003  to the COPYING file provided with the program. Following this notice may exist
00004  a copyright and/or license notice that predates the release of Scribus 1.3.2
00005  for which a new license (GPL+exception) is in place.
00006  */
00007 
00008 
00009 #include <qvaluelist.h>
00010 #include <qobject.h>
00011 #include "sctextstruct.h"
00012 #include "scfonts.h"
00013 #include "resourcecollection.h"
00014 
00015 #include "styles/style.h"
00016 #include "linestyle.h"
00017 #include "desaxe/saxiohelper.h"
00018 #include "desaxe/simple_actions.h"
00019 #include "prefsmanager.h"
00020 
00021 
00022 void LineStyle::applyLineStyle(const LineStyle & other)
00023 {
00024        Style::applyStyle(other);
00025 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00026        if (! other.inh_##attr_NAME) \
00027               set##attr_NAME(other.m_##attr_NAME);
00028 #include "linestyle.attrdefs.cxx"
00029 #undef ATTRDEF
00030 }
00031 
00032 
00033 void LineStyle::eraseLineStyle(const LineStyle & other)
00034 {
00035        other.validate();
00036        Style::eraseStyle(other);
00037 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00038        if (!inh_##attr_NAME && m_##attr_NAME == other.m_##attr_NAME) \
00039               reset##attr_NAME();
00040 #include "linestyle.attrdefs.cxx"
00041 #undef ATTRDEF
00042 }
00043 
00044 bool LineStyle::equiv(const Style & other) const
00045 {
00046        other.validate();
00047        const LineStyle * oth = dynamic_cast<const LineStyle*> ( & other );
00048        return  oth &&
00049               parent() == oth->parent() 
00050 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00051               && (inh_##attr_NAME == oth->inh_##attr_NAME) \
00052               && (inh_##attr_NAME || m_##attr_NAME == oth->m_##attr_NAME)
00053 #include "linestyle.attrdefs.cxx"
00054 #undef ATTRDEF
00055               ;      
00056 }
00057 
00058 
00059 QString LineStyle::displayName() const
00060 {
00061        if ( hasName() || !hasParent() || ! m_context)
00062               return name();
00063 //     else if ( inheritsAll() )
00064 //            return parent()->displayName();
00065        else 
00066               return parentStyle()->displayName() + "+";
00067 }
00068 
00069 
00070 
00071 QString LineStyle::asString() const
00072 {
00073        QString result;
00074 /*     if ( !inh_Font )
00075               result += QObject::tr("font %1 ").arg(font().scName());
00076        if ( !inh_FontSize )
00077               result += QObject::tr("size %1 ").arg(fontSize());
00078        if ( !inh_Effects )
00079               result += QObject::tr("+style ");
00080        if ( !inh_StrokeColor  ||  !inh_StrokeShade  ||  !inh_FillColor || !inh_FillShade )
00081               result += QObject::tr("+color ");
00082        if ( !inh_UnderlineWidth  ||  !inh_UnderlineOffset )
00083               result += underlineWidth() > 0 ? QObject::tr("+underline ") : QObject::tr("-underline ");
00084        if ( !inh_StrikethruWidth || !inh_StrikethruOffset )
00085               result += strikethruWidth() > 0 ? QObject::tr("+strikeout ") : QObject::tr("-strikeout ");
00086        if ( !inh_ShadowXOffset || !inh_ShadowYOffset )
00087               result += shadowXOffset() != 0 || shadowYOffset() != 0 ? QObject::tr("+shadow ") : QObject::tr("-shadow ");
00088        if ( !inh_OutlineWidth )
00089               result += outlineWidth() > 0 ? QObject::tr("+outline ") : QObject::tr("-outline ");
00090        if ( !inh_Tracking )
00091               result += tracking() > 0 ? QObject::tr("+tracking %1 ").arg(tracking()) : QObject::tr("-tracking ");
00092        if ( !inh_BaselineOffset )
00093               result += QObject::tr("+baseline %1 ").arg(baselineOffset());
00094        if ( !inh_ScaleH || !inh_ScaleV )
00095               result += QObject::tr("+stretch ");
00096        if ( hasParent() )
00097               result += QObject::tr("parent= %1").arg(parent());
00098 */     return result.stripWhiteSpace();
00099 }
00100 
00101 
00102 void LineStyle::update(const StyleContext* context)
00103 {
00104        Style::update(context);
00105        const LineStyle * oth = dynamic_cast<const LineStyle*> ( parentStyle() );
00106        if (oth) {
00107 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00108               if (inh_##attr_NAME) \
00109                      m_##attr_NAME = oth->attr_GETTER();
00110 #include "linestyle.attrdefs.cxx"
00111 #undef ATTRDEF
00112        }
00113 }
00114 
00115 
00116 void LineStyle::setStyle(const LineStyle& other) 
00117 {
00118        other.validate();
00119        setParent(other.parent());
00120 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00121        inh_##attr_NAME = other.inh_##attr_NAME; \
00122        m_##attr_NAME = other.m_##attr_NAME;
00123 #include "linestyle.attrdefs.cxx"
00124 #undef ATTRDEF
00125 }
00126 
00127 void LineStyle::getNamedResources(ResourceCollection& lists) const
00128 {
00129        QValueList<LineStyle>::const_iterator it, itend = m_Sublines.constEnd();
00130 
00131        lists.collectColor(color());
00132        for (const Style* sty = parentStyle(); sty != NULL; sty = sty->parentStyle())
00133               lists.collectLineStyle(sty->name());
00134        for (it = m_Sublines.begin(); it != itend; ++it)
00135               (*it).getNamedResources(lists);
00136 }
00137 
00138 void LineStyle::replaceNamedResources(ResourceCollection& newNames)
00139 {
00140        QMap<QString,QString>::ConstIterator it;
00141        QValueList<LineStyle>::iterator itl, itle = m_Sublines.end();
00142 
00143        if (!inh_Color && (it = newNames.colors().find(color())) != newNames.colors().end())
00144               setColor(it.data());
00145        if (hasParent() && (it = newNames.lineStyles().find(parent())) != newNames.lineStyles().end())
00146               setParent(it.data());
00147        for (itl = m_Sublines.begin(); itl != itle; ++itl)
00148               (*itl).replaceNamedResources(newNames);
00149 }
00150 
00151 /*
00152 bool LineStyle::definesAll() const
00153 {
00154        return definesLineSpacing() && 
00155        definesLeftMargin() && 
00156        definesRightMargin() && 
00157        definesFirstIndent() &&
00158        definesAlignment() && 
00159        definesGapBefore()  &&
00160        definesLineSpacingMode()  && 
00161        definesGapAfter()  && 
00162        definesHasDropCap() && 
00163        definesDropCapOffset() && 
00164        definesDropCapLines() && 
00165        definesUseBaselineGrid() && 
00166        lineStyle().definesAll() ;
00167        
00168 }
00169 
00170 // equiv. to "*this == LineStyle()"
00171 bool LineStyle::inheritsAll() const
00172 {
00173        return inheritsLineSpacing() && 
00174        inheritsLeftMargin() && 
00175        inheritsRightMargin() && 
00176        inheritsFirstIndent() &&
00177        inheritsAlignment() && 
00178        inheritsGapBefore()  &&
00179        inheritsLineSpacingMode()  && 
00180        inheritsGapAfter()  && 
00181        inheritsHasDropCap() && 
00182        inheritsDropCapOffset() && 
00183        inheritsDropCapLines() && 
00184        inheritsUseBaselineGrid() && 
00185        lineStyle().inheritsAll() ;
00186 }
00187 */
00188 
00189 typedef QValueList<LineStyle> Sublist;
00190 
00191 static QString toXMLString(const Sublist & )
00192 {
00193        return "dummy";
00194 }
00195 
00196 
00197 void LineStyle::saxx(SaxHandler& handler, const Xml_string& elemtag) const
00198 {
00199        Xml_attr att;
00200        Style::saxxAttributes(att);
00201 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00202        if (!inh_##attr_NAME && strcmp(# attr_NAME, "Sublines") != 0 ) \
00203               att.insert(# attr_NAME, toXMLString(m_##attr_NAME));
00204 #include "linestyle.attrdefs.cxx"
00205 #undef ATTRDEF
00206        if (!name().isEmpty())
00207               att["id"] = mkXMLName(elemtag + name());
00208        handler.begin(elemtag, att);
00209        if (parentStyle())
00210               parentStyle()->saxx(handler);      
00211        Sublist::const_iterator it;
00212        for (it=m_Sublines.begin(); it != m_Sublines.end(); ++it)
00213        {
00214               (*it).saxx(handler, "subline");
00215        }
00216        handler.end(elemtag);
00217 }
00218 
00219 
00220 
00221 
00222 template<>
00223 Sublist parse<Sublist>(const Xml_string& str)
00224 {
00225        return Sublist();
00226 }
00227 
00228 template<>
00229 Qt::PenStyle parse<Qt::PenStyle>(const Xml_string& str)
00230 {
00231        return parseEnum<Qt::PenStyle>(str);
00232 }
00233 
00234 template<>
00235 Qt::PenCapStyle parse<Qt::PenCapStyle>(const Xml_string& str)
00236 {
00237        return parseEnum<Qt::PenCapStyle>(str);
00238 }
00239 
00240 template<>
00241 Qt::PenJoinStyle parse<Qt::PenJoinStyle>(const Xml_string& str)
00242 {
00243        return parseEnum<Qt::PenJoinStyle>(str);
00244 }
00245 
00246 
00247 
00248 using namespace desaxe;
00249 
00250 
00251 const Xml_string LineStyle::saxxDefaultElem("linestyle");
00252 
00253 void LineStyle::desaxeRules(const Xml_string& prefixPattern, Digester& ruleset, Xml_string elemtag)
00254 {
00255        Xml_string stylePrefix(Digester::concat(prefixPattern, elemtag));
00256        ruleset.addRule(stylePrefix, Factory<LineStyle>());
00257        ruleset.addRule(stylePrefix, IdRef<LineStyle>());
00258        Style::desaxeRules<LineStyle>(prefixPattern, ruleset, elemtag);
00259 
00260 //  "**" doesnt work yet - av
00261 //     Xml_string stylePrefixRec(Digester::concat(stylePrefix, "**"));
00262        const Xml_string& stylePrefixRec(stylePrefix);
00263        Xml_string subPrefix(Digester::concat(stylePrefixRec, "subline"));
00264        ruleset.addRule(subPrefix, Factory<LineStyle>());
00265        Style::desaxeRules<LineStyle>(stylePrefixRec, ruleset, "subline");
00266        
00267 #define ATTRDEF(attr_TYPE, attr_GETTER, attr_NAME, attr_DEFAULT) \
00268        if ( strcmp(# attr_NAME, "Sublines") != 0 ) { \
00269               ruleset.addRule(stylePrefix, SetAttributeWithConversion<LineStyle, attr_TYPE> ( & LineStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> )); \
00270               ruleset.addRule(subPrefix, SetAttributeWithConversion<LineStyle, attr_TYPE> ( & LineStyle::set##attr_NAME,  # attr_NAME, &parse<attr_TYPE> )); \
00271        }
00272 #include "linestyle.attrdefs.cxx"
00273 #undef ATTRDEF
00274        ruleset.addRule(subPrefix, SetterWithConversion<LineStyle, const LineStyle&, LineStyle>( & LineStyle::appendSubline ));
00275 }