New css schema object for constructing property values from strings
[kworship.git] / kworship / css / KwCssScope.h
blob3573d038ce90bef6b08e3a6dba3194546bcbc08c
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 #ifndef _KwCssScope_h_
21 #define _KwCssScope_h_
23 /**
24 * @file KwCssScope.h
25 * @brief Cascading style scope.
26 * @author James Hogan <james@albanarts.com>
29 #include "KwCssScopeKey.h"
30 #include "KwCssStyleSheet.h"
31 #include "KwCssStyles.h"
32 #include "KwCssStyleStates.h"
34 #include <QStringList>
35 #include <QString>
36 #include <QSet>
37 #include <QList>
39 class KwCssStyleSheet;
40 class KwResourceManager;
41 class QDomDocument;
42 class QDomElement;
44 #define KW_CSS_SCOPE(TYPE_NAME) \
45 public: \
46 /** Get the type id corresponding to this type statically. */ \
47 static KwCssScopeKey::ScopeTypeId scopeTypeId() \
48 { \
49 static KwCssScopeKey::ScopeTypeId id = KwCssScopeKey::registerScopeType(TYPE_NAME); \
50 return id; \
51 } \
52 /** Get the type id corresponding to this type virtually. */ \
53 virtual KwCssScopeKey::ScopeTypeId getTypeId() const \
54 { \
55 return scopeTypeId(); \
58 /// Cascading style scope.
59 class KwCssScope
61 KW_CSS_SCOPE("scope")
63 public:
66 * Constructors + destructors
69 /// Primary constructor.
70 KwCssScope(KwCssSchema* schema, KwCssScope* parent = 0);
72 /// Destructor.
73 virtual ~KwCssScope();
76 * DOM filters
79 /// Import the style information from a DOM.
80 void importStylesFromDom(const QDomElement& element, KwResourceManager* resourceManager);
82 /// Export the style information to a DOM.
83 void exportStylesToDom(QDomDocument& document, QDomElement& element, KwResourceManager* resourceManager) const;
86 * Main interface
89 /// Add a stylesheet for this scope.
90 void addStyleSheet(KwCssStyleSheet* styleSheet);
92 /// Set an explicit style.
93 template <typename T>
94 void setExplicitStyle(QString name, const T& value)
96 m_styles.setStyle<T>(name, value);
97 recalculateStyles();
100 /// Add a class to this scope.
101 void addClass(QString className);
103 /// Get all the styles included in this scope.
104 const KwCssStyleStates& getStyles() const;
106 /// Recalculate all styles.
107 void recalculateStyles();
110 * Accessors
113 /// Find whether the scope is effectively empty.
114 bool isScopeEmpty() const;
116 /// Get explicit styles.
117 const KwCssStyles& getExplicitStyles() const;
119 /// Get the scope's key.
120 KwCssScopeKey getKey() const;
122 /// Find whether a scope key matches this scope.
123 bool isKeyMatching(KwCssScopeKey key) const;
126 * Mutators
129 /// Set the parent scope.
130 void setParentScope(KwCssScope* parent);
132 private:
135 * Types
138 /// Set of scopes.
139 typedef QSet<KwCssScope*> ScopeSet;
141 /// Set of strings.
142 typedef QSet<QString> StringSet;
144 /// List of style sheets.
145 typedef QList<KwCssStyleSheet*> StyleSheetList;
148 * Basic data
151 /// Style schema.
152 KwCssSchema* m_schema;
154 /// Parent scope.
155 KwCssScope* m_parentScope;
157 /// Set of child scopes.
158 ScopeSet m_childScopes;
160 /// Name of the scope.
161 KwCssScopeKey::ScopeName m_name;
164 * Variables
167 /// Classes enabled by default in this scope.
168 StringSet m_classes;
170 /// Style sheets.
171 StyleSheetList m_styleSheets;
173 /// Explicit style overrides.
174 KwCssStyles m_styles;
177 * Cache
180 /// Cached styles.
181 KwCssStyleStates m_cachedStyles;
183 /// Cached stylesheet accumulation.
184 KwCssStyleSheet m_cachedStyleSheet;
186 /// Cached total class list.
187 StringSet m_cachedClasses;
190 #endif // _KwCssScope_h_