1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * KWorship is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * KWorship is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with KWorship. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file KwCssStyleRule.cpp
22 * @brief Class of cascading styles.
23 * @author James Hogan <james@albanarts.com>
26 #include "KwCssStyleRule.h"
29 * Constructors + destructors
32 /// Default constructor.
33 KwCssStyleRule::KwCssStyleRule()
37 , m_styles(new ReferenceCountedExtension
<KwCssStyles
>)
42 KwCssStyleRule::~KwCssStyleRule()
50 /// Set the set of critieria keys.
51 void KwCssStyleRule::setCriteriaKeys(const KeyList
& keys
)
53 m_criteriaKeys
= keys
;
56 /// Set the set of required classes.
57 void KwCssStyleRule::setCriteriaClasses(const StringSet
& classes
)
59 m_criteriaClasses
= classes
;
63 void KwCssStyleRule::setRawStyle(QString name
, KwCssAbstractStyle
* style
)
65 m_styles
->setRawStyle(name
, style
);
72 /// Get the list of criteria keys.
73 KwCssStyleRule::KeyList
& KwCssStyleRule::getCriteriaKeys()
75 return m_criteriaKeys
;
78 /// Get the set of criteria classes.
79 KwCssStyleRule::StringSet
& KwCssStyleRule::getCriteriaClasses()
81 return m_criteriaClasses
;
84 /// Get the list of included styles.
85 const KwCssStyleRule::StringSet
& KwCssStyleRule::getIncludedStyles() const
87 return m_includedStyles
;
91 const ReferenceCountedExtension
<KwCssStyles
>* KwCssStyleRule::getStyles() const
96 /// Convert to CSS-like format.
97 QString
KwCssStyleRule::toString() const
100 /// @todo Share styles among multiple rules
101 foreach (const KwCssScopeKey
& key
, m_criteriaKeys
)
103 if (key
.isTypeSpecified())
105 result
+= key
.getTypeName();
107 if (key
.isNameSpecified())
109 result
+= "#" + key
.getName();
113 foreach (const QString
& className
, m_criteriaClasses
)
115 result
+= QString(".%1 ").arg(className
);
117 if (!m_includedStyles
.isEmpty())
120 foreach (const QString
& className
, m_includedStyles
)
122 result
+= QString(".%1 ").arg(className
);
126 result
+= m_styles
->toString();