Convertion to CSS-like format of style sheets at top level (criteria, not styles)
[kworship.git] / kworship / css / KwCssStyleRule.cpp
blob095c34dfd9bcfeed3b83a3f3d02cba914c2b0b77
1 /***************************************************************************
2 * This file is part of KWorship. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
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. *
9 * *
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. *
14 * *
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 ***************************************************************************/
20 /**
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()
34 : m_criteriaKeys()
35 , m_criteriaClasses()
36 , m_includedStyles()
37 , m_styles(new ReferenceCountedExtension<KwCssStyles>)
41 /// Destructor.
42 KwCssStyleRule::~KwCssStyleRule()
47 * Main interface.
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;
62 /// Set a style.
63 void KwCssStyleRule::setRawStyle(QString name, KwCssAbstractStyle* style)
65 m_styles->setRawStyle(name, style);
69 * Accessors
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;
90 /// Get the styles.
91 const ReferenceCountedExtension<KwCssStyles>* KwCssStyleRule::getStyles() const
93 return m_styles;
96 /// Convert to CSS-like format.
97 QString KwCssStyleRule::toString() const
99 QString result;
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();
111 result += " ";
113 foreach (const QString& className, m_criteriaClasses)
115 result += QString(".%1 ").arg(className);
117 if (!m_includedStyles.isEmpty())
119 result += ": ";
120 foreach (const QString& className, m_includedStyles)
122 result += QString(".%1 ").arg(className);
125 result += "{\n";
126 result += m_styles->toString();
127 result += "}\n";
128 return result;