Scribus Developer Documentation - API
logo-pen

Scribus Developer Documentation - API

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