New css schema object for constructing property values from strings
[kworship.git] / kworship / css / KwCssStandardise.h
blob3aeb4bf6b75a50be056f64d4cb71a1d1a8573966
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 _KwCssStandardise_h_
21 #define _KwCssStandardise_h_
23 /**
24 * @file KwCssStandardise.h
25 * @brief Macros for css standardisation.
26 * @author James Hogan <james@albanarts.com>
29 #include "KwCssScope.h"
30 #include "KwCssSchema.h"
32 /// Simple class for accessing a style.
33 template <typename T>
34 class KwCssStyleAccessor
36 public:
37 virtual ~KwCssStyleAccessor()
41 * Main interface
43 T operator () (const KwCssScope* scope) const
45 return scope->getStyles().getStyle<T>(getName());
48 void registerToSchema(KwCssSchema* schema) const
50 schema->registerProperty<T>(getName());
52 protected:
53 virtual QString getName() const = 0;
56 #define KWCSS_SCHEMA \
57 inline KwCssSchema* schema() \
58 { \
59 static KwCssSchema* s = 0; \
60 if (0 == s) \
61 { \
62 s = new KwCssSchema; \
63 } \
64 return s; \
67 /// Start the root css namespace.
68 #define KWCSS_ROOT_NAMESPACE(NAME) \
69 namespace NAME \
70 { \
71 inline QString _scopeName() \
72 { \
73 return #NAME; \
76 /// Start a non-root css namespace.
77 #define KWCSS_START_NAMESPACE(PREV,NAME) \
78 namespace NAME \
79 { \
80 inline QString _scopeName() \
81 { \
82 return #PREV "." #NAME; \
85 /// End a css namespace.
86 #define KWCSS_END_NAMESPACE() \
89 /// Define a property in a css namespace.
90 #define KWCSS_DEFINE_PROPERTY(TYPE, LNAME) \
91 KWCSS_EXTERN class Acc_##LNAME : public KwCssStyleAccessor< TYPE > \
92 { \
93 public: \
94 Acc_##LNAME() \
95 { \
96 registerToSchema(schema()); \
97 } \
98 protected: \
99 virtual QString getName() const \
101 QString name = _scopeName(); \
102 name.append("." #LNAME); \
103 return name; \
105 } LNAME;
107 #define KWCSS_EXTERN extern
109 #endif // _KwCssStandardise_h_