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 ***************************************************************************/
20 #ifndef _KwCssScope_h_
21 #define _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>
39 class KwCssStyleSheet
;
40 class KwResourceManager
;
44 #define KW_CSS_SCOPE(TYPE_NAME) \
46 /** Get the type id corresponding to this type statically. */ \
47 static KwCssScopeKey::ScopeTypeId scopeTypeId() \
49 static KwCssScopeKey::ScopeTypeId id = KwCssScopeKey::registerScopeType(TYPE_NAME); \
52 /** Get the type id corresponding to this type virtually. */ \
53 virtual KwCssScopeKey::ScopeTypeId getTypeId() const \
55 return scopeTypeId(); \
58 /// Cascading style scope.
66 * Constructors + destructors
69 /// Primary constructor.
70 KwCssScope(KwCssSchema
* schema
, KwCssScope
* parent
= 0);
73 virtual ~KwCssScope();
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;
89 /// Add a stylesheet for this scope.
90 void addStyleSheet(KwCssStyleSheet
* styleSheet
);
92 /// Set an explicit style.
94 void setExplicitStyle(QString name
, const T
& value
)
96 m_styles
.setStyle
<T
>(name
, value
);
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();
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;
129 /// Set the parent scope.
130 void setParentScope(KwCssScope
* parent
);
139 typedef QSet
<KwCssScope
*> ScopeSet
;
142 typedef QSet
<QString
> StringSet
;
144 /// List of style sheets.
145 typedef QList
<KwCssStyleSheet
*> StyleSheetList
;
152 KwCssSchema
* m_schema
;
155 KwCssScope
* m_parentScope
;
157 /// Set of child scopes.
158 ScopeSet m_childScopes
;
160 /// Name of the scope.
161 KwCssScopeKey::ScopeName m_name
;
167 /// Classes enabled by default in this scope.
171 StyleSheetList m_styleSheets
;
173 /// Explicit style overrides.
174 KwCssStyles m_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_